Skip to content

Commit b9322ca

Browse files
ahunter6acmel
authored andcommitted
perf db-export: Export synth events
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>
1 parent 5fe2cf7 commit b9322ca

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

‎tools/perf/util/scripting-engines/trace-event-python.c‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct tables {
112112
PyObject *sample_handler;
113113
PyObject *call_path_handler;
114114
PyObject *call_return_handler;
115+
PyObject *synth_handler;
115116
bool db_export_mode;
116117
};
117118

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

951+
static int tuple_set_bytes(PyObject *t, unsigned int pos, void *bytes,
952+
unsigned int sz)
953+
{
954+
return PyTuple_SetItem(t, pos, _PyBytes_FromStringAndSize(bytes, sz));
955+
}
956+
950957
static int python_export_evsel(struct db_export *dbe, struct perf_evsel *evsel)
951958
{
952959
struct tables *tables = container_of(dbe, struct tables, dbe);
@@ -1105,8 +1112,8 @@ static int python_export_branch_type(struct db_export *dbe, u32 branch_type,
11051112
return 0;
11061113
}
11071114

1108-
static int python_export_sample(struct db_export *dbe,
1109-
struct export_sample *es)
1115+
static void python_export_sample_table(struct db_export *dbe,
1116+
struct export_sample *es)
11101117
{
11111118
struct tables *tables = container_of(dbe, struct tables, dbe);
11121119
PyObject *t;
@@ -1141,6 +1148,33 @@ static int python_export_sample(struct db_export *dbe,
11411148
call_object(tables->sample_handler, t, "sample_table");
11421149

11431150
Py_DECREF(t);
1151+
}
1152+
1153+
static void python_export_synth(struct db_export *dbe, struct export_sample *es)
1154+
{
1155+
struct tables *tables = container_of(dbe, struct tables, dbe);
1156+
PyObject *t;
1157+
1158+
t = tuple_new(3);
1159+
1160+
tuple_set_u64(t, 0, es->db_id);
1161+
tuple_set_u64(t, 1, es->evsel->attr.config);
1162+
tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size);
1163+
1164+
call_object(tables->synth_handler, t, "synth_data");
1165+
1166+
Py_DECREF(t);
1167+
}
1168+
1169+
static int python_export_sample(struct db_export *dbe,
1170+
struct export_sample *es)
1171+
{
1172+
struct tables *tables = container_of(dbe, struct tables, dbe);
1173+
1174+
python_export_sample_table(dbe, es);
1175+
1176+
if (es->evsel->attr.type == PERF_TYPE_SYNTH && tables->synth_handler)
1177+
python_export_synth(dbe, es);
11441178

11451179
return 0;
11461180
}
@@ -1477,6 +1511,14 @@ static void set_table_handlers(struct tables *tables)
14771511
SET_TABLE_HANDLER(sample);
14781512
SET_TABLE_HANDLER(call_path);
14791513
SET_TABLE_HANDLER(call_return);
1514+
1515+
/*
1516+
* Synthesized events are samples but with architecture-specific data
1517+
* stored in sample->raw_data. They are exported via
1518+
* python_export_sample() and consequently do not need a separate export
1519+
* callback.
1520+
*/
1521+
tables->synth_handler = get_handler("synth_data");
14801522
}
14811523

14821524
#if PY_MAJOR_VERSION < 3

0 commit comments

Comments
 (0)