aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2018-06-07 02:03:22 +0000
committerMatt Macy <mmacy@FreeBSD.org>2018-06-07 02:03:22 +0000
commitf992dd4b5c6635e079c572fe1b59e34f0e28ad6d (patch)
tree6cd98711d1e0c3f928cc01dc292b253f900c79da /usr.sbin
parent1b000b505b84270219bff27d9c627877209f7e56 (diff)
downloadsrc-f992dd4b5c6635e079c572fe1b59e34f0e28ad6d.tar.gz
src-f992dd4b5c6635e079c572fe1b59e34f0e28ad6d.zip
pmc: convert native to jsonl and track TSC value of samples
- add '-j' options to filter to enable converting native pmc log format to json lines format to enable the use of scripts and external tooling % pmc filter -j pmc.log pmc.jsonl - Record the tsc value in sampling interrupts as opposed to recording nanotime when the sample is copied to a global log in hardclock - potentially many milliseconds later. - At initialize record the tsc_freq and the time of day to give us an offset for translating the tsc values in callchain records
Notes
Notes: svn path=/head/; revision=334749
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/Makefile2
-rw-r--r--usr.sbin/pmc/Makefile2
-rw-r--r--usr.sbin/pmc/cmd_pmc_filter.cc50
-rw-r--r--usr.sbin/pmccontrol/Makefile2
-rw-r--r--usr.sbin/pmcstat/Makefile2
5 files changed, 40 insertions, 18 deletions
diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile
index af327d42e97a..0eb9880fcd1d 100644
--- a/usr.sbin/Makefile
+++ b/usr.sbin/Makefile
@@ -181,10 +181,10 @@ SUBDIR.${MK_PF}+= ftp-proxy
SUBDIR.${MK_PKGBOOTSTRAP}+= pkg
.if (${COMPILER_TYPE} == "clang" || (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60100))
SUBDIR.${MK_PMC}+= pmc
-.endif
SUBDIR.${MK_PMC}+= pmcannotate
SUBDIR.${MK_PMC}+= pmccontrol
SUBDIR.${MK_PMC}+= pmcstat
+.endif
SUBDIR.${MK_PMC}+= pmcstudy
SUBDIR.${MK_PORTSNAP}+= portsnap
SUBDIR.${MK_PPP}+= ppp
diff --git a/usr.sbin/pmc/Makefile b/usr.sbin/pmc/Makefile
index 21d727e63aeb..c0a48372b0ae 100644
--- a/usr.sbin/pmc/Makefile
+++ b/usr.sbin/pmc/Makefile
@@ -5,7 +5,7 @@
.include <src.opts.mk>
PROG_CXX= pmc
MAN=
-CXXFLAGS+=
+CXXFLAGS+= -O0
LIBADD= kvm pmc m ncursesw pmcstat elf
diff --git a/usr.sbin/pmc/cmd_pmc_filter.cc b/usr.sbin/pmc/cmd_pmc_filter.cc
index 3892066c7695..ecb5d3d4edf8 100644
--- a/usr.sbin/pmc/cmd_pmc_filter.cc
+++ b/usr.sbin/pmc/cmd_pmc_filter.cc
@@ -72,9 +72,12 @@ __FBSDID("$FreeBSD$");
#include <string>
#include <unordered_map>
+#include <pmcformat.h>
+
+using namespace std;
using std::unordered_map;
-typedef unordered_map <int, std::string> idmap;
-typedef std::pair <int, std::string> identry;
+typedef unordered_map < int ,string > idmap;
+typedef pair < int ,string > identry;
#define LIST_MAX 64
static struct option longopts[] = {
@@ -176,8 +179,26 @@ pmc_find_name(idmap & map, uint32_t id, char *list[LIST_MAX], int count)
}
static void
+pmc_log_event(int fd, struct pmclog_ev *ev, bool json)
+{
+ int len;
+ void *buf;
+
+ if (json) {
+ string ret = event_to_json(ev);
+ buf = (void*)ret.c_str();
+ len = ret.size();
+ } else {
+ len = ev->pl_len;
+ buf = ev->pl_data;
+ }
+ if (write(fd, buf, len) != (ssize_t)len)
+ errx(EX_OSERR, "ERROR: failed output write");
+}
+
+static void
pmc_filter_handler(uint32_t *lwplist, int lwpcount, uint32_t *pidlist, int pidcount,
- char *events, char *processes, char *threads, bool exclusive, int infd,
+ char *events, char *processes, char *threads, bool exclusive, bool json, int infd,
int outfd)
{
struct pmclog_ev ev;
@@ -187,14 +208,15 @@ pmc_filter_handler(uint32_t *lwplist, int lwpcount, uint32_t *pidlist, int pidco
char cpuid[PMC_CPUID_LEN];
char *proclist[LIST_MAX];
char *threadlist[LIST_MAX];
- int i, pmccount, copies, eventcount, proccount, threadcount;
+ int i, pmccount, copies, eventcount;
+ int proccount, threadcount;
uint32_t idx;
idmap pidmap, tidmap;
if ((ps = static_cast < struct pmclog_parse_state *>(pmclog_open(infd)))== NULL)
errx(EX_OSERR, "ERROR: Cannot allocate pmclog parse state: %s\n", strerror(errno));
- proccount = eventcount = pmccount = 0;
+ threadcount = proccount = eventcount = pmccount = 0;
if (processes)
parse_names(processes, proclist, &proccount);
if (threads)
@@ -207,7 +229,6 @@ pmc_filter_handler(uint32_t *lwplist, int lwpcount, uint32_t *pidlist, int pidco
}
if (events)
parse_events(events, eventlist, &eventcount, cpuid);
-
lseek(infd, 0, SEEK_SET);
pmclog_close(ps);
if ((ps = static_cast < struct pmclog_parse_state *>(pmclog_open(infd)))== NULL)
@@ -233,8 +254,7 @@ pmc_filter_handler(uint32_t *lwplist, int lwpcount, uint32_t *pidlist, int pidco
if (ev.pl_type == PMCLOG_TYPE_PROC_CREATE)
pidmap[ev.pl_u.pl_pc.pl_pid] = ev.pl_u.pl_pc.pl_pcomm;
if (ev.pl_type != PMCLOG_TYPE_CALLCHAIN) {
- if (write(outfd, ev.pl_data, ev.pl_len) != (ssize_t)ev.pl_len)
- errx(EX_OSERR, "ERROR: failed output write");
+ pmc_log_event(outfd, &ev, json);
continue;
}
if (pidcount) {
@@ -274,8 +294,7 @@ pmc_filter_handler(uint32_t *lwplist, int lwpcount, uint32_t *pidlist, int pidco
if (threadcount &&
pmc_find_name(tidmap, ev.pl_u.pl_cc.pl_tid, threadlist, threadcount) == exclusive)
continue;
- if (write(outfd, ev.pl_data, ev.pl_len) != (ssize_t)ev.pl_len)
- errx(EX_OSERR, "ERROR: failed output write");
+ pmc_log_event(outfd, &ev, json);
}
}
@@ -287,16 +306,19 @@ cmd_pmc_filter(int argc, char **argv)
uint32_t pidlist[LIST_MAX];
int option, lwpcount, pidcount;
int prelogfd, postlogfd;
- bool exclusive;
+ bool exclusive, json;
threads = processes = lwps = pids = events = NULL;
lwpcount = pidcount = 0;
- exclusive = false;
- while ((option = getopt_long(argc, argv, "e:p:t:xP:T:", longopts, NULL)) != -1) {
+ json = exclusive = false;
+ while ((option = getopt_long(argc, argv, "e:jp:t:xP:T:", longopts, NULL)) != -1) {
switch (option) {
case 'e':
events = strdup(optarg);
break;
+ case 'j':
+ json = true;
+ break;
case 'p':
pids = strdup(optarg);
break;
@@ -336,6 +358,6 @@ cmd_pmc_filter(int argc, char **argv)
strerror(errno));
pmc_filter_handler(lwplist, lwpcount, pidlist, pidcount, events,
- processes, threads, exclusive, prelogfd, postlogfd);
+ processes, threads, exclusive, json, prelogfd, postlogfd);
return (0);
}
diff --git a/usr.sbin/pmccontrol/Makefile b/usr.sbin/pmccontrol/Makefile
index 1940b1ffe123..340c12811a4c 100644
--- a/usr.sbin/pmccontrol/Makefile
+++ b/usr.sbin/pmccontrol/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-PROG= pmccontrol
+PROG_CXX= pmccontrol
MAN= pmccontrol.8
LIBADD+= pmc
diff --git a/usr.sbin/pmcstat/Makefile b/usr.sbin/pmcstat/Makefile
index 472067767ab2..0233ad48f8d9 100644
--- a/usr.sbin/pmcstat/Makefile
+++ b/usr.sbin/pmcstat/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-PROG= pmcstat
+PROG_CXX= pmcstat
MAN= pmcstat.8
LIBADD= kvm pmc m ncursesw pmcstat elf