linux_dsm_epyc7002/tools/perf/util/trace-event-read.c

480 lines
8.1 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-only
2009-08-17 21:18:06 +07:00
/*
* Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
*/
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "../perf.h"
2009-08-17 21:18:06 +07:00
#include "util.h"
#include "trace-event.h"
#include "debug.h"
2009-08-17 21:18:06 +07:00
static int input_fd;
static ssize_t trace_data_size;
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
static bool repipe;
static int __do_read(int fd, void *buf, int size)
{
int rsize = size;
while (size) {
int ret = read(fd, buf, size);
if (ret <= 0)
return -1;
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
if (repipe) {
int retw = write(STDOUT_FILENO, buf, ret);
if (retw <= 0 || retw != ret) {
pr_debug("repiping input file");
return -1;
}
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
}
size -= ret;
buf += ret;
}
return rsize;
}
static int do_read(void *data, int size)
2009-08-17 21:18:06 +07:00
{
int r;
r = __do_read(input_fd, data, size);
if (r <= 0) {
pr_debug("reading input file (size expected=%d received=%d)",
size, r);
return -1;
}
trace_data_size += r;
2009-08-17 21:18:06 +07:00
return r;
}
/* If it fails, the next read will report it */
static void skip(int size)
{
char buf[BUFSIZ];
int r;
while (size) {
r = size > BUFSIZ ? BUFSIZ : size;
do_read(buf, r);
size -= r;
};
}
static unsigned int read4(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned int data;
if (do_read(&data, 4) < 0)
return 0;
return tep_read_number(pevent, &data, 4);
2009-08-17 21:18:06 +07:00
}
static unsigned long long read8(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned long long data;
if (do_read(&data, 8) < 0)
return 0;
return tep_read_number(pevent, &data, 8);
2009-08-17 21:18:06 +07:00
}
static char *read_string(void)
{
char buf[BUFSIZ];
char *str = NULL;
int size = 0;
off_t r;
char c;
2009-08-17 21:18:06 +07:00
for (;;) {
r = read(input_fd, &c, 1);
if (r < 0) {
pr_debug("reading input file");
goto out;
}
2009-08-17 21:18:06 +07:00
if (!r) {
pr_debug("no data");
goto out;
}
2009-08-17 21:18:06 +07:00
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
if (repipe) {
int retw = write(STDOUT_FILENO, &c, 1);
if (retw <= 0 || retw != r) {
pr_debug("repiping input file string");
goto out;
}
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
}
buf[size++] = c;
2009-08-17 21:18:06 +07:00
if (!c)
break;
2009-08-17 21:18:06 +07:00
}
trace_data_size += size;
str = malloc(size);
if (str)
memcpy(str, buf, size);
out:
2009-08-17 21:18:06 +07:00
return str;
}
static int read_proc_kallsyms(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned int size;
size = read4(pevent);
2009-08-17 21:18:06 +07:00
if (!size)
return 0;
/*
* Just skip it, now that we configure libtraceevent to use the
* tools/perf/ symbol resolver.
*
* We need to skip it so that we can continue parsing old perf.data
* files, that contains this /proc/kallsyms payload.
*
* Newer perf.data files will have just the 4-bytes zeros "kallsyms
* payload", so that older tools can continue reading it and interpret
* it as "no kallsyms payload is present".
*/
lseek(input_fd, size, SEEK_CUR);
trace_data_size += size;
return 0;
2009-08-17 21:18:06 +07:00
}
static int read_ftrace_printk(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned int size;
char *buf;
/* it can have 0 size */
size = read4(pevent);
2009-08-17 21:18:06 +07:00
if (!size)
return 0;
perf utils: Null terminate buf in read_ftrace_printk() Ensure that the string that we read from the data file is null terminated. Valgrind was complaining: ==31357== Invalid read of size 1 ==31357== at 0x4EC8C1: __strtok_r_1c (string2.h:200) ==31357== by 0x4EC8C1: parse_ftrace_printk (trace-event-parse.c:161) ==31357== by 0x4F82A8: read_ftrace_printk (trace-event-read.c:204) ==31357== by 0x4F82A8: trace_report (trace-event-read.c:468) ==31357== by 0x4CD552: process_tracing_data (header.c:1576) ==31357== by 0x4D3397: perf_file_section__process (header.c:2705) ==31357== by 0x4D3397: perf_header__process_sections (header.c:2488) ==31357== by 0x4D3397: perf_session__read_header (header.c:2925) ==31357== by 0x4E71E2: perf_session__open (session.c:32) ==31357== by 0x4E71E2: perf_session__new (session.c:139) ==31357== by 0x429F5D: cmd_annotate (builtin-annotate.c:472) ==31357== by 0x497150: run_builtin (perf.c:359) ==31357== by 0x428CE0: handle_internal_command (perf.c:421) ==31357== by 0x428CE0: run_argv (perf.c:467) ==31357== by 0x428CE0: main (perf.c:614) ==31357== Address 0x8ac0efb is 0 bytes after a block of size 1,963 alloc'd ==31357== at 0x4C2DB9D: malloc (vg_replace_malloc.c:299) ==31357== by 0x4F827B: read_ftrace_printk (trace-event-read.c:195) ==31357== by 0x4F827B: trace_report (trace-event-read.c:468) ==31357== by 0x4CD552: process_tracing_data (header.c:1576) ==31357== by 0x4D3397: perf_file_section__process (header.c:2705) ==31357== by 0x4D3397: perf_header__process_sections (header.c:2488) ==31357== by 0x4D3397: perf_session__read_header (header.c:2925) ==31357== by 0x4E71E2: perf_session__open (session.c:32) ==31357== by 0x4E71E2: perf_session__new (session.c:139) ==31357== by 0x429F5D: cmd_annotate (builtin-annotate.c:472) ==31357== by 0x497150: run_builtin (perf.c:359) ==31357== by 0x428CE0: handle_internal_command (perf.c:421) ==31357== by 0x428CE0: run_argv (perf.c:467) ==31357== by 0x428CE0: main (perf.c:614) Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20170322130624.21881-6-tommi.t.rantala@nokia.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-22 20:06:23 +07:00
buf = malloc(size + 1);
if (buf == NULL)
return -1;
2009-08-17 21:18:06 +07:00
if (do_read(buf, size) < 0) {
free(buf);
return -1;
}
2009-08-17 21:18:06 +07:00
perf utils: Null terminate buf in read_ftrace_printk() Ensure that the string that we read from the data file is null terminated. Valgrind was complaining: ==31357== Invalid read of size 1 ==31357== at 0x4EC8C1: __strtok_r_1c (string2.h:200) ==31357== by 0x4EC8C1: parse_ftrace_printk (trace-event-parse.c:161) ==31357== by 0x4F82A8: read_ftrace_printk (trace-event-read.c:204) ==31357== by 0x4F82A8: trace_report (trace-event-read.c:468) ==31357== by 0x4CD552: process_tracing_data (header.c:1576) ==31357== by 0x4D3397: perf_file_section__process (header.c:2705) ==31357== by 0x4D3397: perf_header__process_sections (header.c:2488) ==31357== by 0x4D3397: perf_session__read_header (header.c:2925) ==31357== by 0x4E71E2: perf_session__open (session.c:32) ==31357== by 0x4E71E2: perf_session__new (session.c:139) ==31357== by 0x429F5D: cmd_annotate (builtin-annotate.c:472) ==31357== by 0x497150: run_builtin (perf.c:359) ==31357== by 0x428CE0: handle_internal_command (perf.c:421) ==31357== by 0x428CE0: run_argv (perf.c:467) ==31357== by 0x428CE0: main (perf.c:614) ==31357== Address 0x8ac0efb is 0 bytes after a block of size 1,963 alloc'd ==31357== at 0x4C2DB9D: malloc (vg_replace_malloc.c:299) ==31357== by 0x4F827B: read_ftrace_printk (trace-event-read.c:195) ==31357== by 0x4F827B: trace_report (trace-event-read.c:468) ==31357== by 0x4CD552: process_tracing_data (header.c:1576) ==31357== by 0x4D3397: perf_file_section__process (header.c:2705) ==31357== by 0x4D3397: perf_header__process_sections (header.c:2488) ==31357== by 0x4D3397: perf_session__read_header (header.c:2925) ==31357== by 0x4E71E2: perf_session__open (session.c:32) ==31357== by 0x4E71E2: perf_session__new (session.c:139) ==31357== by 0x429F5D: cmd_annotate (builtin-annotate.c:472) ==31357== by 0x497150: run_builtin (perf.c:359) ==31357== by 0x428CE0: handle_internal_command (perf.c:421) ==31357== by 0x428CE0: run_argv (perf.c:467) ==31357== by 0x428CE0: main (perf.c:614) Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20170322130624.21881-6-tommi.t.rantala@nokia.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-22 20:06:23 +07:00
buf[size] = '\0';
parse_ftrace_printk(pevent, buf, size);
2009-08-17 21:18:06 +07:00
free(buf);
return 0;
2009-08-17 21:18:06 +07:00
}
static int read_header_files(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned long long size;
char *header_page;
2009-08-17 21:18:06 +07:00
char buf[BUFSIZ];
int ret = 0;
2009-08-17 21:18:06 +07:00
if (do_read(buf, 12) < 0)
return -1;
2009-08-17 21:18:06 +07:00
if (memcmp(buf, "header_page", 12) != 0) {
pr_debug("did not read header page");
return -1;
}
2009-08-17 21:18:06 +07:00
size = read8(pevent);
header_page = malloc(size);
if (header_page == NULL)
return -1;
if (do_read(header_page, size) < 0) {
pr_debug("did not read header page");
free(header_page);
return -1;
}
if (!tep_parse_header_page(pevent, header_page, size,
tep_get_long_size(pevent))) {
/*
* The commit field in the page is of type long,
* use that instead, since it represents the kernel.
*/
tep_set_long_size(pevent, tep_get_header_page_size(pevent));
}
free(header_page);
2009-08-17 21:18:06 +07:00
if (do_read(buf, 13) < 0)
return -1;
if (memcmp(buf, "header_event", 13) != 0) {
pr_debug("did not read header event");
return -1;
}
2009-08-17 21:18:06 +07:00
size = read8(pevent);
skip(size);
return ret;
2009-08-17 21:18:06 +07:00
}
static int read_ftrace_file(struct tep_handle *pevent, unsigned long long size)
2009-08-17 21:18:06 +07:00
{
int ret;
2009-08-17 21:18:06 +07:00
char *buf;
buf = malloc(size);
if (buf == NULL) {
pr_debug("memory allocation failure\n");
return -1;
}
ret = do_read(buf, size);
if (ret < 0) {
pr_debug("error reading ftrace file.\n");
goto out;
}
ret = parse_ftrace_file(pevent, buf, size);
if (ret < 0)
pr_debug("error parsing ftrace file.\n");
out:
2009-08-17 21:18:06 +07:00
free(buf);
return ret;
2009-08-17 21:18:06 +07:00
}
static int read_event_file(struct tep_handle *pevent, char *sys,
unsigned long long size)
2009-08-17 21:18:06 +07:00
{
int ret;
2009-08-17 21:18:06 +07:00
char *buf;
buf = malloc(size);
if (buf == NULL) {
pr_debug("memory allocation failure\n");
return -1;
}
ret = do_read(buf, size);
if (ret < 0)
goto out;
ret = parse_event_file(pevent, buf, size, sys);
if (ret < 0)
pr_debug("error parsing event file.\n");
out:
2009-08-17 21:18:06 +07:00
free(buf);
return ret;
2009-08-17 21:18:06 +07:00
}
static int read_ftrace_files(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned long long size;
int count;
int i;
int ret;
2009-08-17 21:18:06 +07:00
count = read4(pevent);
2009-08-17 21:18:06 +07:00
for (i = 0; i < count; i++) {
size = read8(pevent);
ret = read_ftrace_file(pevent, size);
if (ret)
return ret;
2009-08-17 21:18:06 +07:00
}
return 0;
2009-08-17 21:18:06 +07:00
}
static int read_event_files(struct tep_handle *pevent)
2009-08-17 21:18:06 +07:00
{
unsigned long long size;
char *sys;
int systems;
int count;
int i,x;
int ret;
2009-08-17 21:18:06 +07:00
systems = read4(pevent);
2009-08-17 21:18:06 +07:00
for (i = 0; i < systems; i++) {
sys = read_string();
if (sys == NULL)
return -1;
2009-08-17 21:18:06 +07:00
count = read4(pevent);
2009-08-17 21:18:06 +07:00
for (x=0; x < count; x++) {
size = read8(pevent);
ret = read_event_file(pevent, sys, size);
if (ret) {
free(sys);
return ret;
}
2009-08-17 21:18:06 +07:00
}
free(sys);
2009-08-17 21:18:06 +07:00
}
return 0;
2009-08-17 21:18:06 +07:00
}
static int read_saved_cmdline(struct tep_handle *pevent)
{
unsigned long long size;
char *buf;
int ret;
/* it can have 0 size */
size = read8(pevent);
if (!size)
return 0;
buf = malloc(size + 1);
if (buf == NULL) {
pr_debug("memory allocation failure\n");
return -1;
}
ret = do_read(buf, size);
if (ret < 0) {
pr_debug("error reading saved cmdlines\n");
goto out;
}
parse_saved_cmdline(pevent, buf, size);
ret = 0;
out:
free(buf);
return ret;
}
ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
2009-08-17 21:18:06 +07:00
{
char buf[BUFSIZ];
char test[] = { 23, 8, 68 };
char *version;
perf sched: Display time in milliseconds, reorganize output After: ----------------------------------------------------------------------------------- Task | runtime ms | switches | average delay ms | maximum delay ms | ----------------------------------------------------------------------------------- migration/0 | 0.000 ms | 1 | avg: 0.047 ms | max: 0.047 ms | ksoftirqd/0 | 0.000 ms | 1 | avg: 0.039 ms | max: 0.039 ms | migration/1 | 0.000 ms | 3 | avg: 0.013 ms | max: 0.016 ms | migration/3 | 0.000 ms | 2 | avg: 0.003 ms | max: 0.004 ms | migration/4 | 0.000 ms | 1 | avg: 0.022 ms | max: 0.022 ms | distccd | 0.000 ms | 1 | avg: 0.004 ms | max: 0.004 ms | distccd | 0.000 ms | 1 | avg: 0.014 ms | max: 0.014 ms | distccd | 0.000 ms | 2 | avg: 0.000 ms | max: 0.000 ms | distccd | 0.000 ms | 2 | avg: 0.012 ms | max: 0.019 ms | distccd | 0.000 ms | 1 | avg: 0.002 ms | max: 0.002 ms | as | 0.000 ms | 2 | avg: 0.019 ms | max: 0.019 ms | as | 0.000 ms | 3 | avg: 0.015 ms | max: 0.017 ms | as | 0.000 ms | 1 | avg: 0.009 ms | max: 0.009 ms | perf | 0.000 ms | 1 | avg: 0.001 ms | max: 0.001 ms | gcc | 0.000 ms | 1 | avg: 0.021 ms | max: 0.021 ms | run-mozilla.sh | 0.000 ms | 2 | avg: 0.010 ms | max: 0.017 ms | mozilla-plugin- | 0.000 ms | 1 | avg: 0.006 ms | max: 0.006 ms | gcc | 0.000 ms | 2 | avg: 0.013 ms | max: 0.013 ms | ----------------------------------------------------------------------------------- (The runtime ms column is not filled in yet.) Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-12 15:08:34 +07:00
int show_version = 0;
2009-08-17 21:18:06 +07:00
int show_funcs = 0;
int show_printk = 0;
ssize_t size = -1;
int file_bigendian;
int host_bigendian;
int file_long_size;
int file_page_size;
struct tep_handle *pevent = NULL;
int err;
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
repipe = __repipe;
input_fd = fd;
2009-08-17 21:18:06 +07:00
if (do_read(buf, 3) < 0)
return -1;
if (memcmp(buf, test, 3) != 0) {
pr_debug("no trace data in the file");
return -1;
}
2009-08-17 21:18:06 +07:00
if (do_read(buf, 7) < 0)
return -1;
if (memcmp(buf, "tracing", 7) != 0) {
pr_debug("not a trace file (missing 'tracing' tag)");
return -1;
}
2009-08-17 21:18:06 +07:00
version = read_string();
if (version == NULL)
return -1;
perf sched: Display time in milliseconds, reorganize output After: ----------------------------------------------------------------------------------- Task | runtime ms | switches | average delay ms | maximum delay ms | ----------------------------------------------------------------------------------- migration/0 | 0.000 ms | 1 | avg: 0.047 ms | max: 0.047 ms | ksoftirqd/0 | 0.000 ms | 1 | avg: 0.039 ms | max: 0.039 ms | migration/1 | 0.000 ms | 3 | avg: 0.013 ms | max: 0.016 ms | migration/3 | 0.000 ms | 2 | avg: 0.003 ms | max: 0.004 ms | migration/4 | 0.000 ms | 1 | avg: 0.022 ms | max: 0.022 ms | distccd | 0.000 ms | 1 | avg: 0.004 ms | max: 0.004 ms | distccd | 0.000 ms | 1 | avg: 0.014 ms | max: 0.014 ms | distccd | 0.000 ms | 2 | avg: 0.000 ms | max: 0.000 ms | distccd | 0.000 ms | 2 | avg: 0.012 ms | max: 0.019 ms | distccd | 0.000 ms | 1 | avg: 0.002 ms | max: 0.002 ms | as | 0.000 ms | 2 | avg: 0.019 ms | max: 0.019 ms | as | 0.000 ms | 3 | avg: 0.015 ms | max: 0.017 ms | as | 0.000 ms | 1 | avg: 0.009 ms | max: 0.009 ms | perf | 0.000 ms | 1 | avg: 0.001 ms | max: 0.001 ms | gcc | 0.000 ms | 1 | avg: 0.021 ms | max: 0.021 ms | run-mozilla.sh | 0.000 ms | 2 | avg: 0.010 ms | max: 0.017 ms | mozilla-plugin- | 0.000 ms | 1 | avg: 0.006 ms | max: 0.006 ms | gcc | 0.000 ms | 2 | avg: 0.013 ms | max: 0.013 ms | ----------------------------------------------------------------------------------- (The runtime ms column is not filled in yet.) Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-12 15:08:34 +07:00
if (show_version)
printf("version = %s\n", version);
2009-08-17 21:18:06 +07:00
if (do_read(buf, 1) < 0) {
free(version);
return -1;
}
2009-08-17 21:18:06 +07:00
file_bigendian = buf[0];
host_bigendian = bigendian();
if (trace_event__init(tevent)) {
pr_debug("trace_event__init failed");
goto out;
}
pevent = tevent->pevent;
tep_set_flag(pevent, TEP_NSEC_OUTPUT);
tep_set_file_bigendian(pevent, file_bigendian);
tep_set_local_bigendian(pevent, host_bigendian);
if (do_read(buf, 1) < 0)
goto out;
file_long_size = buf[0];
2009-08-17 21:18:06 +07:00
file_page_size = read4(pevent);
if (!file_page_size)
goto out;
2009-08-17 21:18:06 +07:00
tep_set_long_size(pevent, file_long_size);
tep_set_page_size(pevent, file_page_size);
err = read_header_files(pevent);
if (err)
goto out;
err = read_ftrace_files(pevent);
if (err)
goto out;
err = read_event_files(pevent);
if (err)
goto out;
err = read_proc_kallsyms(pevent);
if (err)
goto out;
err = read_ftrace_printk(pevent);
if (err)
goto out;
if (atof(version) >= 0.6) {
err = read_saved_cmdline(pevent);
if (err)
goto out;
}
2009-08-17 21:18:06 +07:00
size = trace_data_size;
perf: add perf-inject builtin Currently, perf 'live mode' writes build-ids at the end of the session, which isn't actually useful for processing live mode events. What would be better would be to have the build-ids sent before any of the samples that reference them, which can be done by processing the event stream and retrieving the build-ids on the first hit. Doing that in perf-record itself, however, is off-limits. This patch introduces perf-inject, which does the same job while leaving perf-record untouched. Normal mode perf still records the build-ids at the end of the session as it should, but for live mode, perf-inject can be injected in between the record and report steps e.g.: perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i - perf-inject reads a perf-record event stream and repipes it to stdout. At any point the processing code can inject other events into the event stream - in this case build-ids (-b option) are read and injected as needed into the event stream. Build-ids are just the first user of perf-inject - potentially anything that needs userspace processing to augment the trace stream with additional information could make use of this facility. Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frédéric Weisbecker <fweisbec@gmail.com> LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com> Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-01 13:41:20 +07:00
repipe = false;
2009-08-17 21:18:06 +07:00
if (show_funcs) {
tep_print_funcs(pevent);
} else if (show_printk) {
tep_print_printk(pevent);
2009-08-17 21:18:06 +07:00
}
pevent = NULL;
out:
if (pevent)
trace_event__cleanup(tevent);
free(version);
return size;
2009-08-17 21:18:06 +07:00
}