Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F176943922
D58924.1793636072.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D58924.1793636072.diff
View Options
diff --git a/usr.sbin/pmc/cmd_pmc_program.cc b/usr.sbin/pmc/cmd_pmc_program.cc
new file mode 100644
--- /dev/null
+++ b/usr.sbin/pmc/cmd_pmc_program.cc
@@ -0,0 +1,212 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026, Netflix, Inc.
+ *
+ * This software was developed by Ali Mashtizadeh under the sponsorship from
+ * Netflix, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#include <sys/event.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <sys/ttycom.h>
+#include <sys/user.h>
+#include <sys/wait.h>
+
+#include <assert.h>
+#include <curses.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <kvm.h>
+#include <libgen.h>
+#include <limits.h>
+#include <locale.h>
+#include <math.h>
+#include <pmc.h>
+#include <pmclog.h>
+#include <regex.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include "cmd_pmc.h"
+
+#include <iostream>
+#include <map>
+#include <set>
+#include <string>
+#include <unordered_map>
+#include <unordered_set>
+#include <vector>
+
+#include "display.hh"
+#include "view.hh"
+
+struct funcinfo
+{
+ std::string binary;
+ std::string func;
+ uint64_t samples;
+ uint64_t ksamples;
+};
+
+static int sortcol = 2;
+
+class program_view : public pmcview
+{
+public:
+ program_view() : total(), samples() { }
+ ~program_view() { }
+
+ void
+ addsample(const syminfo &sym, bool user)
+ {
+ std::string bin = basename(sym.binary);
+ std::string key = bin + "!!" + sym.name;
+
+ auto e = samples.find(key);
+ if (e == samples.end())
+ samples[key] = funcinfo({ bin, sym.name, 0, 0 });
+
+ if (user)
+ samples[key].samples++;
+ else
+ samples[key].ksamples++;
+
+ total++;
+ }
+
+ virtual void
+ callchain(struct pmclog_ev_callchain &p, uintfptr_t *cc, __unused int len)
+ {
+ int usermode = (PMC_CALLCHAIN_CPUFLAGS_TO_USERMODE(p.pl_cpuflags) != 0);
+
+ syminfo sym = addrtosymbol(usermode ? p.pl_pid : 0, cc[0]);
+ if (sym.binary != "") {
+ addsample(sym, usermode != 0);
+ }
+ }
+
+ virtual void
+ print()
+ {
+ // Print header
+ table t = table();
+ t.addcolumn("Image", true);
+ t.addcolumn("Function", true);
+ t.addcolumn("Samples");
+
+ for (auto &kv : samples) {
+ std::vector<field> r;
+
+ r.emplace_back(kv.second.binary);
+ r.emplace_back(kv.second.func);
+ r.emplace_back(kv.second.samples, total, kv.second.ksamples, total);
+
+ t.addrow(r);
+ }
+
+ t.sort(sortcol);
+ t.print();
+ }
+protected:
+ uint64_t total = 0;
+ std::unordered_map<std::string, funcinfo> samples = std::unordered_map<std::string, funcinfo>();
+};
+
+
+static struct option longopts[] = {
+ PMCFILTER_LOPTS,
+ { NULL, 0, NULL, 0 }
+};
+
+static void
+usage(void)
+{
+ printf("Usage: pmc program [options] [pmclog]\n\n");
+ printf("Display a per-function summary\n\n");
+ printf("Options:\n");
+ printf("\t-s,--sort Sort by event\n\n");
+ PMCFILTER_PRINTOPTS();
+}
+
+int
+cmd_pmc_program(int argc, char **argv)
+{
+ struct pmcfilter filter = pmcfilter();
+ const char *logfile = "default.log";
+ int option, logfd;
+
+ while ((option = getopt_long(argc, argv, PMCFILTER_SOPTS, longopts, NULL)) != -1) {
+ switch (option) {
+ PMCFILTER_CASE(filter);
+ case 's':
+ sortcol = atoi(optarg);
+ break;
+ case '?':
+ default:
+ usage();
+ exit(EX_USAGE);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc > 1) {
+ usage();
+ exit(EX_USAGE);
+ }
+ if (argc == 1)
+ logfile = argv[0];
+
+ setup_screen();
+
+ if ((logfd = open(logfile, O_RDONLY)) < 0) {
+ errx(EX_OSERR, "ERROR: Cannot open \"%s\" for reading: %s.", argv[0],
+ strerror(errno));
+ }
+
+ program_view v = program_view();
+ v.setfilter(filter);
+ v.process(logfd);
+ v.print();
+
+ close(logfd);
+
+ return (EX_OK);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 2, 4:14 PM (17 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36963758
Default Alt Text
D58924.1793636072.diff (5 KB)
Attached To
Mode
D58924: pmc: Display a program level breakdown of performance data
Attached
Detach File
Event Timeline