Module Name: src Committed By: msaitoh Date: Mon Apr 17 08:37:24 UTC 2023
Modified Files: src/usr.sbin/tprof: tprof.8 tprof.c tprof.h tprof_top.c Log Message: Use the default counter if -e argument is not specified. monitor command: The default counter is selected if -e argument is not specified. list command: Print the name of the default counter for monitor and top command. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/tprof/tprof.8 cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/tprof/tprof.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof.h cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/tprof_top.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/tprof/tprof.8 diff -u src/usr.sbin/tprof/tprof.8:1.26 src/usr.sbin/tprof/tprof.8:1.27 --- src/usr.sbin/tprof/tprof.8:1.26 Mon Apr 17 07:13:35 2023 +++ src/usr.sbin/tprof/tprof.8 Mon Apr 17 08:37:24 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: tprof.8,v 1.26 2023/04/17 07:13:35 msaitoh Exp $ +.\" $NetBSD: tprof.8,v 1.27 2023/04/17 08:37:24 msaitoh Exp $ .\" .\" Copyright (c)2011 YAMAMOTO Takashi, .\" All rights reserved. @@ -69,10 +69,11 @@ Display the following information: a list of performance counter events available on the system .It the maximum number of counters that can be used simultaneously +.It +the default counter for monitor and top command .El .It monitor Xo -.Fl e -.Ar name[:option][,scale] +.Op Fl e Ar name[:option][,scale] .Op Fl e Ar ... .Op Fl o Ar outfile .Ar command @@ -91,6 +92,9 @@ specifies the source of the event; it mu Multiple .Fl e arguments can be specified. +If none of the +.Fl e +arguments are speficied, the CPU's default counter is used. The collected samples are written into the file .Ar scale specifies the ratio of the speed to the cycle counter, or the counter until Index: src/usr.sbin/tprof/tprof.c diff -u src/usr.sbin/tprof/tprof.c:1.20 src/usr.sbin/tprof/tprof.c:1.21 --- src/usr.sbin/tprof/tprof.c:1.20 Mon Dec 26 08:00:13 2022 +++ src/usr.sbin/tprof/tprof.c Mon Apr 17 08:37:24 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $ */ +/* $NetBSD: tprof.c,v 1.21 2023/04/17 08:37:24 msaitoh Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $"); +__RCSID("$NetBSD: tprof.c,v 1.21 2023/04/17 08:37:24 msaitoh Exp $"); #endif /* not lint */ #include <sys/atomic.h> @@ -260,7 +260,12 @@ process_stat(void *arg) static void tprof_list(int argc, char **argv) { - printf("%u events can be counted at the same time\n", ncounters); + const char *defaultevent = tprof_cycle_event_name(); + + printf("%u events can be counted at the same time.\n", ncounters); + if (defaultevent != NULL) + printf("The default counter for monitor and top command is " + "\"%s\".\n", defaultevent); tprof_event_list(); } @@ -356,6 +361,29 @@ tprof_parse_event(tprof_param_t *param, return error; } +const char * +tprof_cycle_event_name(void) +{ + const char *cycleevent; + + switch (tprof_info.ti_ident) { + case TPROF_IDENT_INTEL_GENERIC: + cycleevent = "unhalted-core-cycles"; + break; + case TPROF_IDENT_AMD_GENERIC: + cycleevent = "LsNotHaltedCyc"; + break; + case TPROF_IDENT_ARMV8_GENERIC: + case TPROF_IDENT_ARMV7_GENERIC: + cycleevent = "CPU_CYCLES"; + break; + default: + cycleevent = NULL; + break; + } + return cycleevent; +} + static void tprof_monitor_common(bool do_profile, int argc, char **argv) { @@ -404,8 +432,17 @@ tprof_monitor_common(bool do_profile, in } argc -= optind; argv += optind; - if (argc == 0 || nevent == 0) { + if (argc == 0) usage(); + if (nevent == 0) { + const char *defaultevent = tprof_cycle_event_name(); + if (defaultevent == NULL) + errx(EXIT_FAILURE, "cpu not supported"); + + tprof_event_lookup(defaultevent, ¶ms[nevent]); + eventname[nevent] = defaultevent; + params[nevent].p_flags |= TPROF_PARAM_KERN; + nevent++; } if (do_profile) { Index: src/usr.sbin/tprof/tprof.h diff -u src/usr.sbin/tprof/tprof.h:1.4 src/usr.sbin/tprof/tprof.h:1.5 --- src/usr.sbin/tprof/tprof.h:1.4 Fri Dec 16 08:02:04 2022 +++ src/usr.sbin/tprof/tprof.h Mon Apr 17 08:37:24 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tprof.h,v 1.4 2022/12/16 08:02:04 ryo Exp $ */ +/* $NetBSD: tprof.h,v 1.5 2023/04/17 08:37:24 msaitoh Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -34,6 +34,7 @@ extern int ncpu; extern int devfd; extern u_int ncounters; +const char *tprof_cycle_event_name(void); int tprof_event_init(uint32_t); void tprof_event_list(void); void tprof_event_lookup(const char *, struct tprof_param *); Index: src/usr.sbin/tprof/tprof_top.c diff -u src/usr.sbin/tprof/tprof_top.c:1.8 src/usr.sbin/tprof/tprof_top.c:1.9 --- src/usr.sbin/tprof/tprof_top.c:1.8 Fri Dec 23 19:37:06 2022 +++ src/usr.sbin/tprof/tprof_top.c Mon Apr 17 08:37:24 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $ */ +/* $NetBSD: tprof_top.c,v 1.9 2023/04/17 08:37:24 msaitoh Exp $ */ /*- * Copyright (c) 2022 Ryo Shimizu <r...@nerv.org> @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $"); +__RCSID("$NetBSD: tprof_top.c,v 1.9 2023/04/17 08:37:24 msaitoh Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -118,29 +118,6 @@ static uint64_t *sample_n_per_event_cpu[ static uint64_t *counters; /* counters[2][ncpu][nevent] */ static u_int counters_i; -static const char * -cycle_event_name(void) -{ - const char *cycleevent; - - switch (tprof_info.ti_ident) { - case TPROF_IDENT_INTEL_GENERIC: - cycleevent = "unhalted-core-cycles"; - break; - case TPROF_IDENT_AMD_GENERIC: - cycleevent = "LsNotHaltedCyc"; - break; - case TPROF_IDENT_ARMV8_GENERIC: - case TPROF_IDENT_ARMV7_GENERIC: - cycleevent = "CPU_CYCLES"; - break; - default: - cycleevent = NULL; - break; - } - return cycleevent; -} - static void reset_cursor_pos(void) { @@ -978,7 +955,7 @@ tprof_top(int argc, char **argv) tprof_top_usage(); if (nevent == 0) { - const char *defaultevent = cycle_event_name(); + const char *defaultevent = tprof_cycle_event_name(); if (defaultevent == NULL) die_errc(EXIT_FAILURE, 0, "cpu not supported");