Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/tprof - added 'c' command to tprof-top to show/hide...



details:   https://anonhg.NetBSD.org/src/rev/13d41c637178
branches:  trunk
changeset: 372651:13d41c637178
user:      ryo <ryo%NetBSD.org@localhost>
date:      Fri Dec 16 08:00:47 2022 +0000

description:
- added 'c' command to tprof-top to show/hide event counter.
- column widths were not calculated correctly and sometimes displayed incorrectly.
- use putp() for terminfo str.
- fix build error with llvm.

diffstat:

 usr.sbin/tprof/tprof.8     |   6 +++-
 usr.sbin/tprof/tprof_top.c |  58 ++++++++++++++++++++++++---------------------
 2 files changed, 35 insertions(+), 29 deletions(-)

diffs (182 lines):

diff -r 3a4e7cdca76d -r 13d41c637178 usr.sbin/tprof/tprof.8
--- a/usr.sbin/tprof/tprof.8    Fri Dec 16 07:59:42 2022 +0000
+++ b/usr.sbin/tprof/tprof.8    Fri Dec 16 08:00:47 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: tprof.8,v 1.22 2022/12/09 01:59:51 ryo Exp $
+.\"    $NetBSD: tprof.8,v 1.23 2022/12/16 08:00:47 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 9, 2022
+.Dd December 16, 2022
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -175,6 +175,8 @@
 .Bl -tag -width XXcommandsX -offset indent
 .It Ic a
 toggle accumurative mode.
+.It Ic c
+shows/hides the event counters.
 .It Ic q
 quit
 .Nm .
diff -r 3a4e7cdca76d -r 13d41c637178 usr.sbin/tprof/tprof_top.c
--- a/usr.sbin/tprof/tprof_top.c        Fri Dec 16 07:59:42 2022 +0000
+++ b/usr.sbin/tprof/tprof_top.c        Fri Dec 16 08:00:47 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $        */
+/*     $NetBSD: tprof_top.c,v 1.6 2022/12/16 08:00:47 ryo Exp $        */
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.6 2022/12/16 08:00:47 ryo Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -154,10 +154,10 @@
 
        /* cursor_up * n */
        if ((p = tigetstr("cuu")) != NULL) {
-               printf("%s", tparm(p, win.ws_row - 1, 0, 0, 0, 0, 0, 0, 0, 0));
+               putp(tparm(p, win.ws_row - 1, 0, 0, 0, 0, 0, 0, 0, 0));
        } else if ((p = tigetstr("cuu1")) != NULL) {
                for (i = win.ws_row - 1; i > 0; i--)
-                       printf("%s", p);
+                       putp(p);
        }
 }
 
@@ -170,7 +170,7 @@
                return;
 
        if ((p = tigetstr("el")) != NULL)
-               printf("%s", p);
+               putp(p);
 }
 
 /* newline, and clearing to end of line if needed */
@@ -288,7 +288,7 @@
        sigalrm = 1;
 }
 
-static void
+__dead static void
 die(int signo)
 {
        tty_restore();
@@ -297,7 +297,7 @@
        exit(EXIT_SUCCESS);
 }
 
-static void __dead
+__dead static void
 die_errc(int status, int code, const char *fmt, ...)
 {
        va_list ap;
@@ -676,20 +676,21 @@
                        do_redraw = true;
                }
        }
-       for (i = 0; i < nevent; i++) {
-               for (n = 0; n < ncpu; n++) {
-                       l = snprintf(buf, sizeof(buf), "%"PRIu64,
-                           sample_n_per_event_cpu[opt_mode][nevent * n + i]);
-                       if (sample_cpu_width[n] < (u_int)l) {
-                               sample_cpu_width[n] = l;
-                               do_redraw = true;
-                       }
+       for (n = 0; n < ncpu; n++) {
+               uint64_t sum = 0;
+               for (i = 0; i < nevent; i++)
+                       sum += sample_n_per_event_cpu[opt_mode][nevent * n + i];
+               l = snprintf(buf, sizeof(buf), "%"PRIu64, sum);
+               if (sample_cpu_width[n] < (u_int)l) {
+                       sample_cpu_width[n] = l;
+                       do_redraw = true;
                }
        }
 
        if (do_redraw) {
-               lim_printf(lim, "  Rate %*s Eventname                       ",
-                   sample_event_width, "Sample#");
+               lim_printf(lim, "  Rate %*s %-*s",
+                   sample_event_width, "Sample#",
+                   SYMBOL_LEN, "Eventname");
                for (n = 0; n < ncpu; n++) {
                        snprintf(buf, sizeof(buf), "CPU%d", n);
                        lim_printf(lim, " %*s", sample_cpu_width[n], buf);
@@ -796,8 +797,9 @@
        lim_newline(&lim);
 
        if (do_redraw) {
-               lim_printf(&lim, "  Rate %*s Symbol                          ",
-                   sample_event_width, "Sample#");
+               lim_printf(&lim, "  Rate %*s %-*s",
+                   sample_event_width, "Sample#",
+                   SYMBOL_LEN, "Symbol");
                for (n = 0; n < ncpu; n++) {
                        snprintf(namebuf, sizeof(namebuf), "CPU%d", n);
                        lim_printf(&lim, " %*s", sample_cpu_width[n], namebuf);
@@ -944,7 +946,7 @@
        return 0;
 }
 
-void
+__dead void
 tprof_top(int argc, char **argv)
 {
        tprof_param_t params[TPROF_MAXCOUNTERS];
@@ -1046,12 +1048,12 @@
        printf("collecting samples...");
        fflush(stdout);
 
-       tprof_bufsize = sizeof(tprof_sample_t) * 8192;
+       tprof_bufsize = sizeof(tprof_sample_t) * 1024 * 32;
        tprof_buf = emalloc(tprof_bufsize);
        do {
                bool force_update = false;
 
-               for (;;) {
+               while (sigalrm == 0 && !force_update) {
                        fd_set r;
                        int nfound;
                        char c;
@@ -1081,6 +1083,12 @@
                                        /* toggle mode */
                                        opt_mode = (opt_mode + 1) %
                                            SAMPLE_MODE_NUM;
+                                       do_redraw = true;
+                                       break;
+                               case 'c':
+                                       /* toggle mode */
+                                       opt_showcounter ^= 1;
+                                       do_redraw = true;
                                        break;
                                case 'q':
                                        goto done;
@@ -1088,14 +1096,10 @@
                                        sample_reset(true);
                                        break;
                                default:
-                                       printf("[%02x]", c);
-                                       fflush(stdout);
+                                       continue;
                                }
                                force_update = true;
-                               continue;
                        }
-                       if (sigalrm != 0 || force_update)
-                               break;
 
                        if (FD_ISSET(devfd, &r)) {
                                len = read(devfd, tprof_buf, tprof_bufsize);



Home | Main Index | Thread Index | Old Index