perf tools: Add traceevent plugins support
cover perf tools: Add traceevent plugins support
hi,
backporting traceevent plugin support from trace-cmd.
Having plugins allow traceevent to properly parse 'print fmt' line of tracepoint format and display proper/additional data in perf script command, like:
- displaying call_site details in kmem:* tracepoints:
$ sudo perf record -e kmem:kmalloc ls
before:
ls 31708 [003] 15123.850504: kmem:kmalloc: call_site=ffffffff812030eb ptr=0xffff8801cbb91840 bytes_req=40 bytes_alloc=64 gfp_ ls 31708 [003] 15123.850506: kmem:kmalloc: call_site=ffffffff811be761 ptr=0xffff8801cbbddd20 bytes_req=32 bytes_alloc=32 gfp_ ls 31708 [003] 15123.850507: kmem:kmalloc: call_site=ffffffff811be6ab ptr=0xffff880163bf1800 bytes_req=112 bytes_alloc=128 gf ls 31708 [003] 15123.850535: kmem:kmalloc: call_site=ffffffff811bed5e ptr=0xffff88017d41b000 bytes_req=4096 bytes_alloc=4096 ls 31708 [003] 15123.850691: kmem:kmalloc: call_site=ffffffff81128333 ptr=0xffff88020eedc000 bytes_req=4104 bytes_alloc=8192 ls 31708 [003] 15123.850838: kmem:kmalloc: call_site=ffffffff8121c28e ptr=0xffff8801cb981940 bytes_req=48 bytes_alloc=64 gfp_ ls 31708 [003] 15123.850848: kmem:kmalloc: call_site=ffffffff8121c418 ptr=0xffff8801cb916bc0 bytes_req=50 bytes_alloc=64 gfp_ ls 31708 [003] 15123.850850: kmem:kmalloc: call_site=ffffffff8121c418 ptr=0xffff8801cb916b40 bytes_req=51 bytes_alloc=64 gfp_
now:
$ sudo perf script ... ls 30512 [001] 14717.425867: kmem:kmalloc: (perf_event_mmap+0xf3) call_site=ffffffff81128333 ptr=0xffff880211cea000 bytes_req ls 30512 [001] 14717.425981: kmem:kmalloc: (proc_reg_open+0x4b) call_site=ffffffff812030eb ptr=0xffff88017de85a40 bytes_req=4 ls 30512 [001] 14717.425982: kmem:kmalloc: (single_open+0x41) call_site=ffffffff811be761 ptr=0xffff8801958e1e00 bytes_req=32 ls 30512 [001] 14717.425982: kmem:kmalloc: (seq_open+0xfb) call_site=ffffffff811be6ab ptr=0xffff880211d88f00 bytes_req=112 by ls 30512 [001] 14717.425989: kmem:kmalloc: (seq_read+0x2ee) call_site=ffffffff811bed5e ptr=0xffff88017be8c000 bytes_req=4096 ls 30512 [001] 14717.426034: kmem:kmalloc: (perf_event_mmap+0xf3) call_site=ffffffff81128333 ptr=0xffff880211cea000 bytes_req ls 30512 [001] 14717.426079: kmem:kmalloc: (ext4_readdir+0x6fe) call_site=ffffffff8121c28e ptr=0xffff88017de85f00 bytes_req=4 ls 30512 [001] 14717.426081: kmem:kmalloc: (ext4_htree_store_dirent+0x38) call_site=ffffffff8121c418 ptr=0xffff88017de85080 b ...
- displaying details for timer_expire_entry and hrtimer_start tracepoints:
$ sudo perf record -e timer:* ls
before:
ls 31727 [001] 15171.487282: timer:hrtimer_cancel: hrtimer=0xffff88021e24e4c0
ls 31727 [001] 15171.487284: timer:hrtimer_expire_entry: [FAILED TO PARSE] hrtimer=0xffff88021e24e4c0 now=15167505000662 func ls 31727 [001] 15171.487290: timer:hrtimer_expire_exit: hrtimer=0xffff88021e24e4c0
ls 31727 [001] 15171.487290: timer:hrtimer_start: [FAILED TO PARSE] hrtimer=0xffff88021e24e4c0 function=0xffffffff810b6460 ex
now:
$ sudo perf script .. ls 30557 [001] 14855.443889: timer:hrtimer_cancel: hrtimer=0xffff88021e24e4c0 ls 30557 [001] 14855.443891: timer:hrtimer_expire_entry: hrtimer=0xffff88021e24e4c0 now=14851544000735 function=tick_sched_timer/0x0 ls 30557 [001] 14855.443897: timer:hrtimer_expire_exit: hrtimer=0xffff88021e24e4c0 ls 30557 [001] 14855.443897: timer:hrtimer_start: hrtimer=0xffff88021e24e4c0 function=tick_sched_timer expires=14851545000000 softexpires=14851545000000 ls 30557 [001] 14855.443899: timer:timer_cancel: timer=0xffff88021e250b68 ls 30557 [001] 14855.443900: timer:timer_expire_entry: timer=0xffff88021e250b68 function=delayed_work_timer_fn now=4309518840 ls 30557 [001] 14855.443903: timer:timer_expire_exit: timer=0xffff88021e250b68 ls 30557 [001] 14855.444888: timer:hrtimer_cancel: hrtimer=0xffff88021e24e4c0 ls 30557 [001] 14855.444889: timer:hrtimer_expire_entry: hrtimer=0xffff88021e24e4c0 now=14851545000598 function=tick_sched_timer/0x0 ...
All plugins present in trace-cmd are backported plus added new scsi and xen. The 'xen' plugin still cannot handle all the 'print fmt' functions, since I dont follow xen code ;-) Also xen tracepoints use 'sizeof' in the format string and it's not clear yet how to handle that.
Plugins get installed to following locations:
'$(HOME)/.traceevent/plugins'
- if no prefix is provided
'$(perfexecdir)/traceevent/plugins'
- if prefix is provided
thanks for comments,
jirka
---
Jiri Olsa (24):
perf tools: Fix 'make install prefix=...' build rule
perf tools: Remove unused trace-event-* code
perf tools: Unify page_size usage
tools list traceevent: Add plugin support
tools list traceevent: Add options support
tools list traceevent: Add plugin build support
tools list traceevent: Add traceevent_host_bigendian function tools list traceevent: Add pevent_print_func_field function tools list traceevent: Add jbd2 plugin
tools list traceevent: Add blk plugin
tools list traceevent: Add hrtimer plugin
tools list traceevent: Add kmem plugin
tools list traceevent: Add kvm plugin
tools list traceevent: Add mac80211 plugin
tools list traceevent: Add sched_switch plugin
tools list traceevent: Add function plugin
tools list traceevent: Update kvm plugin with is_writable_pte helper tools list traceevent: Add xen plugin
tools list traceevent: Add scsi plugin
tools list traceevent: Change pevent_parse_event to return event format perf tools: Add traceevents Makefile install rule
perf tools: Add trace-event object
perf tools: Add traceevent object to interface traceevent lib perf tools: Overload pr_stat traceevent print function
tools/lib/traceevent/Makefile | 57 +++++++++-- tools/lib/traceevent/event-option.c | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.c | 70 +++++++++---- tools/lib/traceevent/event-parse.h | 29 +++++- tools/lib/traceevent/event-plugin.c | 202 +++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_blk.c | 389 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_function.c | 182 +++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_hrtimer.c | 94 ++++++++++++++++++ tools/lib/traceevent/plugin_jbd2.c | 68 +++++++++++++ tools/lib/traceevent/plugin_kmem.c | 76 ++++++++++++++ tools/lib/traceevent/plugin_kvm.c | 480 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_mac80211.c | 204 +++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_sched_switch.c | 147 +++++++++++++++++++++++++++ tools/lib/traceevent/plugin_scsi.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/plugin_xen.c | 132 ++++++++++++++++++++++++ tools/perf/Makefile | 13 ++- tools/perf/builtin-record.c | 5 +- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-trace.c | 5 +- tools/perf/config/Makefile | 4 +- tools/perf/perf.c | 1 + tools/perf/util/debug.c | 16 +++ tools/perf/util/debug.h | 2 + tools/perf/util/evsel.c | 44 +------- tools/perf/util/header.c | 8 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/python.c | 1 + tools/perf/util/session.c | 2 +- tools/perf/util/session.h | 3 +- tools/perf/util/trace-event-parse.c | 53 +--------- tools/perf/util/trace-event-read.c | 20 ++-- tools/perf/util/trace-event.c | 121 ++++++++++++++++++++++ tools/perf/util/trace-event.h | 22 ++-- 33 files changed, 3002 insertions(+), 160 deletions(-) create mode 100644 tools/lib/traceevent/event-option.c create mode 100644 tools/lib/traceevent/event-plugin.c create mode 100644 tools/lib/traceevent/plugin_blk.c create mode 100644 tools/lib/traceevent/plugin_function.c create mode 100644 tools/lib/traceevent/plugin_hrtimer.c create mode 100644 tools/lib/traceevent/plugin_jbd2.c create mode 100644 tools/lib/traceevent/plugin_kmem.c create mode 100644 tools/lib/traceevent/plugin_kvm.c create mode 100644 tools/lib/traceevent/plugin_mac80211.c create mode 100644 tools/lib/traceevent/plugin_sched_switch.c create mode 100644 tools/lib/traceevent/plugin_scsi.c create mode 100644 tools/lib/traceevent/plugin_xen.c create mode 100644 tools/perf/util/trace-event.c
PATCH 1/24 perf tools: Fix 'make install prefix=...' build rule
Currently we fail for following make command:
$ sudo make install prefix=/opt/perf
...
GEN python/perf.so
install -d -m 755 '/opt/perf/bin'
install perf '/opt/perf/bin'
install perf-archive -t '/opt/perf/libexec/perf-core'
install: accessing `/opt/perf/libexec/perf-core': No such file or directory
make: *** [install-bin] Error 1Fixing this by properly creating '/opt/perf/libexec/perf-core' directory.
--- tools/perf/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/perf/Makefile +1 -0
@@ -768,6 +768,7 @@ check: $(OUTPUT)common-cmds.h install-bin: all $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)' + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' ifndef NO_LIBPERL $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
Signature · 1 line
1.7.11.7
Re: [PATCH 01/24] perf tools: Fix 'make install prefix=...' build rule
Hi Jiri,
Quoted 11 lines · Jiri Olsa
Currently we fail for following make command:
$ sudo make install prefix=/opt/perf ... GEN python/perf.so install -d -m 755 '/opt/perf/bin' install perf '/opt/perf/bin' install perf-archive -t '/opt/perf/libexec/perf-core' install: accessing `/opt/perf/libexec/perf-core': No such file or directory make: *** [install-bin] Error 1
Quoted 3 lines
Fixing this by properly creating '
/opt/perf/libexec/perf-core' directory.
Thanks,
Namhyung
PATCH 2/24 perf tools: Remove unused trace-event-* code
In reply to Jiri OlsaRemoving unused trace-event-* code.
--- tools/perf/util/trace-event-parse.c | 36 ------------------------------------ tools/perf/util/trace-event.h | 9 --------- 2 files changed, 45 deletions(-)
tools/perf/util/trace-event-parse.c +0 -36
@@ -120,42 +120,6 @@ raw_field_value(struct event_format *event, const char *name, void *data)return val; } -void *raw_field_ptr (struct event_format *event,const char *name,void *data) -{ -struct format_field *field; - - field =pevent_find_any_field (event, name); -if (!field) -return NULL ; - -if (field->flags &FIELD_IS_DYNAMIC ) { -int offset; - - offset = *(int *)(data + field->offset); - offset &=0xffff ; - -return data + offset; - } - -return data + field->offset; -} - -int trace_parse_common_type (struct pevent *pevent,void *data) -{ -struct pevent_record record; - - record.data = data; -return pevent_data_type (pevent, &record); -} - -int trace_parse_common_pid (struct pevent *pevent,void *data) -{ -struct pevent_record record; - - record.data = data; -return pevent_data_pid (pevent, &record); -} -unsigned long long read_size (struct event_format *event,void *ptr,int size) {return pevent_read_number (event->pevent, ptr, size);
tools/perf/util/trace-event.h +0 -9
@@ -11,8 +11,6 @@ union perf_event;struct perf_tool ;struct thread ; -extern struct pevent *perf_pevent; -int bigendian (void );struct pevent *read_trace_init (int file_bigendian,int host_bigendian);
@@ -23,26 +21,19 @@ int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size);int parse_event_file (struct pevent *pevent,char *buf,unsigned long size,char *sys); -struct pevent_record *trace_peek_data (struct pevent *pevent,int cpu); -unsigned long long raw_field_value (struct event_format *event,const char *name,void *data); -void *raw_field_ptr (struct event_format *event,const char *name,void *data);void parse_proc_kallsyms (struct pevent *pevent,char *file,unsigned int size);void parse_ftrace_printk (struct pevent *pevent,char *file,unsigned int size);ssize_t trace_report (int fd,struct pevent **pevent,bool repipe); -int trace_parse_common_type (struct pevent *pevent,void *data); -int trace_parse_common_pid (struct pevent *pevent,void *data); -struct event_format *trace_find_next_event (struct pevent *pevent,struct event_format *event);unsigned long long read_size (struct event_format *event,void *ptr,int size);unsigned long long eval_flag (const char *flag); -struct pevent_record *trace_read_data (struct pevent *pevent,int cpu);int read_tracing_data (int fd,struct list_head *pattrs);struct tracing_data {
Signature · 1 line
1.7.11.7
Re: [PATCH 02/24] perf tools: Remove unused trace-event-* code
Quoted 1 line · Jiri Olsa
Removing unused trace-event-* code.
Thanks,
Namhyung
PATCH 3/24 perf tools: Unify page_size usage
In reply to Jiri OlsaMaking page_size global from the util object. Removing the not needed one.
--- tools/perf/builtin-record.c | 5 +---- tools/perf/perf.c | 1 + tools/perf/util/python.c | 1 + 3 files changed, 3 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +1 -4
@@ -70,7 +70,6 @@ struct perf_record {struct perf_session *session;const char *progname;int output; -unsigned int page_size;int realtime_prio;bool no_buildid;bool no_buildid_cache;
@@ -119,7 +118,7 @@ static int perf_record__mmap_read(struct perf_record *rec, {unsigned int head =perf_mmap__read_head (md);unsigned int old = md->prev; -unsigned char *data = md->base + rec->page_size; +unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ;
@@ -360,8 +359,6 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) rec->progname = argv[0 ]; - rec->page_size =sysconf (_SC_PAGE_SIZE); -on_exit (perf_record__sig_exit, rec);signal (SIGCHLD , sig_handler);signal (SIGINT , sig_handler);
tools/perf/perf.c +1 -0
@@ -456,6 +456,7 @@ int main(int argc, const char **argv) {const char *cmd; +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cmd =perf_extract_argv0_path (argv[0 ]);
tools/perf/util/python.c +1 -0
@@ -1035,6 +1035,7 @@ PyMODINIT_FUNC initperf(void) pyrf_cpu_map__setup_types() < 0)return ; +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE);Py_INCREF (&pyrf_evlist__type);
Signature · 1 line
1.7.11.7
Re: [PATCH 03/24] perf tools: Unify page_size usage
Quoted 2 lines · Jiri Olsa
Making
page_sizeglobal from the util object.
Removing the not needed one.
Thanks,
Namhyung
PATCH 4/24 tools list traceevent: Add plugin support
In reply to Jiri OlsaBackporting plugin support for traceevent lib.
It's now possible to use following interface to load plugins for 'struct pevent' object:
struct plugin_list* traceevent_load_plugins(struct pevent *pevent)
- loads plusing for 'struct pevent' object and returns loaded plugins list
void traceevent_unload_plugins(struct plugin_list *plugin_list);
- unload plugin list
Adding -ldl dependency for perf which is needed due to plugins support.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/event-parse.h | 5 + tools/lib/traceevent/event-plugin.c | 202 ++++++++++++++++++++++++++++++++++++ tools/perf/config/Makefile | 2 +- 4 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 tools/lib/traceevent/event-plugin.c
tools/lib/traceevent/Makefile +1 -1
@@ -180,7 +180,7 @@ $(obj)/%.o: $(src)/%.c %.o: $(src)/%.c $(Q)$(call do_compile) -PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o +PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o PEVENT_LIB_OBJS += kbuffer-parse.o ALL_OBJS = $(PEVENT_LIB_OBJS)
tools/lib/traceevent/event-parse.h +5 -0
@@ -374,6 +374,11 @@ enum pevent_errno { };#undef _PE +struct plugin_list ; + +struct plugin_list *traceevent_load_plugins (struct pevent *pevent); +void traceevent_unload_plugins (struct plugin_list *plugin_list); +struct cmdline ;struct cmdline_list ;struct func_map ;
tools/lib/traceevent/event-plugin.c new file +202 -0
202 lines not on this page · raw message
tools/perf/config/Makefile +1 -1
@@ -87,7 +87,7 @@ CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -std=gnu99 -EXTLIBS = -lelf -lpthread -lrt -lm +EXTLIBS = -lelf -lpthread -lrt -lm -ldl ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y) CFLAGS += -fstack-protector-all
Signature · 1 line
1.7.11.7
Re: [PATCH 04/24] tools list traceevent: Add plugin support
Quoted 1 line · Jiri Olsa
Backporting plugin support for traceevent lib.
It would be worthwhile to not where the code is ported from -- repository and as of commit id.
David
Quoted 284 lines
It's now possible to use following interface to load plugins for 'struct pevent' object:
struct plugin_list*
traceevent_load_plugins(struct pevent *pevent)
- loads plusing for 'struct pevent' object and returns loaded plugins listvoid
traceevent_unload_plugins(struct plugin_list *plugin_list);
- unload plugin listAdding -ldl dependency for perf which is needed due to plugins support.
Signed-off-by Jiri Olsa <[email protected]>Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Steven Rostedt <[email protected]>Cc David Ahern <[email protected]>--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/event-parse.h | 5 + tools/lib/traceevent/event-plugin.c | 202 ++++++++++++++++++++++++++++++++++++ tools/perf/config/Makefile | 2 +- 4 files changed, 209 insertions(+), 2 deletions(-)create mode 100644
tools/lib/traceevent/event-plugin.ctools/lib/traceevent/Makefile +1
-1@@ -180,7 +180,7 @@ $(obj)/%.o: $(src)/%.c %.o: $(src)/%.c $(Q)$(call do_compile) -PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o +PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o PEVENT_LIB_OBJS += kbuffer-parse.o ALL_OBJS = $(PEVENT_LIB_OBJS)tools/lib/traceevent/event-parse.h +5
-0@@ -374,6 +374,11 @@ enum pevent_errno { };#undef _PE +struct plugin_list ; + +struct plugin_list *traceevent_load_plugins (struct pevent *pevent); +void traceevent_unload_plugins (struct plugin_list *plugin_list); +struct cmdline ;struct cmdline_list ;struct func_map ;tools/lib/traceevent/event-plugin.c new file +202
-0@@ -0,0 +1,202 @@ +/* +* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]> +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License (not later!) +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, see <http://www.gnu.org/licenses> +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ + +#include <string.h> +#include <dlfcn.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <dirent.h> +#include "event-parse.h" +#include "event-utils.h" + +#define LOCAL_PLUGIN_DIR ".traceevent/plugins" + +struct plugin_list { +struct plugin_list *next; +char *name; +void *handle; +}; + +static void +load_plugin (struct pevent *pevent,const char *path, +const char *file,void *data) +{ +struct plugin_list **plugin_list = data; +pevent_plugin_load_func func; +struct plugin_list *list; +const char *alias; +char *plugin; +void *handle; + + plugin =malloc_or_die (strlen (path) +strlen (file) +2 ); + +strcpy (plugin, path); +strcat (plugin,"/" ); +strcat (plugin, file); + + handle =dlopen (plugin,RTLD_NOW |RTLD_GLOBAL ); +if (!handle) { +warning ("could not load plugin '%s'\n%s\n" , + plugin,dlerror ()); + goto out_free; + } + + alias =dlsym (handle,PEVENT_PLUGIN_ALIAS_NAME ); +if (!alias) + alias = file; + + func =dlsym (handle,PEVENT_PLUGIN_LOADER_NAME ); +if (!func) { +warning ("could not find func '%s' in plugin '%s'\n%s\n" , +PEVENT_PLUGIN_LOADER_NAME , plugin,dlerror ()); + goto out_free; + } + + list =malloc_or_die (sizeof (*list)); + list->next = *plugin_list; + list->handle = handle; + list->name = plugin; + *plugin_list = list; + +pr_stat ("registering plugin: %s" , plugin); +func (pevent); +return ; + + out_free: +free (plugin); +} + +static void +load_plugins_dir (struct pevent *pevent,const char *suffix, +const char *path, +void (*load_plugin)(struct pevent *pevent, +const char *path, +const char *name, +void *data), +void *data) +{ +struct dirent *dent; +struct stat st; +DIR *dir; +int ret; + + ret =stat (path, &st); +if (ret <0 ) +return ; + +if (!S_ISDIR (st.st_mode)) +return ; + + dir =opendir (path); +if (!dir) +return ; + +while ((dent =readdir (dir))) { +const char *name = dent->d_name; + +if (strcmp (name,"." ) ==0 || +strcmp (name,".." ) ==0 ) +continue ; + +/* Only load plugins that end in suffix */ +if (strcmp (name + (strlen (name) -strlen (suffix)), suffix) !=0 ) +continue ; + +load_plugin (pevent, path, name, data); + } + +closedir (dir); +} + +static void +load_plugins (struct pevent *pevent,const char *suffix, +void (*load_plugin)(struct pevent *pevent, +const char *path, +const char *name, +void *data), +void *data) +{ +char *home; +char *path; +char *envdir; + +/* +* If a system plugin directory was defined, +* check that first. +*/ +#ifdef PLUGIN_DIR +load_plugins_dir (pevent, suffix,PLUGIN_DIR , load_plugin, data); +#endif + +/* +* Next let the environment-set plugin directory +* override the system defaults. +*/ + envdir =getenv ("TRACEEVENT_PLUGIN_DIR" ); +if (envdir) +load_plugins_dir (pevent, suffix, envdir, load_plugin, data); + +/* +* Now let the home directory override the environment +* or system defaults. +*/ + home =getenv ("HOME" ); +if (!home) +return ; + + path =malloc_or_die (strlen (home) +strlen (LOCAL_PLUGIN_DIR ) +2 ); + +strcpy (path, home); +strcat (path,"/" ); +strcat (path,LOCAL_PLUGIN_DIR ); + +load_plugins_dir (pevent, suffix, path, load_plugin, data); + +free (path); +} + +struct plugin_list * +traceevent_load_plugins (struct pevent *pevent) +{ +struct plugin_list *list =NULL ; + +load_plugins (pevent,".so" , load_plugin, &list); +return list; +} + +void +traceevent_unload_plugins (struct plugin_list *plugin_list) +{ +pevent_plugin_unload_func func; +struct plugin_list *list; + +while (plugin_list) { + list = plugin_list; + plugin_list = list->next; + func =dlsym (list->handle,PEVENT_PLUGIN_UNLOADER_NAME ); +if (func) +func (); +dlclose (list->handle); +free (list->name); +free (list); + } +}tools/perf/config/Makefile +1
-1@@ -87,7 +87,7 @@ CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -std=gnu99 -EXTLIBS = -lelf -lpthread -lrt -lm +EXTLIBS = -lelf -lpthread -lrt -lm -ldl ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y) CFLAGS += -fstack-protector-all
PATCH 5/24 tools list traceevent: Add options support
In reply to Jiri OlsaBackporting options support for traceevent lib.
It's now possible to use following interface to load options for 'struct pevent' object:
void traceevent_add_options(const char *name, struct plugin_option *options);
- adds a set of options by a plugin
void traceevent_remove_options(struct plugin_option *options);
- removes plugin options that were registered
void traceevent_add_option(const char *name, const char *val);
- modifies plugin option
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/event-option.c | 278 ++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 4 + 3 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/event-option.c
tools/lib/traceevent/Makefile +1 -1
@@ -180,7 +180,7 @@ $(obj)/%.o: $(src)/%.c %.o: $(src)/%.c $(Q)$(call do_compile) -PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o +PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o ALL_OBJS = $(PEVENT_LIB_OBJS)
tools/lib/traceevent/event-option.c new file +278 -0
278 lines not on this page · raw message
tools/lib/traceevent/event-parse.h +4 -0
@@ -110,6 +110,10 @@ struct plugin_option {int set; }; +void traceevent_add_options (const char *name,struct plugin_option *options); +void traceevent_remove_options (struct plugin_option *options); +void traceevent_add_option (const char *name,const char *val); +/* * Plugin hooks that can be called: *
Signature · 1 line
1.7.11.7
Re: [PATCH 05/24] tools list traceevent: Add options support
Quoted 1 line · Jiri Olsa
Backporting options support for traceevent lib.
ditto -- where's the code from and last commit id.
Quoted 4 lines
It's now possible to use following interface
to load options for 'struct pevent' object:
Quoted 8 lines
void
traceevent_add_options(const char *name, struct plugin_option *options);
- adds a set of options by a pluginvoid
traceevent_remove_options(struct plugin_option *options);
- removes plugin options that were registeredvoid
traceevent_add_option(const char *name, const char *val);
- modifies plugin option
And how is the code used? Take for instance the kvm plugin: would I be able to use this interface to pass in a vmlinux path to resolve guest symbols or some other option to convert RIPs in kvm tracepoints to symbols?
David
PATCH 6/24 tools list traceevent: Add plugin build support
In reply to Jiri OlsaBackporting missing pieces of plugin building infrastructure.
--- tools/lib/traceevent/Makefile | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
tools/lib/traceevent/Makefile +33 -4
@@ -43,6 +43,17 @@ man_dir_SQ = '$(subst ','\'',$(man_dir))' export man_dir man_dir_SQ INSTALL export DESTDIR DESTDIR_SQ +# Set plugin_dir to preffered global plugin location +# If we install under $HOME directory we go under +# $(HOME)/.traceevent/plugins +ifeq ($(prefix),$(HOME)) +override plugin_dir = $(HOME)/.traceevent/plugins +else +override plugin_dir ?= $(prefix)/lib/traceevent/plugins +PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" +PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' +endif + # copy a bit from Linux kbuild ifeq ("$(origin V)", "command line")
@@ -96,6 +107,7 @@ export prefix bindir src obj # Shell quotes bindir_SQ = $(subst ','\'',$(bindir)) bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) +plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) LIB_FILE = libtraceevent.a libtraceevent.so
@@ -139,7 +151,7 @@ else print_fpic_compile = echo ' CC FPIC '$(OBJ); print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ); print_plugin_obj_compile = echo ' CC PLUGIN OBJ '$(OBJ); - print_plugin_build = echo ' CC PLUGI '$(OBJ); + print_plugin_build = echo ' BUILD PLUGIN '$(OBJ); print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ); print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2'; endif
@@ -183,9 +195,11 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -ALL_OBJS = $(PEVENT_LIB_OBJS) +PLUGINS := $(PLUGIN_OBJS:.o=.so) -CMD_TARGETS = $(LIB_FILE) +ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS) + +CMD_TARGETS = $(LIB_FILE) $(PLUGINS) TARGETS = $(CMD_TARGETS)
@@ -200,9 +214,17 @@ libtraceevent.so: $(PEVENT_LIB_OBJS) libtraceevent.a: $(PEVENT_LIB_OBJS) $(Q)$(do_build_static_lib) +plugins: $(PLUGINS) + $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS $(Q)$(do_fpic_compile) +$(PLUGIN_OBJS): %.o : $(src)/%.c + $(Q)$(do_compile_plugin_obj) + +$(PLUGINS): %.so: %.o + $(Q)$(do_plugin_build) + define make_version.h (echo '/* This file is automatically generated. Do not modify. */'; \ echo \#define VERSION_CODE $(shell \
@@ -290,9 +312,16 @@ define do_install $(INSTALL) $1 '$(DESTDIR_SQ)$2' endef -install_lib: all_cmd +install_lib: all_cmd install_plugins $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ)) +PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS)) + +$(PLUGINS_INSTALL): %.install : %.so force + $(Q)$(call do_install,$<,$(plugin_dir_SQ)) + +install_plugins: $(PLUGINS_INSTALL) + install: install_lib clean:
Signature · 1 line
1.7.11.7
PATCH 7/24 tools list traceevent: Add traceevent_host_bigendian function
In reply to Jiri OlsaAdding traceevent_host_bigendian function to get host endianity. It's used in following patches.
--- tools/lib/traceevent/event-parse.h | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/lib/traceevent/event-parse.h +9 -0
@@ -526,6 +526,15 @@ __data2host8(struct pevent *pevent, unsigned long long data)__data2host8 (pevent, __val); \ }) +static inline int traceevent_host_bigendian (void ) +{ +unsigned char str[] = {0x1 ,0x2 ,0x3 ,0x4 }; +unsigned int *ptr; + + ptr = (unsigned int *)str; +return *ptr ==0x01020304 ; +} +/* taken from kernel/trace/trace.h */ enum trace_flag_type {TRACE_FLAG_IRQS_OFF =0x01 ,
Signature · 1 line
1.7.11.7
PATCH 8/24 tools list traceevent: Add pevent_print_func_field function
In reply to Jiri OlsaAdding pevent_print_func_field function to print a field and a format for function pointers. It's used in following patches.
--- tools/lib/traceevent/event-parse.c | 42 ++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 4 ++++ 2 files changed, 46 insertions(+)
tools/lib/traceevent/event-parse.c +42 -0
@@ -5326,6 +5326,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,return -1 ; } +/** +* pevent_print_func_field - print a field and a format for function pointers +* @s: The seq to print to +* @fmt: The printf format to print the field with. +* @event: the event that the field is for +* @name: The name of the field +* @record: The record with the field name. +* @err: print default error if failed. +* +* Returns: 0 on success, -1 field not found, or 1 if buffer is full. +*/ +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err) +{ +struct format_field *field =pevent_find_field (event, name); +struct pevent *pevent = event->pevent; +unsigned long long val; +struct func_map *func; +char tmp[128 ]; + +if (!field) + goto failed; + +if (pevent_read_number_field (field, record->data, &val)) + goto failed; + + func =find_func (pevent, val); + +if (func) +snprintf (tmp,128 ,"%s/0x%llx" , func->func, func->addr - val); +else +sprintf (tmp,"0x%08llx" , val); + +return trace_seq_printf (s, fmt, tmp); + + failed: +if (err) +trace_seq_printf (s,"CAN'T FIND FIELD \"%s\"" , name); +return -1 ; +} +static void free_func_handle (struct pevent_function_handler *func) {struct pevent_func_params *params;
tools/lib/traceevent/event-parse.h +4 -0
@@ -581,6 +581,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt, struct event_format *event, const char *name, struct pevent_record *record, int err); +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err); +int pevent_register_event_handler (struct pevent *pevent,int id,const char *sys_name,const char *event_name,pevent_event_handler_func func,void *context);
Signature · 1 line
1.7.11.7
PATCH 9/24 tools list traceevent: Add jbd2 plugin
In reply to Jiri OlsaBackporting jbd2 plugin.
--- tools/lib/traceevent/Makefile | 2 ++ tools/lib/traceevent/plugin_jbd2.c | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tools/lib/traceevent/plugin_jbd2.c
tools/lib/traceevent/Makefile +2 -0
@@ -195,6 +195,8 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o +PLUGIN_OBJS = plugin_jbd2.o + PLUGINS := $(PLUGIN_OBJS:.o=.so) ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
tools/lib/traceevent/plugin_jbd2.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 10/24 tools list traceevent: Add blk plugin
In reply to Jiri OlsaBackporting blk plugin.
--- tools/lib/traceevent/Makefile | 17 +- tools/lib/traceevent/plugin_blk.c | 389 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 404 insertions(+), 2 deletions(-) create mode 100644 tools/lib/traceevent/plugin_blk.c
tools/lib/traceevent/Makefile +15 -2
@@ -63,6 +63,19 @@ ifndef VERBOSE VERBOSE = 0 endif +# $(call test-build, snippet, ret) -> ret if snippet compiles +# -> empty otherwise +test-build = $(if $(shell sh -c 'echo "$(1)" | \ + $(CC) -o /dev/null -c -x c - > /dev/null 2>&1 && echo y'), $2) + +define BLK_TC_FLUSH_SOURCE +#include <linux/blktrace_api.h> +int main(void) { return BLK_TC_FLUSH; } +endef + +# have flush/fua block layer instead of barriers? +blk-flags := $(call test-build,$(BLK_TC_FLUSH_SOURCE),-DHAVE_BLK_TC_FLUSH) + ifeq ("$(origin O)", "command line") BUILD_OUTPUT := $(O) endif
@@ -133,7 +146,7 @@ CFLAGS ?= -g -Wall # Append required CFLAGS override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) -override CFLAGS += $(udis86-flags) -D_GNU_SOURCE +override CFLAGS += $(blk-flags) -D_GNU_SOURCE ifeq ($(VERBOSE),1) Q =
@@ -195,7 +208,7 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -PLUGIN_OBJS = plugin_jbd2.o +PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_blk.c new file +389 -0
389 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 11/24 tools list traceevent: Add hrtimer plugin
In reply to Jiri OlsaBackporting hrtimer plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_hrtimer.c | 94 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_hrtimer.c
tools/lib/traceevent/Makefile +1 -1
@@ -208,7 +208,7 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o +PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_hrtimer.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 12/24 tools list traceevent: Add kmem plugin
In reply to Jiri OlsaBackporting kmem plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_kmem.c | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_kmem.c
tools/lib/traceevent/Makefile +1 -1
@@ -208,7 +208,7 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o +PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_kmem.c new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 13/24 tools list traceevent: Add kvm plugin
In reply to Jiri OlsaBackporting kvm plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_kvm.c | 464 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_kvm.c
tools/lib/traceevent/Makefile +1 -1
@@ -208,7 +208,7 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o +PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_kvm.c new file +464 -0
464 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 14/24 tools list traceevent: Add mac80211 plugin
In reply to Jiri OlsaBackporting mac80211 plugin.
--- tools/lib/traceevent/Makefile | 3 +- tools/lib/traceevent/plugin_mac80211.c | 204 +++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_mac80211.c
tools/lib/traceevent/Makefile +2 -1
@@ -208,7 +208,8 @@ $(obj)/%.o: $(src)/%.c PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o event-option.o PEVENT_LIB_OBJS += kbuffer-parse.o -PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o +PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o \ + plugin_mac80211.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_mac80211.c new file +204 -0
204 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 15/24 tools list traceevent: Add sched_switch plugin
In reply to Jiri OlsaBackporting sched_switch plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_sched_switch.c | 147 +++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_sched_switch.c
tools/lib/traceevent/Makefile +1 -1
@@ -209,7 +209,7 @@ PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse- PEVENT_LIB_OBJS += kbuffer-parse.o PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o \ - plugin_mac80211.o + plugin_mac80211.o plugin_sched_switch.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_sched_switch.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 16/24 tools list traceevent: Add function plugin
In reply to Jiri OlsaBackporting function plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_function.c | 182 +++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_function.c
tools/lib/traceevent/Makefile +1 -1
@@ -209,7 +209,7 @@ PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse- PEVENT_LIB_OBJS += kbuffer-parse.o PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o \ - plugin_mac80211.o plugin_sched_switch.o + plugin_mac80211.o plugin_sched_switch.o plugin_function.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_function.c new file +182 -0
182 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 17/24 tools list traceevent: Update kvm plugin with is_writable_pte helper
In reply to Jiri OlsaAdding is_writable_pte print helper function, so the kvmmmu:fast_page_fault print format gets resolved properly.
--- tools/lib/traceevent/plugin_kvm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/lib/traceevent/plugin_kvm.c +16 -0
@@ -427,6 +427,16 @@ static int kvm_mmu_get_page_handler(struct trace_seq *s,return kvm_mmu_print_role (s, record, event, context); } +#define PT_WRITABLE_SHIFT 1 +#define PT_WRITABLE_MASK (1ULL << PT_WRITABLE_SHIFT) + +unsigned long long process_is_writable_pte (struct trace_seq *s, +unsigned long long *args) +{ +unsigned long pte = args[0 ]; +return pte &PT_WRITABLE_MASK ; +} +int PEVENT_PLUGIN_LOADER (struct pevent *pevent) {init_disassembler ();
@@ -460,5 +470,11 @@ int PEVENT_PLUGIN_LOADER(struct pevent *pevent)"kvm_mmu_prepare_zap_page" , kvm_mmu_print_role, NULL); +pevent_register_print_function (pevent, + process_is_writable_pte, +PEVENT_FUNC_ARG_INT , +"is_writable_pte" , +PEVENT_FUNC_ARG_LONG , +PEVENT_FUNC_ARG_VOID );return 0 ; }
Signature · 1 line
1.7.11.7
PATCH 18/24 tools list traceevent: Add xen plugin
In reply to Jiri OlsaAdding xen plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_xen.c | 132 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_xen.c
tools/lib/traceevent/Makefile +1 -1
@@ -209,7 +209,7 @@ PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse- PEVENT_LIB_OBJS += kbuffer-parse.o PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o \ - plugin_mac80211.o plugin_sched_switch.o plugin_function.o + plugin_mac80211.o plugin_sched_switch.o plugin_function.o plugin_xen.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_xen.c new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 19/24 tools list traceevent: Add scsi plugin
In reply to Jiri OlsaAdding scsi plugin.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/plugin_scsi.c | 431 +++++++++++++++++++++++++++++++++++++ 2 files changed, 432 insertions(+), 1 deletion(-) create mode 100644 tools/lib/traceevent/plugin_scsi.c
tools/lib/traceevent/Makefile +1 -1
@@ -209,7 +209,7 @@ PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse- PEVENT_LIB_OBJS += kbuffer-parse.o PLUGIN_OBJS = plugin_jbd2.o plugin_blk.o plugin_hrtimer.o plugin_kmem.o plugin_kvm.o \ - plugin_mac80211.o plugin_sched_switch.o plugin_function.o plugin_xen.o + plugin_mac80211.o plugin_sched_switch.o plugin_function.o plugin_xen.o plugin_scsi.o PLUGINS := $(PLUGIN_OBJS:.o=.so)
tools/lib/traceevent/plugin_scsi.c new file +431 -0
431 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 20/24 tools list traceevent: Change pevent_parse_event to return event format
In reply to Jiri OlsaChanging pevent_parse_event to return 'struct event_format', for the parsed event if the return pointer is specified.
This way we can remove pevent_parse_format which does the same stuff just without 'struct pevent' object. We will need this change in following patches.
--- tools/lib/traceevent/event-parse.c | 28 +++++++--------------------- tools/lib/traceevent/event-parse.h | 7 ++++--- tools/perf/util/evsel.c | 2 +- tools/perf/util/trace-event-parse.c | 4 ++-- 4 files changed, 14 insertions(+), 27 deletions(-)
tools/lib/traceevent/event-parse.c +7 -21
@@ -5044,25 +5044,6 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp, }/** -* pevent_parse_format - parse the event format -* @buf: the buffer storing the event format string -* @size: the size of @buf -* @sys: the system the event belongs to -* -* This parses the event format and creates an event structure -* to quickly parse raw data for a given event. -* -* These files currently come from: -* -* /sys/kernel/debug/tracing/events/.../.../format -*/ -enum pevent_errno pevent_parse_format (struct event_format **eventp,const char *buf, -unsigned long size,const char *sys) -{ -return __pevent_parse_format (eventp,NULL , buf, size, sys); -} - -/** * pevent_parse_event - parse the event format * @pevent: the handle to the pevent * @buf: the buffer storing the event format string
@@ -5076,7 +5057,9 @@ enum pevent_errno pevent_parse_format(struct event_format **eventp, const char ** * /sys/kernel/debug/tracing/events/.../.../format */ -enum pevent_errno pevent_parse_event (struct pevent *pevent,const char *buf, +enum pevent_errno pevent_parse_event (struct pevent *pevent, +struct event_format **format, +const char *buf,unsigned long size,const char *sys) {struct event_format *event =NULL ;
@@ -5085,7 +5068,7 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,if (event ==NULL )return ret; -if (add_event (pevent, event)) { +if (pevent &&add_event (pevent, event)) { ret =PEVENT_ERRNO__MEM_ALLOC_FAILED ; goto event_add_failed; }
@@ -5094,6 +5077,9 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,if (PRINT_ARGS && event->print_fmt.args)print_args (event->print_fmt.args); +if (format) + *format = event; +return 0 ; event_add_failed:
tools/lib/traceevent/event-parse.h +4 -3
@@ -557,10 +557,11 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,int pevent_parse_header_page (struct pevent *pevent,char *buf,unsigned long size,int long_size); -enum pevent_errno pevent_parse_event (struct pevent *pevent,const char *buf, +enum pevent_errno pevent_parse_event (struct pevent *pevent, +struct event_format **format, +const char *buf,unsigned long size,const char *sys); -enum pevent_errno pevent_parse_format (struct event_format **eventp,const char *buf, -unsigned long size,const char *sys); +void pevent_free_format (struct event_format *event); void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
tools/perf/util/evsel.c +1 -1
@@ -207,7 +207,7 @@ struct event_format *event_format__new(const char *sys, const char *name) size += n; }while (n >0 ); -pevent_parse_format (&format, bf, size, sys); +pevent_parse_event (NULL , &format, bf, size, sys); out_free_bf:free (bf);
tools/perf/util/trace-event-parse.c +2 -2
@@ -198,13 +198,13 @@ void parse_ftrace_printk(struct pevent *pevent,int parse_ftrace_file (struct pevent *pevent,char *buf,unsigned long size) { -return pevent_parse_event (pevent, buf, size,"ftrace" ); +return pevent_parse_event (pevent,NULL , buf, size,"ftrace" ); }int parse_event_file (struct pevent *pevent,char *buf,unsigned long size,char *sys) { -return pevent_parse_event (pevent, buf, size, sys); +return pevent_parse_event (pevent,NULL , buf, size, sys); } struct event_format *trace_find_next_event(struct pevent *pevent,
Signature · 1 line
1.7.11.7
PATCH 21/24 perf tools: Add traceevents Makefile install rule
In reply to Jiri OlsaInstructing perf to install plugins into:
$HOME/.traceevent/plugins
- if installed localy under $HOME
$(perfexecdir)/traceevent/plugins
- if installed globally
--- tools/perf/Makefile | 11 ++++++++--- tools/perf/config/Makefile | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-)
tools/perf/Makefile +8 -3
@@ -665,12 +665,14 @@ $(sort $(dir $(DIRECTORY_DEPS))): $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) +LIBTRACEEVENT_FLAGS=$(QUIET_SUBDIR1) O=$(OUTPUT) plugin_dir=$(plugindir_SQ) + # libtraceevent.a $(LIBTRACEEVENT): - $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a + $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) libtraceevent.a plugins $(LIBTRACEEVENT)-clean: - $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean + $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) clean # if subdir is set, we've been called from above so target has been built # already
@@ -684,6 +686,9 @@ ifeq ($(subdir),) $(QUIET_SUBDIR0)$(LK_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean endif +install-traceevent-plugins: + $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) install_plugins + help: @echo 'Perf make targets:' @echo ' doc - make *all* documentation (see below)'
@@ -791,7 +796,7 @@ endif $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' -install: install-bin try-install-man +install: install-bin try-install-man install-traceevent-plugins install-python_ext: $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
tools/perf/config/Makefile +2 -0
@@ -457,6 +457,7 @@ sysconfdir = $(prefix)/etc ETC_PERFCONFIG = etc/perfconfig endif lib = lib +plugindir=$(perfexecdir)/traceevent/plugins # Shell quote (do not use $(call) to accommodate ancient setups); ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
@@ -476,3 +477,4 @@ else perfexec_instdir = $(prefix)/$(perfexecdir) endif perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) +plugindir_SQ= $(subst ','\'',$(prefix)/$(plugindir))
Signature · 1 line
1.7.11.7
PATCH 22/24 perf tools: Add trace-event object
In reply to Jiri OlsaAdd trace-event object to keep together 'struct pevent' object with its loaded plugins with following interface:
int trace_event__init(struct trace_event *t);
- initalizes 'struct pevent' object and loads plugins for it
void trace_event__cleanup(struct trace_event *t);
- cleanups both 'struct pevent' and plugins
--- tools/perf/Makefile | 1 + tools/perf/builtin-script.c | 2 +- tools/perf/util/header.c | 8 ++++---- tools/perf/util/python-ext-sources | 1 + tools/perf/util/session.c | 2 +- tools/perf/util/session.h | 3 ++- tools/perf/util/trace-event-parse.c | 13 ------------- tools/perf/util/trace-event-read.c | 20 +++++++++++--------- tools/perf/util/trace-event.c | 21 +++++++++++++++++++++ tools/perf/util/trace-event.h | 13 ++++++++++--- 10 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 tools/perf/util/trace-event.c
tools/perf/Makefile +1 -0
@@ -347,6 +347,7 @@ LIB_OBJS += $(OUTPUT)util/pmu-bison.o LIB_OBJS += $(OUTPUT)util/trace-event-read.o LIB_OBJS += $(OUTPUT)util/trace-event-info.o LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o +LIB_OBJS += $(OUTPUT)util/trace-event.o LIB_OBJS += $(OUTPUT)util/svghelper.o LIB_OBJS += $(OUTPUT)util/sort.o LIB_OBJS += $(OUTPUT)util/hist.o
tools/perf/builtin-script.c +1 -1
@@ -1538,7 +1538,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)return -1 ; } - err = scripting_ops->generate_script (session->pevent, + err = scripting_ops->generate_script (session->tevent.pevent,"perf-script" ); goto out; }
tools/perf/util/header.c +4 -4
@@ -2799,11 +2799,11 @@ int perf_session__read_header(struct perf_session *session) symbol_conf.nr_events = nr_attrs; -perf_header__process_sections (header, fd, &session->pevent, +perf_header__process_sections (header, fd, &session->tevent, perf_file_section__process);if (perf_evlist__prepare_tracepoint_events (session->evlist, - session->pevent)) + session->tevent.pevent)) goto out_delete_evlist;return 0 ;
@@ -2967,7 +2967,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,lseek (session->fd, offset +sizeof (struct tracing_data_event ),SEEK_SET ); - size_read =trace_report (session->fd, &session->pevent, + size_read =trace_report (session->fd, &session->tevent, session->repipe); padding =PERF_ALIGN (size_read,sizeof (u64)) - size_read;
@@ -2989,7 +2989,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused, }perf_evlist__prepare_tracepoint_events (session->evlist, - session->pevent); + session->tevent.pevent);return size_read + padding; }
tools/perf/util/python-ext-sources +1 -0
@@ -18,4 +18,5 @@ util/cgroup.c util/rblist.c util/strlist.c util/sysfs.c +util/trace-event.c ../../lib/rbtree.c
tools/perf/util/session.c +1 -1
@@ -1637,7 +1637,7 @@ int __perf_session__set_tracepoints_handlers(struct perf_session *session, goto out_free; *name++ ='\0' ; - format =pevent_find_event_by_name (session->pevent, + format =pevent_find_event_by_name (session->tevent.pevent, tracepoint, name);if (format ==NULL ) {/*
tools/perf/util/session.h +2 -1
@@ -1,6 +1,7 @@#ifndef __PERF_SESSION_H#define __PERF_SESSION_H +#include "trace-event.h" #include "hist.h" #include "event.h" #include "header.h"
@@ -32,7 +33,7 @@ struct perf_session {unsigned long size;struct machines machines;struct perf_evlist *evlist; -struct pevent *pevent; +struct trace_event tevent;struct events_stats stats;int fd;bool fd_pipe;
tools/perf/util/trace-event-parse.c +0 -13
@@ -28,19 +28,6 @@#include "util.h" #include "trace-event.h" -struct pevent *read_trace_init (int file_bigendian,int host_bigendian) -{ -struct pevent *pevent =pevent_alloc (); - -if (pevent !=NULL ) { -pevent_set_flag (pevent,PEVENT_NSEC_OUTPUT ); -pevent_set_file_bigendian (pevent, file_bigendian); -pevent_set_host_bigendian (pevent, host_bigendian); - } - -return pevent; -} -static int get_common_field (struct scripting_context *context,int *offset,int *size,const char *type) {
tools/perf/util/trace-event-read.c +11 -9
@@ -343,7 +343,7 @@ static int read_event_files(struct pevent *pevent)return 0 ; } -ssize_t trace_report (int fd,struct pevent **ppevent,bool __repipe) +ssize_t trace_report (int fd,struct trace_event *tevent,bool __repipe) {char buf[BUFSIZ ];char test[] = {23 ,8 ,68 };
@@ -356,11 +356,9 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)int host_bigendian;int file_long_size;int file_page_size; -struct pevent *pevent; +struct pevent *pevent =NULL ;int err; - *ppevent =NULL ; - repipe = __repipe; input_fd = fd;
@@ -390,12 +388,17 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) file_bigendian = buf[0 ]; host_bigendian =bigendian (); - pevent =read_trace_init (file_bigendian, host_bigendian); -if (pevent ==NULL ) { -pr_debug ("read_trace_init failed" ); +if (trace_event__init (tevent)) { +pr_debug ("trace_event__init failed" ); goto out; } + pevent = tevent->pevent; + +pevent_set_flag (pevent,PEVENT_NSEC_OUTPUT ); +pevent_set_file_bigendian (pevent, file_bigendian); +pevent_set_host_bigendian (pevent, host_bigendian); +if (do_read (buf,1 ) <0 ) goto out; file_long_size = buf[0 ];
@@ -432,11 +435,10 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)pevent_print_printk (pevent); } - *ppevent = pevent; pevent =NULL ; out:if (pevent) -pevent_free (pevent); +trace_event__cleanup (tevent);return size; }
tools/perf/util/trace-event.c new file +21 -0
@@ -0,0 +1,21 @@ + +#include <traceevent/event-parse.h> +#include "trace-event.h" + +int trace_event__init (struct trace_event *t) +{ +struct pevent *pevent =pevent_alloc (); + +if (pevent) { + t->plugin_list =traceevent_load_plugins (pevent); + t->pevent = pevent; + } + +return pevent ?0 :-1 ; +} + +void trace_event__cleanup (struct trace_event *t) +{ +pevent_free (t->pevent); +traceevent_unload_plugins (t->plugin_list); +}
tools/perf/util/trace-event.h +10 -3
@@ -3,17 +3,24 @@#include <traceevent/event-parse.h> #include "parse-events.h" -#include "session.h" struct machine ;struct perf_sample ;union perf_event ;struct perf_tool ;struct thread ; +struct plugin_list ; + +struct trace_event { +struct pevent *pevent; +struct plugin_list *plugin_list; +}; + +int trace_event__init (struct trace_event *t); +void trace_event__cleanup (struct trace_event *t);int bigendian (void ); -struct pevent *read_trace_init (int file_bigendian,int host_bigendian);void event_format__print (struct event_format *event,int cpu,void *data,int size);
@@ -27,7 +34,7 @@ raw_field_value(struct event_format *event, const char *name, void *data);void parse_proc_kallsyms (struct pevent *pevent,char *file,unsigned int size);void parse_ftrace_printk (struct pevent *pevent,char *file,unsigned int size); -ssize_t trace_report (int fd,struct pevent **pevent,bool repipe); +ssize_t trace_report (int fd,struct trace_event *tevent,bool repipe);struct event_format *trace_find_next_event (struct pevent *pevent,struct event_format *event);
Signature · 1 line
1.7.11.7
PATCH 23/24 perf tools: Add traceevent object to interface traceevent lib
In reply to Jiri OlsaAdding traceevent object to interface traceevent lib.
--- tools/perf/builtin-trace.c | 5 ++- tools/perf/util/evsel.c | 44 +------------------ tools/perf/util/trace-event.c | 100 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/trace-event.h | 2 + 4 files changed, 107 insertions(+), 44 deletions(-)
tools/perf/builtin-trace.c +3 -2
@@ -10,6 +10,7 @@#include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h" +#include "trace-event.h" #include <libaudit.h> #include <stdlib.h>
@@ -422,11 +423,11 @@ static int trace__read_syscall_info(struct trace *trace, int id) sc->fmt =syscall_fmt__find (sc->name);snprintf (tp_name,sizeof (tp_name),"sys_enter_%s" , sc->name); - sc->tp_format =event_format__new ("syscalls" , tp_name); + sc->tp_format =trace_event__tp_format ("syscalls" , tp_name);if (sc->tp_format ==NULL && sc->fmt && sc->fmt->alias) {snprintf (tp_name,sizeof (tp_name),"sys_enter_%s" , sc->fmt->alias); - sc->tp_format =event_format__new ("syscalls" , tp_name); + sc->tp_format =trace_event__tp_format ("syscalls" , tp_name); }if (sc->tp_format ==NULL )
tools/perf/util/evsel.c +2 -42
62 lines not on this page · raw message
tools/perf/util/trace-event.c +100 -0
109 lines not on this page · raw message
tools/perf/util/trace-event.h +2 -0
@@ -18,6 +18,8 @@ struct trace_event {int trace_event__init (struct trace_event *t);void trace_event__cleanup (struct trace_event *t); +struct event_format * +trace_event__tp_format (const char *sys,const char *name);int bigendian (void );
Signature · 1 line
1.7.11.7
PATCH 24/24 perf tools: Overload pr_stat traceevent print function
In reply to Jiri OlsaThe traceevent lib uses pr_stat to display all standard info. It's defined as __weak. Overloading it with perf version plugged into perf output system logic.
Displaying the pr_stat stuff under '-v' option.
--- tools/perf/util/debug.c | 16 ++++++++++++++++ tools/perf/util/debug.h | 2 ++ 2 files changed, 18 insertions(+)
tools/perf/util/debug.c +16 -0
@@ -33,6 +33,22 @@ int eprintf(int level, const char *fmt, ...)return ret; } +/* +* Overloading libtraceevent standard info print +* function, display with -v in perf. +*/ +void pr_stat (const char *fmt, ...) +{ +va_list args; + +if (verbose >=1 ) { +va_start (args, fmt); +vfprintf (stderr, fmt, args); +fprintf (stderr,"\n" ); +va_end (args); + } +} +int dump_printf (const char *fmt, ...) {va_list args;
tools/perf/util/debug.h +2 -0
@@ -17,4 +17,6 @@ void trace_event(union perf_event *event);int ui__error (const char *format, ...) __attribute__((format (printf,1 ,2 )));int ui__warning (const char *format, ...) __attribute__((format (printf,1 ,2 ))); +void pr_stat (const char *fmt, ...); +#endif /* __PERF_DEBUG_H */
Signature · 1 line
1.7.11.7
Quoted 2 lines · Jiri Olsa
hi,
backporting traceevent plugin support from trace-cmd.
It's reachable here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_plugins
jirka