Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/tprof Use the default counter if -e argument is not...
details: https://anonhg.NetBSD.org/src/rev/3403b6332fc9
branches: trunk
changeset: 374288:3403b6332fc9
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Apr 17 08:37:24 2023 +0000
description:
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.
diffstat:
usr.sbin/tprof/tprof.8 | 10 +++++++---
usr.sbin/tprof/tprof.c | 45 +++++++++++++++++++++++++++++++++++++++++----
usr.sbin/tprof/tprof.h | 3 ++-
usr.sbin/tprof/tprof_top.c | 29 +++--------------------------
4 files changed, 53 insertions(+), 34 deletions(-)
diffs (188 lines):
diff -r 8ac8a4e4dc72 -r 3403b6332fc9 usr.sbin/tprof/tprof.8
--- a/usr.sbin/tprof/tprof.8 Mon Apr 17 08:14:51 2023 +0000
+++ b/usr.sbin/tprof/tprof.8 Mon Apr 17 08:37:24 2023 +0000
@@ -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
diff -r 8ac8a4e4dc72 -r 3403b6332fc9 usr.sbin/tprof/tprof.c
--- a/usr.sbin/tprof/tprof.c Mon Apr 17 08:14:51 2023 +0000
+++ b/usr.sbin/tprof/tprof.c Mon Apr 17 08:37:24 2023 +0000
@@ -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) {
diff -r 8ac8a4e4dc72 -r 3403b6332fc9 usr.sbin/tprof/tprof.h
--- a/usr.sbin/tprof/tprof.h Mon Apr 17 08:14:51 2023 +0000
+++ b/usr.sbin/tprof/tprof.h Mon Apr 17 08:37:24 2023 +0000
@@ -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 *);
diff -r 8ac8a4e4dc72 -r 3403b6332fc9 usr.sbin/tprof/tprof_top.c
--- a/usr.sbin/tprof/tprof_top.c Mon Apr 17 08:14:51 2023 +0000
+++ b/usr.sbin/tprof/tprof_top.c Mon Apr 17 08:37:24 2023 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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");
Home |
Main Index |
Thread Index |
Old Index