git: ce6ab51fc378 - main - pmc: enable the new pmc commands

Warner Losh <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a690317.43317.5f4ea6a7__7996.16856254346$1785267043$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=ce6ab51fc3784aec3d7501b50e7d2d0a75507a86

commit ce6ab51fc3784aec3d7501b50e7d2d0a75507a86
Author:     Ali Mashtizadeh <[email protected]>
AuthorDate: 2026-07-28 17:46:57 +0000
Commit:     Warner Losh <[email protected]>
CommitDate: 2026-07-28 19:27:45 +0000

    pmc: enable the new pmc commands
    
    This change hooks everything up to the pmc command and improves the
    usage to document all functions.  There are a couple older commands that
    are currently broken that I have hidden from the usage, but left in the
    code for those using it.  I won't remove those until we have our
    replacements upstreamed that depend on the AMD PMC multiplexing patches.
    
    Sponsored by: Netflix
    Reviewed by:    adrian, imp
    Differential Revision:  https://reviews.freebsd.org/D57780
---
 usr.sbin/pmc/Makefile  |  6 ++++--
 usr.sbin/pmc/cmd_pmc.h |  7 +++++--
 usr.sbin/pmc/pmc.c     | 52 +++++++++++++++++++++++++++++++++++---------------
 3 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/usr.sbin/pmc/Makefile b/usr.sbin/pmc/Makefile
index d2f482b8fa5c..c27ad797e696 100644
--- a/usr.sbin/pmc/Makefile
+++ b/usr.sbin/pmc/Makefile
@@ -6,10 +6,12 @@ MAN=
 CWARNFLAGS.gcc+= -Wno-redundant-decls
 CFLAGS+= -I${SRCTOP}/lib/libpmcstat
 
-LIBADD=	pmc m pmcstat elf
+LIBADD=	pmc m util ncursesw pmcstat elf dwarf
 
 SRCS=	pmc.c pmc_util.c cmd_pmc_stat.c \
 	cmd_pmc_list.c cmd_pmc_filter.cc \
-	cmd_pmc_summary.cc
+	cmd_pmc_summary.cc \
+	cmd_pmc_frontend.cc cmd_pmc_record.cc cmd_pmc_info.cc \
+	display.cc util.cc view.cc
 
 .include <bsd.prog.mk>
diff --git a/usr.sbin/pmc/cmd_pmc.h b/usr.sbin/pmc/cmd_pmc.h
index 83c279c4e8b7..795c762cbed5 100644
--- a/usr.sbin/pmc/cmd_pmc.h
+++ b/usr.sbin/pmc/cmd_pmc.h
@@ -41,10 +41,13 @@ typedef int (*cmd_disp_t)(int, char **);
 #if defined(__cplusplus)
 extern "C" {
 #endif
-	int	cmd_pmc_stat(int, char **);
+	int	cmd_pmc_info(int, char **);
 	int	cmd_pmc_filter(int, char **);
-	int	cmd_pmc_stat_system(int, char **);
+	int	cmd_pmc_frontend(int, char **);
 	int	cmd_pmc_list_events(int, char **);
+	int	cmd_pmc_record(int, char **);
+	int	cmd_pmc_stat(int, char **);
+	int	cmd_pmc_stat_system(int, char **);
 	int	cmd_pmc_summary(int, char **);
 #if defined(__cplusplus)
 };
diff --git a/usr.sbin/pmc/pmc.c b/usr.sbin/pmc/pmc.c
index 4b4d113e2bd4..92f27db55026 100644
--- a/usr.sbin/pmc/pmc.c
+++ b/usr.sbin/pmc/pmc.c
@@ -36,11 +36,11 @@
 #include <string.h>
 #include <pmc.h>
 #include <pmclog.h>
+#include <libelf.h>
 #include <libpmcstat.h>
 #include <sysexits.h>
 #include <unistd.h>
 
-#include <libpmcstat.h>
 #include "cmd_pmc.h"
 
 int	pmc_displayheight = DEFAULT_DISPLAY_HEIGHT;
@@ -57,27 +57,44 @@ struct pmcstat_process_hash_list pmcstat_process_hash[PMCSTAT_NHASH];
 struct cmd_handler {
 	const char *ch_name;
 	cmd_disp_t ch_fn;
+	const char *ch_desc;
 };
 
 static struct cmd_handler disp_table[] = {
-	{"stat", cmd_pmc_stat},
-	{"stat-system", cmd_pmc_stat_system},
-	{"list-events", cmd_pmc_list_events},
-	{"filter", cmd_pmc_filter},
-	{"summary", cmd_pmc_summary},
-	{NULL, NULL}
+	{ "filter", cmd_pmc_filter, NULL },
+	{ "frontend", cmd_pmc_frontend, "Analyze front-end stalls" },
+	{ "info", cmd_pmc_info, "Display high level information about a log" },
+	{ "list-events", cmd_pmc_list_events, "List available PMC events" },
+	{ "record", cmd_pmc_record, "Record a performance sample" },
+	{ "stat", cmd_pmc_stat, NULL },
+	{ "stat-system", cmd_pmc_stat_system, NULL },
+	{ "summary", cmd_pmc_summary, NULL },
+	{ NULL, NULL, NULL }
 };
 
-static void __dead2
+static void
 usage(void)
 {
-	errx(EX_USAGE,
-	    "\t pmc management utility\n"
-	    "\t stat <program> run program and print stats\n"
-		 "\t stat-system <program> run program and print system wide stats for duration of execution\n"
-		 "\t list-events list PMC events available on host\n"
-		 "\t filter filter records by lwp, pid, or event\n"
-	    );
+	int i;
+
+	fprintf(stderr, "Usage: pmc <COMMAND> [OPTIONS] ...\n\n");
+	fprintf(stderr, "PMC tool\n\n");
+
+	fprintf(stderr, "Commands:\n");
+	for (i = 0; disp_table[i].ch_name != NULL; i++) {
+		// Hide stuff we plan to deprecate
+		if (disp_table[i].ch_desc)
+			fprintf(stderr, "    %-12s    %s\n",
+			    disp_table[i].ch_name, disp_table[i].ch_desc);
+	}
+
+	fprintf(stderr, "\nEnvironment Variables:\n");
+	fprintf(stderr, "    CLICOLOR        Enables color graphs\n");
+	fprintf(stderr, "    SYSROOT         Path to system root\n");
+	fprintf(stderr, "    SYMROOT         Path to debug symbols\n");
+	fprintf(stderr, "    TERM            Controls symbols and color palettes\n");
+
+	exit(EX_USAGE);
 }
 
 static cmd_disp_t
@@ -109,9 +126,14 @@ main(int argc, char **argv)
 	/* Allocate a kqueue */
 	if ((pmc_kq = kqueue()) < 0)
 		err(EX_OSERR, "ERROR: Cannot allocate kqueue");
+
 	if (pmc_init() < 0)
 		err(EX_UNAVAILABLE,
 		    "ERROR: Initialization of the pmc(3) library failed"
 		    );
+
+	if (elf_version(EV_CURRENT) == EV_NONE)
+		err(EX_UNAVAILABLE, "ERROR: ELF library version too old");
+
 	return (disp(argc, argv));
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.