extends perf-script to native scripts (updated)
PATCH 1/1 extends perf-script to native scripts (updated)
As it is perf-script allows one to use perl or python scripts to parse perf events. The following proposal aimed to introduce support of .so files as scripts. This support allows for better performance when parsing perf's data files and a complete access to the raw data.
This support is implemented analogously to the one in place for perl/python script. More precisely, when passing a .so file as a script argument, the following symbols are loaded :
- start_script
- stop_script
- process_event
These symbols will be called instead of the corresponding :
- default_start_script
- default_stop_script
- process_event
There currently is a limitation regarding the generate_script function which cannot be generalized to native scripts. Is it better to leave things as they are (die gracefully when the user asks for native_generate_script) or to do one of the following :
- print a usage message specifying the symbols a .so script should
expose
- create a .c file complying with said interface
Regarding style compliance, the following issues remains :
- 3 'fprintf' lines slightly over 80 chars in trace-event-native. Is it better to introduce a line break than to have a 83-chars
long line?
- in trace-event-scripting.c a struct is declared as extern. Here,
I followed
what was already done for perl/python scripting.
Since the first time this was submitted, the following change was added:
- a local variable (error) in trace-event-native.c could shadow a
goto label.
A compilation error could then occur with gcc 4.7. The variable has
been renamed
to avoid that.
Thank you for your time and valued input.
---
tools/perf/Makefile.perf +4 -0
@@ -543,6 +543,10 @@ ifndef NO_LIBPYTHON LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o endif +ifndef NO_NATIVE_SCRIPTING + LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-native.o +endif + ifeq ($(NO_PERF_REGS),0) ifeq ($(ARCH),x86) LIB_H += arch/x86/include/perf_regs.h
@@ -715,6 +719,9 @@ $(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/tra $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o:
scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS)
-Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+$(OUTPUT)util/scripting-engines/trace-event-native.o: util/scripting-engines/trace-event-native.c $(OUTPUT)PERF-CFLAGS
+ $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+
$(OUTPUT)perf-%: %.o $(PERFLIBS)
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
tools/perf/PERF-FEATURES new file +1 -0
@@ -0,0 +1 @@ +feature-dwarf(1) feature-glibc(1) feature-gtk2(1) feature-libaudit(1) feature-libbfd(1) feature-libelf(1) feature-libnuma(1) feature-libperl(0) feature-libpython(1) feature-libslang(1) feature-libunwind(1) feature-libdw-dwarf-unwind(0) dwarf-post-unwind(libunwind)
tools/perf/builtin-script.c +1 -0
@@ -522,6 +522,7 @@ static void setup_scripting(void) {setup_perl_scripting ();setup_python_scripting (); +setup_native_scripting (); scripting_ops = &default_scripting_ops; }
tools/perf/util/scripting-engines/trace-event-native.c new file +125 -0
125 lines not on this page · raw message
tools/perf/util/trace-event-scripting.c +22 -0
@@ -169,3 +169,25 @@ void setup_perl_scripting(void) register_perl_scripting(&perl_scripting_ops); }#endif + + + +extern struct scripting_ops native_scripting_ops; + +void setup_native_scripting (void ) +{ +int err; + err =script_spec_register ("Native" , &native_scripting_ops); +if (err) +die ("error registering Native script extension" ); + + err =script_spec_register ("so" , &native_scripting_ops); +if (err) +die ("error registering so script extension" ); + + scripting_context =malloc (sizeof (struct scripting_context )); +} + + + +
tools/perf/util/trace-event.h +1 -0
@@ -77,6 +77,7 @@ int script_spec_register(const char *spec, struct scripting_ops *ops);void setup_perl_scripting (void );void setup_python_scripting (void ); +void setup_native_scripting (void );struct scripting_context {struct pevent *pevent;