- 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.
This commit is contained in:
parent
2b54f35cc3
commit
923aefa047
|
@ -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 @@ These commands are currently recognized:
|
|||
.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 .
|
||||
|
|
|
@ -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>
|
||||
|
@ -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 @@ reset_cursor_pos(void)
|
|||
|
||||
/* 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 @@ clr_to_eol(void)
|
|||
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_handler(int signo)
|
|||
sigalrm = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
__dead static void
|
||||
die(int signo)
|
||||
{
|
||||
tty_restore();
|
||||
|
@ -297,7 +297,7 @@ die(int signo)
|
|||
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 @@ show_count_per_event(int *lim)
|
|||
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 @@ sample_show(void)
|
|||
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 @@ parse_event_scale(tprof_param_t *param, const char *str)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
__dead void
|
||||
tprof_top(int argc, char **argv)
|
||||
{
|
||||
tprof_param_t params[TPROF_MAXCOUNTERS];
|
||||
|
@ -1046,12 +1048,12 @@ tprof_top(int argc, char **argv)
|
|||
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 @@ tprof_top(int argc, char **argv)
|
|||
/* 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 @@ tprof_top(int argc, char **argv)
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue