blob: a8ca2f8179a951beb7b5fec1f0422e51063bd5fd [file] [log] [blame]
Tom Zanussi7e4b21b2010-01-27 02:27:57 -06001/*
2 * trace-event-python. Feed trace events to an embedded Python interpreter.
3 *
4 * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <Python.h>
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060027#include <errno.h>
28
29#include "../../perf.h"
30#include "../util.h"
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020031#include "../event.h"
32#include "../thread.h"
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060033#include "../trace-event.h"
34
35PyMODINIT_FUNC initperf_trace_context(void);
36
37#define FTRACE_MAX_EVENT \
38 ((1 << (sizeof(unsigned short) * 8)) - 1)
39
Steven Rostedtaaf045f2012-04-06 00:47:56 +020040struct event_format *events[FTRACE_MAX_EVENT];
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060041
42#define MAX_FIELDS 64
43#define N_COMMON_FIELDS 7
44
45extern struct scripting_context *scripting_context;
46
47static char *cur_field_name;
48static int zero_flag_atom;
49
50static PyObject *main_module, *main_dict;
51
52static void handler_call_die(const char *handler_name)
53{
54 PyErr_Print();
55 Py_FatalError("problem in Python trace event handler");
56}
57
58static void define_value(enum print_arg_type field_type,
59 const char *ev_name,
60 const char *field_name,
61 const char *field_value,
62 const char *field_str)
63{
64 const char *handler_name = "define_flag_value";
65 PyObject *handler, *t, *retval;
66 unsigned long long value;
67 unsigned n = 0;
68
69 if (field_type == PRINT_SYMBOL)
70 handler_name = "define_symbolic_value";
71
Tom Zanussi44ad9cd2010-02-22 01:12:59 -060072 t = PyTuple_New(4);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060073 if (!t)
74 Py_FatalError("couldn't create Python tuple");
75
76 value = eval_flag(field_value);
77
78 PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
79 PyTuple_SetItem(t, n++, PyString_FromString(field_name));
80 PyTuple_SetItem(t, n++, PyInt_FromLong(value));
81 PyTuple_SetItem(t, n++, PyString_FromString(field_str));
82
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060083 handler = PyDict_GetItemString(main_dict, handler_name);
84 if (handler && PyCallable_Check(handler)) {
85 retval = PyObject_CallObject(handler, t);
86 if (retval == NULL)
87 handler_call_die(handler_name);
88 }
89
90 Py_DECREF(t);
91}
92
93static void define_values(enum print_arg_type field_type,
94 struct print_flag_sym *field,
95 const char *ev_name,
96 const char *field_name)
97{
98 define_value(field_type, ev_name, field_name, field->value,
99 field->str);
100
101 if (field->next)
102 define_values(field_type, field->next, ev_name, field_name);
103}
104
105static void define_field(enum print_arg_type field_type,
106 const char *ev_name,
107 const char *field_name,
108 const char *delim)
109{
110 const char *handler_name = "define_flag_field";
111 PyObject *handler, *t, *retval;
112 unsigned n = 0;
113
114 if (field_type == PRINT_SYMBOL)
115 handler_name = "define_symbolic_field";
116
Tom Zanussi44ad9cd2010-02-22 01:12:59 -0600117 if (field_type == PRINT_FLAGS)
118 t = PyTuple_New(3);
119 else
120 t = PyTuple_New(2);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600121 if (!t)
122 Py_FatalError("couldn't create Python tuple");
123
124 PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
125 PyTuple_SetItem(t, n++, PyString_FromString(field_name));
126 if (field_type == PRINT_FLAGS)
127 PyTuple_SetItem(t, n++, PyString_FromString(delim));
128
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600129 handler = PyDict_GetItemString(main_dict, handler_name);
130 if (handler && PyCallable_Check(handler)) {
131 retval = PyObject_CallObject(handler, t);
132 if (retval == NULL)
133 handler_call_die(handler_name);
134 }
135
136 Py_DECREF(t);
137}
138
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200139static void define_event_symbols(struct event_format *event,
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600140 const char *ev_name,
141 struct print_arg *args)
142{
143 switch (args->type) {
144 case PRINT_NULL:
145 break;
146 case PRINT_ATOM:
147 define_value(PRINT_FLAGS, ev_name, cur_field_name, "0",
148 args->atom.atom);
149 zero_flag_atom = 0;
150 break;
151 case PRINT_FIELD:
152 if (cur_field_name)
153 free(cur_field_name);
154 cur_field_name = strdup(args->field.name);
155 break;
156 case PRINT_FLAGS:
157 define_event_symbols(event, ev_name, args->flags.field);
158 define_field(PRINT_FLAGS, ev_name, cur_field_name,
159 args->flags.delim);
160 define_values(PRINT_FLAGS, args->flags.flags, ev_name,
161 cur_field_name);
162 break;
163 case PRINT_SYMBOL:
164 define_event_symbols(event, ev_name, args->symbol.field);
165 define_field(PRINT_SYMBOL, ev_name, cur_field_name, NULL);
166 define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name,
167 cur_field_name);
168 break;
169 case PRINT_STRING:
170 break;
171 case PRINT_TYPE:
172 define_event_symbols(event, ev_name, args->typecast.item);
173 break;
174 case PRINT_OP:
175 if (strcmp(args->op.op, ":") == 0)
176 zero_flag_atom = 1;
177 define_event_symbols(event, ev_name, args->op.left);
178 define_event_symbols(event, ev_name, args->op.right);
179 break;
180 default:
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200181 /* gcc warns for these? */
182 case PRINT_BSTRING:
183 case PRINT_DYNAMIC_ARRAY:
184 case PRINT_FUNC:
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600185 /* we should warn... */
186 return;
187 }
188
189 if (args->next)
190 define_event_symbols(event, ev_name, args->next);
191}
192
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300193static inline
194struct event_format *find_cache_event(struct pevent *pevent, int type)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600195{
196 static char ev_name[256];
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200197 struct event_format *event;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600198
199 if (events[type])
200 return events[type];
201
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300202 events[type] = event = pevent_find_event(pevent, type);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600203 if (!event)
204 return NULL;
205
206 sprintf(ev_name, "%s__%s", event->system, event->name);
207
208 define_event_symbols(event, ev_name, event->print_fmt.args);
209
210 return event;
211}
212
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300213static void python_process_event(union perf_event *perf_event __unused,
214 struct pevent *pevent,
David Ahernbe6d8422011-03-09 22:23:23 -0700215 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300216 struct perf_evsel *evsel __unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200217 struct machine *machine __unused,
David Ahernbe6d8422011-03-09 22:23:23 -0700218 struct thread *thread)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600219{
Pierre Tardyc0251482010-05-31 23:12:09 +0200220 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600221 static char handler_name[256];
222 struct format_field *field;
223 unsigned long long val;
224 unsigned long s, ns;
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200225 struct event_format *event;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600226 unsigned n = 0;
227 int type;
228 int pid;
David Ahernbe6d8422011-03-09 22:23:23 -0700229 int cpu = sample->cpu;
230 void *data = sample->raw_data;
231 unsigned long long nsecs = sample->time;
232 char *comm = thread->comm;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600233
234 t = PyTuple_New(MAX_FIELDS);
235 if (!t)
236 Py_FatalError("couldn't create Python tuple");
237
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300238 type = trace_parse_common_type(pevent, data);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600239
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300240 event = find_cache_event(pevent, type);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600241 if (!event)
242 die("ug! no event found for type %d", type);
243
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300244 pid = trace_parse_common_pid(pevent, data);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600245
246 sprintf(handler_name, "%s__%s", event->system, event->name);
247
Pierre Tardyc0251482010-05-31 23:12:09 +0200248 handler = PyDict_GetItemString(main_dict, handler_name);
249 if (handler && !PyCallable_Check(handler))
250 handler = NULL;
251 if (!handler) {
252 dict = PyDict_New();
253 if (!dict)
254 Py_FatalError("couldn't create Python dict");
255 }
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600256 s = nsecs / NSECS_PER_SEC;
257 ns = nsecs - s * NSECS_PER_SEC;
258
259 scripting_context->event_data = data;
260
261 context = PyCObject_FromVoidPtr(scripting_context, NULL);
262
263 PyTuple_SetItem(t, n++, PyString_FromString(handler_name));
Kyle McMartinfb7d0b32011-01-24 11:13:04 -0500264 PyTuple_SetItem(t, n++, context);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600265
Pierre Tardyc0251482010-05-31 23:12:09 +0200266 if (handler) {
267 PyTuple_SetItem(t, n++, PyInt_FromLong(cpu));
268 PyTuple_SetItem(t, n++, PyInt_FromLong(s));
269 PyTuple_SetItem(t, n++, PyInt_FromLong(ns));
270 PyTuple_SetItem(t, n++, PyInt_FromLong(pid));
271 PyTuple_SetItem(t, n++, PyString_FromString(comm));
272 } else {
273 PyDict_SetItemString(dict, "common_cpu", PyInt_FromLong(cpu));
274 PyDict_SetItemString(dict, "common_s", PyInt_FromLong(s));
275 PyDict_SetItemString(dict, "common_ns", PyInt_FromLong(ns));
276 PyDict_SetItemString(dict, "common_pid", PyInt_FromLong(pid));
277 PyDict_SetItemString(dict, "common_comm", PyString_FromString(comm));
278 }
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600279 for (field = event->format.fields; field; field = field->next) {
280 if (field->flags & FIELD_IS_STRING) {
281 int offset;
282 if (field->flags & FIELD_IS_DYNAMIC) {
283 offset = *(int *)(data + field->offset);
284 offset &= 0xffff;
285 } else
286 offset = field->offset;
Tom Zanussib1dcc032010-04-01 23:58:25 -0500287 obj = PyString_FromString((char *)data + offset);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600288 } else { /* FIELD_IS_NUMERIC */
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300289 val = read_size(pevent, data + field->offset,
290 field->size);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600291 if (field->flags & FIELD_IS_SIGNED) {
Tom Zanussib1dcc032010-04-01 23:58:25 -0500292 if ((long long)val >= LONG_MIN &&
293 (long long)val <= LONG_MAX)
294 obj = PyInt_FromLong(val);
295 else
296 obj = PyLong_FromLongLong(val);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600297 } else {
Tom Zanussib1dcc032010-04-01 23:58:25 -0500298 if (val <= LONG_MAX)
299 obj = PyInt_FromLong(val);
300 else
301 obj = PyLong_FromUnsignedLongLong(val);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600302 }
303 }
Pierre Tardyc0251482010-05-31 23:12:09 +0200304 if (handler)
305 PyTuple_SetItem(t, n++, obj);
306 else
307 PyDict_SetItemString(dict, field->name, obj);
308
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600309 }
Pierre Tardyc0251482010-05-31 23:12:09 +0200310 if (!handler)
311 PyTuple_SetItem(t, n++, dict);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600312
313 if (_PyTuple_Resize(&t, n) == -1)
314 Py_FatalError("error resizing Python tuple");
315
Pierre Tardyc0251482010-05-31 23:12:09 +0200316 if (handler) {
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600317 retval = PyObject_CallObject(handler, t);
318 if (retval == NULL)
319 handler_call_die(handler_name);
320 } else {
321 handler = PyDict_GetItemString(main_dict, "trace_unhandled");
322 if (handler && PyCallable_Check(handler)) {
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600323
324 retval = PyObject_CallObject(handler, t);
325 if (retval == NULL)
326 handler_call_die("trace_unhandled");
327 }
Pierre Tardyc0251482010-05-31 23:12:09 +0200328 Py_DECREF(dict);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600329 }
330
331 Py_DECREF(t);
332}
333
334static int run_start_sub(void)
335{
336 PyObject *handler, *retval;
337 int err = 0;
338
339 main_module = PyImport_AddModule("__main__");
340 if (main_module == NULL)
341 return -1;
342 Py_INCREF(main_module);
343
344 main_dict = PyModule_GetDict(main_module);
345 if (main_dict == NULL) {
346 err = -1;
347 goto error;
348 }
349 Py_INCREF(main_dict);
350
351 handler = PyDict_GetItemString(main_dict, "trace_begin");
352 if (handler == NULL || !PyCallable_Check(handler))
353 goto out;
354
355 retval = PyObject_CallObject(handler, NULL);
356 if (retval == NULL)
357 handler_call_die("trace_begin");
358
359 Py_DECREF(retval);
360 return err;
361error:
362 Py_XDECREF(main_dict);
363 Py_XDECREF(main_module);
364out:
365 return err;
366}
367
368/*
369 * Start trace script
370 */
371static int python_start_script(const char *script, int argc, const char **argv)
372{
373 const char **command_line;
374 char buf[PATH_MAX];
375 int i, err = 0;
376 FILE *fp;
377
378 command_line = malloc((argc + 1) * sizeof(const char *));
379 command_line[0] = script;
380 for (i = 1; i < argc + 1; i++)
381 command_line[i] = argv[i - 1];
382
383 Py_Initialize();
384
385 initperf_trace_context();
386
387 PySys_SetArgv(argc + 1, (char **)command_line);
388
389 fp = fopen(script, "r");
390 if (!fp) {
391 sprintf(buf, "Can't open python script \"%s\"", script);
392 perror(buf);
393 err = -1;
394 goto error;
395 }
396
397 err = PyRun_SimpleFile(fp, script);
398 if (err) {
399 fprintf(stderr, "Error running python script %s\n", script);
400 goto error;
401 }
402
403 err = run_start_sub();
404 if (err) {
405 fprintf(stderr, "Error starting python script %s\n", script);
406 goto error;
407 }
408
409 free(command_line);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600410
411 return err;
412error:
413 Py_Finalize();
414 free(command_line);
415
416 return err;
417}
418
419/*
420 * Stop trace script
421 */
422static int python_stop_script(void)
423{
424 PyObject *handler, *retval;
425 int err = 0;
426
427 handler = PyDict_GetItemString(main_dict, "trace_end");
428 if (handler == NULL || !PyCallable_Check(handler))
429 goto out;
430
431 retval = PyObject_CallObject(handler, NULL);
432 if (retval == NULL)
433 handler_call_die("trace_end");
434 else
435 Py_DECREF(retval);
436out:
437 Py_XDECREF(main_dict);
438 Py_XDECREF(main_module);
439 Py_Finalize();
440
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600441 return err;
442}
443
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300444static int python_generate_script(struct pevent *pevent, const char *outfile)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600445{
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200446 struct event_format *event = NULL;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600447 struct format_field *f;
448 char fname[PATH_MAX];
449 int not_first, count;
450 FILE *ofp;
451
452 sprintf(fname, "%s.py", outfile);
453 ofp = fopen(fname, "w");
454 if (ofp == NULL) {
455 fprintf(stderr, "couldn't open %s\n", fname);
456 return -1;
457 }
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100458 fprintf(ofp, "# perf script event handlers, "
459 "generated by perf script -g python\n");
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600460
461 fprintf(ofp, "# Licensed under the terms of the GNU GPL"
462 " License version 2\n\n");
463
464 fprintf(ofp, "# The common_* event handler fields are the most useful "
465 "fields common to\n");
466
467 fprintf(ofp, "# all events. They don't necessarily correspond to "
468 "the 'common_*' fields\n");
469
470 fprintf(ofp, "# in the format files. Those fields not available as "
471 "handler params can\n");
472
473 fprintf(ofp, "# be retrieved using Python functions of the form "
474 "common_*(context).\n");
475
476 fprintf(ofp, "# See the perf-trace-python Documentation for the list "
477 "of available functions.\n\n");
478
479 fprintf(ofp, "import os\n");
480 fprintf(ofp, "import sys\n\n");
481
482 fprintf(ofp, "sys.path.append(os.environ['PERF_EXEC_PATH'] + \\\n");
483 fprintf(ofp, "\t'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')\n");
484 fprintf(ofp, "\nfrom perf_trace_context import *\n");
485 fprintf(ofp, "from Core import *\n\n\n");
486
487 fprintf(ofp, "def trace_begin():\n");
488 fprintf(ofp, "\tprint \"in trace_begin\"\n\n");
489
490 fprintf(ofp, "def trace_end():\n");
491 fprintf(ofp, "\tprint \"in trace_end\"\n\n");
492
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300493 while ((event = trace_find_next_event(pevent, event))) {
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600494 fprintf(ofp, "def %s__%s(", event->system, event->name);
495 fprintf(ofp, "event_name, ");
496 fprintf(ofp, "context, ");
497 fprintf(ofp, "common_cpu,\n");
498 fprintf(ofp, "\tcommon_secs, ");
499 fprintf(ofp, "common_nsecs, ");
500 fprintf(ofp, "common_pid, ");
501 fprintf(ofp, "common_comm,\n\t");
502
503 not_first = 0;
504 count = 0;
505
506 for (f = event->format.fields; f; f = f->next) {
507 if (not_first++)
508 fprintf(ofp, ", ");
509 if (++count % 5 == 0)
510 fprintf(ofp, "\n\t");
511
512 fprintf(ofp, "%s", f->name);
513 }
514 fprintf(ofp, "):\n");
515
516 fprintf(ofp, "\t\tprint_header(event_name, common_cpu, "
517 "common_secs, common_nsecs,\n\t\t\t"
518 "common_pid, common_comm)\n\n");
519
520 fprintf(ofp, "\t\tprint \"");
521
522 not_first = 0;
523 count = 0;
524
525 for (f = event->format.fields; f; f = f->next) {
526 if (not_first++)
527 fprintf(ofp, ", ");
528 if (count && count % 3 == 0) {
529 fprintf(ofp, "\" \\\n\t\t\"");
530 }
531 count++;
532
533 fprintf(ofp, "%s=", f->name);
534 if (f->flags & FIELD_IS_STRING ||
535 f->flags & FIELD_IS_FLAG ||
536 f->flags & FIELD_IS_SYMBOLIC)
537 fprintf(ofp, "%%s");
538 else if (f->flags & FIELD_IS_SIGNED)
539 fprintf(ofp, "%%d");
540 else
541 fprintf(ofp, "%%u");
542 }
543
544 fprintf(ofp, "\\n\" %% \\\n\t\t(");
545
546 not_first = 0;
547 count = 0;
548
549 for (f = event->format.fields; f; f = f->next) {
550 if (not_first++)
551 fprintf(ofp, ", ");
552
553 if (++count % 5 == 0)
554 fprintf(ofp, "\n\t\t");
555
556 if (f->flags & FIELD_IS_FLAG) {
557 if ((count - 1) % 5 != 0) {
558 fprintf(ofp, "\n\t\t");
559 count = 4;
560 }
561 fprintf(ofp, "flag_str(\"");
562 fprintf(ofp, "%s__%s\", ", event->system,
563 event->name);
564 fprintf(ofp, "\"%s\", %s)", f->name,
565 f->name);
566 } else if (f->flags & FIELD_IS_SYMBOLIC) {
567 if ((count - 1) % 5 != 0) {
568 fprintf(ofp, "\n\t\t");
569 count = 4;
570 }
571 fprintf(ofp, "symbol_str(\"");
572 fprintf(ofp, "%s__%s\", ", event->system,
573 event->name);
574 fprintf(ofp, "\"%s\", %s)", f->name,
575 f->name);
576 } else
577 fprintf(ofp, "%s", f->name);
578 }
579
580 fprintf(ofp, "),\n\n");
581 }
582
583 fprintf(ofp, "def trace_unhandled(event_name, context, "
Pierre Tardyc0251482010-05-31 23:12:09 +0200584 "event_fields_dict):\n");
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600585
Pierre Tardyc0251482010-05-31 23:12:09 +0200586 fprintf(ofp, "\t\tprint ' '.join(['%%s=%%s'%%(k,str(v))"
587 "for k,v in sorted(event_fields_dict.items())])\n\n");
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600588
589 fprintf(ofp, "def print_header("
590 "event_name, cpu, secs, nsecs, pid, comm):\n"
591 "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t"
592 "(event_name, cpu, secs, nsecs, pid, comm),\n");
593
594 fclose(ofp);
595
596 fprintf(stderr, "generated Python script: %s\n", fname);
597
598 return 0;
599}
600
601struct scripting_ops python_scripting_ops = {
602 .name = "Python",
603 .start_script = python_start_script,
604 .stop_script = python_stop_script,
605 .process_event = python_process_event,
606 .generate_script = python_generate_script,
607};