aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-09-26 19:05:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-09-26 19:42:23 -0400
commit514f1c67c2fdae7b334fdc5adee63a484781241a (patch)
tree4aa41fed839dea9806d8c905c7baec6422b6196b /tools
parent201b7334dc4e977479eb22b106ee8ec506e5e55c (diff)
perf trace: New tool
Initially should look loosely like the venerable 'strace' tool, but using the infrastructure in the perf tools to allow tracing extra targets: [acme@sandy linux]$ perf trace --hell Error: unknown option `hell' usage: perf trace <PID> -p, --pid <pid> trace events on existing process id --tid <tid> trace events on existing thread id --all-cpus system-wide collection from all CPUs --cpu <cpu> list of cpus to monitor --no-inherit child tasks do not inherit counters --mmap-pages <n> number of mmap data pages --uid <user> user to profile [acme@sandy linux]$ Those should have the same semantics as when using with 'perf record'. It gets stuck sometimes, but hey, it works sometimes too! In time it should support perf.data based workloads, i.e. it should have a: -o filename Command line option that will produce a perf.data file that can then be used with 'perf trace' or any of the other perf tools (script, report, etc). It will also eventually have the set of functionalities described in the previous 'trace' prototype by Thomas Gleixner: "Announcing a new utility: 'trace'" http://lwn.net/Articles/415728/ Also planned is to have some of the features suggested in the comments of that LWN article. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Documentation/perf-trace.txt53
-rw-r--r--tools/perf/Makefile3
-rw-r--r--tools/perf/builtin-trace.c300
-rw-r--r--tools/perf/builtin.h1
-rw-r--r--tools/perf/command-list.txt1
-rw-r--r--tools/perf/perf.c1
6 files changed, 358 insertions, 1 deletions
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
new file mode 100644
index 000000000000..3a2ae37310a9
--- /dev/null
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -0,0 +1,53 @@
1perf-trace(1)
2=============
3
4NAME
5----
6perf-trace - strace inspired tool
7
8SYNOPSIS
9--------
10[verse]
11'perf trace'
12
13DESCRIPTION
14-----------
15This command will show the events associated with the target, initially
16syscalls, but other system events like pagefaults, task lifetime events,
17scheduling events, etc.
18
19Initially this is a live mode only tool, but eventually will work with
20perf.data files like the other tools, allowing a detached 'record' from
21analysis phases.
22
23OPTIONS
24-------
25
26--all-cpus::
27 System-wide collection from all CPUs.
28
29-p::
30--pid=::
31 Record events on existing process ID (comma separated list).
32
33--tid=::
34 Record events on existing thread ID (comma separated list).
35
36--uid=::
37 Record events in threads owned by uid. Name or number.
38
39--no-inherit::
40 Child tasks do not inherit counters.
41
42--mmap-pages=::
43 Number of mmap data pages. Must be a power of two.
44
45--cpu::
46Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
47comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
48In per-thread mode with inheritance mode on (default), Events are captured only when
49the thread executes on the designated CPUs. Default is to monitor all CPUs.
50
51SEE ALSO
52--------
53linkperf:perf-record[1], linkperf:perf-script[1]
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 251dcd7fb5ac..6958ba4f5dcb 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -102,7 +102,7 @@ ifdef PARSER_DEBUG
102endif 102endif
103 103
104CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) 104CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS)
105EXTLIBS = -lpthread -lrt -lelf -lm 105EXTLIBS = -lpthread -lrt -lelf -lm -laudit
106ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE 106ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
107ALL_LDFLAGS = $(LDFLAGS) 107ALL_LDFLAGS = $(LDFLAGS)
108STRIP ?= strip 108STRIP ?= strip
@@ -442,6 +442,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
442BUILTIN_OBJS += $(OUTPUT)builtin-lock.o 442BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
443BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o 443BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
444BUILTIN_OBJS += $(OUTPUT)builtin-test.o 444BUILTIN_OBJS += $(OUTPUT)builtin-test.o
445BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
445BUILTIN_OBJS += $(OUTPUT)builtin-inject.o 446BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
446 447
447PERFLIBS = $(LIB_FILE) $(LIBTRACEEVENT) 448PERFLIBS = $(LIB_FILE) $(LIBTRACEEVENT)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
new file mode 100644
index 000000000000..5fa1820cc969
--- /dev/null
+++ b/tools/perf/builtin-trace.c
@@ -0,0 +1,300 @@
1#include "builtin.h"
2#include "util/evlist.h"
3#include "util/parse-options.h"
4#include "util/thread_map.h"
5#include "event-parse.h"
6
7#include <libaudit.h>
8#include <stdlib.h>
9
10static struct syscall_fmt {
11 const char *name;
12 bool errmsg;
13 bool timeout;
14} syscall_fmts[] = {
15 { .name = "futex", .errmsg = true, },
16 { .name = "poll", .errmsg = true, .timeout = true, },
17 { .name = "ppoll", .errmsg = true, .timeout = true, },
18 { .name = "read", .errmsg = true, },
19 { .name = "recvfrom", .errmsg = true, },
20 { .name = "select", .errmsg = true, .timeout = true, },
21};
22
23static int syscall_fmt__cmp(const void *name, const void *fmtp)
24{
25 const struct syscall_fmt *fmt = fmtp;
26 return strcmp(name, fmt->name);
27}
28
29static struct syscall_fmt *syscall_fmt__find(const char *name)
30{
31 const int nmemb = ARRAY_SIZE(syscall_fmts);
32 return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp);
33}
34
35struct syscall {
36 struct event_format *tp_format;
37 const char *name;
38 struct syscall_fmt *fmt;
39};
40
41struct trace {
42 int audit_machine;
43 struct {
44 int max;
45 struct syscall *table;
46 } syscalls;
47 struct perf_record_opts opts;
48};
49
50static int trace__read_syscall_info(struct trace *trace, int id)
51{
52 char tp_name[128];
53 struct syscall *sc;
54
55 if (id > trace->syscalls.max) {
56 struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc));
57
58 if (nsyscalls == NULL)
59 return -1;
60
61 if (trace->syscalls.max != -1) {
62 memset(nsyscalls + trace->syscalls.max + 1, 0,
63 (id - trace->syscalls.max) * sizeof(*sc));
64 } else {
65 memset(nsyscalls, 0, (id + 1) * sizeof(*sc));
66 }
67
68 trace->syscalls.table = nsyscalls;
69 trace->syscalls.max = id;
70 }
71
72 sc = trace->syscalls.table + id;
73 sc->name = audit_syscall_to_name(id, trace->audit_machine);
74 if (sc->name == NULL)
75 return -1;
76
77 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
78
79 sc->tp_format = event_format__new("syscalls", tp_name);
80 sc->fmt = syscall_fmt__find(sc->name);
81
82 return sc->tp_format != NULL ? 0 : -1;
83}
84
85static size_t syscall__fprintf_args(struct syscall *sc, unsigned long *args, FILE *fp)
86{
87 int i = 0;
88 size_t printed = 0;
89
90 if (sc->tp_format != NULL) {
91 struct format_field *field;
92
93 for (field = sc->tp_format->format.fields->next; field; field = field->next) {
94 printed += fprintf(fp, "%s%s: %ld", printed ? ", " : "",
95 field->name, args[i++]);
96 }
97 } else {
98 while (i < 6) {
99 printed += fprintf(fp, "%sarg%d: %ld", printed ? ", " : "", i, args[i]);
100 ++i;
101 }
102 }
103