Re: [PATCH 1/3] perf script: Add general python handler to processnon-tracepoint events

From: Feng Tang
Date: Thu May 17 2012 - 22:52:09 EST


Hi Arnaldo,

Thanks for your review!

On Thu, 17 May 2012 12:43:15 -0300
Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:

> Em Wed, May 16, 2012 at 08:59:13PM +0800, Feng Tang escreveu:
> > This patch just follows Robert Richter's idea and the commit 37a058ea0
> > "perf script: Add generic perl handler to process events"
> > to similarly add a python handler for general events other than tracepoints.
> >
> > For non-tracepoint events, this patch will try to find a function named
> > "process_general_event" in the python script, and pass the event
>
> But in perl isn't it named "process_event"? Can't we use the same
> convention in the python case?

Good point, will comply with the perl code.

>
> > header, attribute, perf_sample, raw_data in format of raw string. And
> > the python script can use "struct" module's unpack function to disasemble
> > the needed info and process.
> >
> > Signed-off-by: Feng Tang <feng.tang@xxxxxxxxx>
> > ---
> > .../util/scripting-engines/trace-event-python.c | 60
> > +++++++++++++++++++- 1 files changed, 59 insertions(+), 1 deletions(-)
> >
> > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c
> > b/tools/perf/util/scripting-engines/trace-event-python.c index
> > c2623c6..aaf2679 100644 ---
> > a/tools/perf/util/scripting-engines/trace-event-python.c +++
> > b/tools/perf/util/scripting-engines/trace-event-python.c @@ -324,6 +325,63
> > @@ static void python_process_event(union perf_event *pevent __unused,
> > Py_DECREF(t); }
> >
> > +static void python_process_general_event(union perf_event *pevent __unused,
> > + struct perf_sample *sample,
> > + struct perf_evsel *evsel __unused,
> > + struct machine *machine __unused,
> > + struct thread *thread __unused)
> > +{
> > + PyObject *handler, *retval, *t;
> > + static char handler_name[64];
> > + unsigned n = 0;
> > + void *data = sample->raw_data;
> > +
> > + t = PyTuple_New(MAX_FIELDS);
> > + if (!t)
> > + Py_FatalError("couldn't create Python tuple");
> > +
> > + sprintf(handler_name, "process_general_event");
>
> Strange use of sprintf, if you think it is safe to not bounds check, use
> strcpy(), if you still want to use sprintf, please instead use:
>
> snprintf(handler_name, sizeof(handler_name), "%s", "process_event");

Ok, will change it. Following is the update patch: