Skip to content

Commit

Permalink
perf db-export: Export synth events
Browse files Browse the repository at this point in the history
Synthesized events are samples but with architecture-specific data
stored in sample->raw_data. They are identified by attribute type
PERF_TYPE_SYNTH.  Add a function to export them.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190622093248.581-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
ahunter6 authored and acmel committed Jun 25, 2019
1 parent 5fe2cf7 commit b9322ca
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions tools/perf/util/scripting-engines/trace-event-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct tables {
PyObject *sample_handler;
PyObject *call_path_handler;
PyObject *call_return_handler;
PyObject *synth_handler;
bool db_export_mode;
};

Expand Down Expand Up @@ -947,6 +948,12 @@ static int tuple_set_string(PyObject *t, unsigned int pos, const char *s)
return PyTuple_SetItem(t, pos, _PyUnicode_FromString(s));
}

static int tuple_set_bytes(PyObject *t, unsigned int pos, void *bytes,
unsigned int sz)
{
return PyTuple_SetItem(t, pos, _PyBytes_FromStringAndSize(bytes, sz));
}

static int python_export_evsel(struct db_export *dbe, struct perf_evsel *evsel)
{
struct tables *tables = container_of(dbe, struct tables, dbe);
Expand Down Expand Up @@ -1105,8 +1112,8 @@ static int python_export_branch_type(struct db_export *dbe, u32 branch_type,
return 0;
}

static int python_export_sample(struct db_export *dbe,
struct export_sample *es)
static void python_export_sample_table(struct db_export *dbe,
struct export_sample *es)
{
struct tables *tables = container_of(dbe, struct tables, dbe);
PyObject *t;
Expand Down Expand Up @@ -1141,6 +1148,33 @@ static int python_export_sample(struct db_export *dbe,
call_object(tables->sample_handler, t, "sample_table");

Py_DECREF(t);
}

static void python_export_synth(struct db_export *dbe, struct export_sample *es)
{
struct tables *tables = container_of(dbe, struct tables, dbe);
PyObject *t;

t = tuple_new(3);

tuple_set_u64(t, 0, es->db_id);
tuple_set_u64(t, 1, es->evsel->attr.config);
tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size);

call_object(tables->synth_handler, t, "synth_data");

Py_DECREF(t);
}

static int python_export_sample(struct db_export *dbe,
struct export_sample *es)
{
struct tables *tables = container_of(dbe, struct tables, dbe);

python_export_sample_table(dbe, es);

if (es->evsel->attr.type == PERF_TYPE_SYNTH && tables->synth_handler)
python_export_synth(dbe, es);

return 0;
}
Expand Down Expand Up @@ -1477,6 +1511,14 @@ static void set_table_handlers(struct tables *tables)
SET_TABLE_HANDLER(sample);
SET_TABLE_HANDLER(call_path);
SET_TABLE_HANDLER(call_return);

/*
* Synthesized events are samples but with architecture-specific data
* stored in sample->raw_data. They are exported via
* python_export_sample() and consequently do not need a separate export
* callback.
*/
tables->synth_handler = get_handler("synth_data");
}

#if PY_MAJOR_VERSION < 3
Expand Down

0 comments on commit b9322ca

Please sign in to comment.