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.
This commit is contained in:
msaitoh 2023-04-17 08:37:24 +00:00
parent 414e9ab499
commit 8dc7413669
4 changed files with 53 additions and 34 deletions

View File

@ -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 must be a combination of
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

View File

@ -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, const char *str, uint32_t flags,
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, int argc, char **argv)
}
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, &params[nevent]);
eventname[nevent] = defaultevent;
params[nevent].p_flags |= TPROF_PARAM_KERN;
nevent++;
}
if (do_profile) {

View File

@ -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 *);

View File

@ -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>
@ -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[SAMPLE_MODE_NUM]; /* [ncpu] */
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");