perf tools : adds support for native scripting
PATCH 1/1 perf tools : adds support for native scripting
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.
---
tools/perf/Makefile.perf +7 -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/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;
Quoted 5 lines · Adrien BAK
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.
You'll at least need some documentation how to use it.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
Quoted 8 lines · On Thursday 22 May 2014 04:24:11 Andi Kleen wrote:
Quoted 5 lines · Adrien BAK
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.You'll at least need some documentation how to use it.
Ping, any news on this feature? I'd welcome the ability to create native scripts to write efficient tools based on perf.
Bye
Signature · 3 lines
Milian Wolff [email protected] http://milianw.de