| .. | .. |
|---|
| 31 | 31 | #include <linux/compiler.h> |
|---|
| 32 | 32 | #include <linux/time64.h> |
|---|
| 33 | 33 | |
|---|
| 34 | | -#include "../../perf.h" |
|---|
| 34 | +#include "../build-id.h" |
|---|
| 35 | +#include "../counts.h" |
|---|
| 35 | 36 | #include "../debug.h" |
|---|
| 37 | +#include "../dso.h" |
|---|
| 36 | 38 | #include "../callchain.h" |
|---|
| 37 | 39 | #include "../evsel.h" |
|---|
| 38 | | -#include "../util.h" |
|---|
| 39 | 40 | #include "../event.h" |
|---|
| 40 | 41 | #include "../thread.h" |
|---|
| 41 | 42 | #include "../comm.h" |
|---|
| .. | .. |
|---|
| 44 | 45 | #include "../thread-stack.h" |
|---|
| 45 | 46 | #include "../trace-event.h" |
|---|
| 46 | 47 | #include "../call-path.h" |
|---|
| 48 | +#include "map.h" |
|---|
| 49 | +#include "symbol.h" |
|---|
| 47 | 50 | #include "thread_map.h" |
|---|
| 48 | | -#include "cpumap.h" |
|---|
| 49 | 51 | #include "print_binary.h" |
|---|
| 50 | 52 | #include "stat.h" |
|---|
| 51 | 53 | #include "mem-events.h" |
|---|
| .. | .. |
|---|
| 110 | 112 | PyObject *sample_handler; |
|---|
| 111 | 113 | PyObject *call_path_handler; |
|---|
| 112 | 114 | PyObject *call_return_handler; |
|---|
| 115 | + PyObject *synth_handler; |
|---|
| 116 | + PyObject *context_switch_handler; |
|---|
| 113 | 117 | bool db_export_mode; |
|---|
| 114 | 118 | }; |
|---|
| 115 | 119 | |
|---|
| .. | .. |
|---|
| 193 | 197 | call_object(handler, args, handler_name); |
|---|
| 194 | 198 | } |
|---|
| 195 | 199 | |
|---|
| 196 | | -static void define_value(enum print_arg_type field_type, |
|---|
| 200 | +static void define_value(enum tep_print_arg_type field_type, |
|---|
| 197 | 201 | const char *ev_name, |
|---|
| 198 | 202 | const char *field_name, |
|---|
| 199 | 203 | const char *field_value, |
|---|
| .. | .. |
|---|
| 204 | 208 | unsigned long long value; |
|---|
| 205 | 209 | unsigned n = 0; |
|---|
| 206 | 210 | |
|---|
| 207 | | - if (field_type == PRINT_SYMBOL) |
|---|
| 211 | + if (field_type == TEP_PRINT_SYMBOL) |
|---|
| 208 | 212 | handler_name = "define_symbolic_value"; |
|---|
| 209 | 213 | |
|---|
| 210 | 214 | t = PyTuple_New(4); |
|---|
| .. | .. |
|---|
| 223 | 227 | Py_DECREF(t); |
|---|
| 224 | 228 | } |
|---|
| 225 | 229 | |
|---|
| 226 | | -static void define_values(enum print_arg_type field_type, |
|---|
| 227 | | - struct print_flag_sym *field, |
|---|
| 230 | +static void define_values(enum tep_print_arg_type field_type, |
|---|
| 231 | + struct tep_print_flag_sym *field, |
|---|
| 228 | 232 | const char *ev_name, |
|---|
| 229 | 233 | const char *field_name) |
|---|
| 230 | 234 | { |
|---|
| .. | .. |
|---|
| 235 | 239 | define_values(field_type, field->next, ev_name, field_name); |
|---|
| 236 | 240 | } |
|---|
| 237 | 241 | |
|---|
| 238 | | -static void define_field(enum print_arg_type field_type, |
|---|
| 242 | +static void define_field(enum tep_print_arg_type field_type, |
|---|
| 239 | 243 | const char *ev_name, |
|---|
| 240 | 244 | const char *field_name, |
|---|
| 241 | 245 | const char *delim) |
|---|
| .. | .. |
|---|
| 244 | 248 | PyObject *t; |
|---|
| 245 | 249 | unsigned n = 0; |
|---|
| 246 | 250 | |
|---|
| 247 | | - if (field_type == PRINT_SYMBOL) |
|---|
| 251 | + if (field_type == TEP_PRINT_SYMBOL) |
|---|
| 248 | 252 | handler_name = "define_symbolic_field"; |
|---|
| 249 | 253 | |
|---|
| 250 | | - if (field_type == PRINT_FLAGS) |
|---|
| 254 | + if (field_type == TEP_PRINT_FLAGS) |
|---|
| 251 | 255 | t = PyTuple_New(3); |
|---|
| 252 | 256 | else |
|---|
| 253 | 257 | t = PyTuple_New(2); |
|---|
| .. | .. |
|---|
| 256 | 260 | |
|---|
| 257 | 261 | PyTuple_SetItem(t, n++, _PyUnicode_FromString(ev_name)); |
|---|
| 258 | 262 | PyTuple_SetItem(t, n++, _PyUnicode_FromString(field_name)); |
|---|
| 259 | | - if (field_type == PRINT_FLAGS) |
|---|
| 263 | + if (field_type == TEP_PRINT_FLAGS) |
|---|
| 260 | 264 | PyTuple_SetItem(t, n++, _PyUnicode_FromString(delim)); |
|---|
| 261 | 265 | |
|---|
| 262 | 266 | try_call_object(handler_name, t); |
|---|
| .. | .. |
|---|
| 264 | 268 | Py_DECREF(t); |
|---|
| 265 | 269 | } |
|---|
| 266 | 270 | |
|---|
| 267 | | -static void define_event_symbols(struct event_format *event, |
|---|
| 271 | +static void define_event_symbols(struct tep_event *event, |
|---|
| 268 | 272 | const char *ev_name, |
|---|
| 269 | | - struct print_arg *args) |
|---|
| 273 | + struct tep_print_arg *args) |
|---|
| 270 | 274 | { |
|---|
| 271 | 275 | if (args == NULL) |
|---|
| 272 | 276 | return; |
|---|
| 273 | 277 | |
|---|
| 274 | 278 | switch (args->type) { |
|---|
| 275 | | - case PRINT_NULL: |
|---|
| 279 | + case TEP_PRINT_NULL: |
|---|
| 276 | 280 | break; |
|---|
| 277 | | - case PRINT_ATOM: |
|---|
| 278 | | - define_value(PRINT_FLAGS, ev_name, cur_field_name, "0", |
|---|
| 281 | + case TEP_PRINT_ATOM: |
|---|
| 282 | + define_value(TEP_PRINT_FLAGS, ev_name, cur_field_name, "0", |
|---|
| 279 | 283 | args->atom.atom); |
|---|
| 280 | 284 | zero_flag_atom = 0; |
|---|
| 281 | 285 | break; |
|---|
| 282 | | - case PRINT_FIELD: |
|---|
| 286 | + case TEP_PRINT_FIELD: |
|---|
| 283 | 287 | free(cur_field_name); |
|---|
| 284 | 288 | cur_field_name = strdup(args->field.name); |
|---|
| 285 | 289 | break; |
|---|
| 286 | | - case PRINT_FLAGS: |
|---|
| 290 | + case TEP_PRINT_FLAGS: |
|---|
| 287 | 291 | define_event_symbols(event, ev_name, args->flags.field); |
|---|
| 288 | | - define_field(PRINT_FLAGS, ev_name, cur_field_name, |
|---|
| 292 | + define_field(TEP_PRINT_FLAGS, ev_name, cur_field_name, |
|---|
| 289 | 293 | args->flags.delim); |
|---|
| 290 | | - define_values(PRINT_FLAGS, args->flags.flags, ev_name, |
|---|
| 294 | + define_values(TEP_PRINT_FLAGS, args->flags.flags, ev_name, |
|---|
| 291 | 295 | cur_field_name); |
|---|
| 292 | 296 | break; |
|---|
| 293 | | - case PRINT_SYMBOL: |
|---|
| 297 | + case TEP_PRINT_SYMBOL: |
|---|
| 294 | 298 | define_event_symbols(event, ev_name, args->symbol.field); |
|---|
| 295 | | - define_field(PRINT_SYMBOL, ev_name, cur_field_name, NULL); |
|---|
| 296 | | - define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name, |
|---|
| 299 | + define_field(TEP_PRINT_SYMBOL, ev_name, cur_field_name, NULL); |
|---|
| 300 | + define_values(TEP_PRINT_SYMBOL, args->symbol.symbols, ev_name, |
|---|
| 297 | 301 | cur_field_name); |
|---|
| 298 | 302 | break; |
|---|
| 299 | | - case PRINT_HEX: |
|---|
| 300 | | - case PRINT_HEX_STR: |
|---|
| 303 | + case TEP_PRINT_HEX: |
|---|
| 304 | + case TEP_PRINT_HEX_STR: |
|---|
| 301 | 305 | define_event_symbols(event, ev_name, args->hex.field); |
|---|
| 302 | 306 | define_event_symbols(event, ev_name, args->hex.size); |
|---|
| 303 | 307 | break; |
|---|
| 304 | | - case PRINT_INT_ARRAY: |
|---|
| 308 | + case TEP_PRINT_INT_ARRAY: |
|---|
| 305 | 309 | define_event_symbols(event, ev_name, args->int_array.field); |
|---|
| 306 | 310 | define_event_symbols(event, ev_name, args->int_array.count); |
|---|
| 307 | 311 | define_event_symbols(event, ev_name, args->int_array.el_size); |
|---|
| 308 | 312 | break; |
|---|
| 309 | | - case PRINT_STRING: |
|---|
| 313 | + case TEP_PRINT_STRING: |
|---|
| 310 | 314 | break; |
|---|
| 311 | | - case PRINT_TYPE: |
|---|
| 315 | + case TEP_PRINT_TYPE: |
|---|
| 312 | 316 | define_event_symbols(event, ev_name, args->typecast.item); |
|---|
| 313 | 317 | break; |
|---|
| 314 | | - case PRINT_OP: |
|---|
| 318 | + case TEP_PRINT_OP: |
|---|
| 315 | 319 | if (strcmp(args->op.op, ":") == 0) |
|---|
| 316 | 320 | zero_flag_atom = 1; |
|---|
| 317 | 321 | define_event_symbols(event, ev_name, args->op.left); |
|---|
| .. | .. |
|---|
| 319 | 323 | break; |
|---|
| 320 | 324 | default: |
|---|
| 321 | 325 | /* gcc warns for these? */ |
|---|
| 322 | | - case PRINT_BSTRING: |
|---|
| 323 | | - case PRINT_DYNAMIC_ARRAY: |
|---|
| 324 | | - case PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 325 | | - case PRINT_FUNC: |
|---|
| 326 | | - case PRINT_BITMASK: |
|---|
| 326 | + case TEP_PRINT_BSTRING: |
|---|
| 327 | + case TEP_PRINT_DYNAMIC_ARRAY: |
|---|
| 328 | + case TEP_PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 329 | + case TEP_PRINT_FUNC: |
|---|
| 330 | + case TEP_PRINT_BITMASK: |
|---|
| 327 | 331 | /* we should warn... */ |
|---|
| 328 | 332 | return; |
|---|
| 329 | 333 | } |
|---|
| .. | .. |
|---|
| 332 | 336 | define_event_symbols(event, ev_name, args->next); |
|---|
| 333 | 337 | } |
|---|
| 334 | 338 | |
|---|
| 335 | | -static PyObject *get_field_numeric_entry(struct event_format *event, |
|---|
| 336 | | - struct format_field *field, void *data) |
|---|
| 339 | +static PyObject *get_field_numeric_entry(struct tep_event *event, |
|---|
| 340 | + struct tep_format_field *field, void *data) |
|---|
| 337 | 341 | { |
|---|
| 338 | | - bool is_array = field->flags & FIELD_IS_ARRAY; |
|---|
| 342 | + bool is_array = field->flags & TEP_FIELD_IS_ARRAY; |
|---|
| 339 | 343 | PyObject *obj = NULL, *list = NULL; |
|---|
| 340 | 344 | unsigned long long val; |
|---|
| 341 | 345 | unsigned int item_size, n_items, i; |
|---|
| .. | .. |
|---|
| 353 | 357 | |
|---|
| 354 | 358 | val = read_size(event, data + field->offset + i * item_size, |
|---|
| 355 | 359 | item_size); |
|---|
| 356 | | - if (field->flags & FIELD_IS_SIGNED) { |
|---|
| 360 | + if (field->flags & TEP_FIELD_IS_SIGNED) { |
|---|
| 357 | 361 | if ((long long)val >= LONG_MIN && |
|---|
| 358 | 362 | (long long)val <= LONG_MAX) |
|---|
| 359 | 363 | obj = _PyLong_FromLong(val); |
|---|
| .. | .. |
|---|
| 388 | 392 | } |
|---|
| 389 | 393 | |
|---|
| 390 | 394 | static PyObject *python_process_callchain(struct perf_sample *sample, |
|---|
| 391 | | - struct perf_evsel *evsel, |
|---|
| 395 | + struct evsel *evsel, |
|---|
| 392 | 396 | struct addr_location *al) |
|---|
| 393 | 397 | { |
|---|
| 394 | 398 | PyObject *pylist; |
|---|
| .. | .. |
|---|
| 424 | 428 | pydict_set_item_string_decref(pyelem, "ip", |
|---|
| 425 | 429 | PyLong_FromUnsignedLongLong(node->ip)); |
|---|
| 426 | 430 | |
|---|
| 427 | | - if (node->sym) { |
|---|
| 431 | + if (node->ms.sym) { |
|---|
| 428 | 432 | PyObject *pysym = PyDict_New(); |
|---|
| 429 | 433 | if (!pysym) |
|---|
| 430 | 434 | Py_FatalError("couldn't create Python dictionary"); |
|---|
| 431 | 435 | pydict_set_item_string_decref(pysym, "start", |
|---|
| 432 | | - PyLong_FromUnsignedLongLong(node->sym->start)); |
|---|
| 436 | + PyLong_FromUnsignedLongLong(node->ms.sym->start)); |
|---|
| 433 | 437 | pydict_set_item_string_decref(pysym, "end", |
|---|
| 434 | | - PyLong_FromUnsignedLongLong(node->sym->end)); |
|---|
| 438 | + PyLong_FromUnsignedLongLong(node->ms.sym->end)); |
|---|
| 435 | 439 | pydict_set_item_string_decref(pysym, "binding", |
|---|
| 436 | | - _PyLong_FromLong(node->sym->binding)); |
|---|
| 440 | + _PyLong_FromLong(node->ms.sym->binding)); |
|---|
| 437 | 441 | pydict_set_item_string_decref(pysym, "name", |
|---|
| 438 | | - _PyUnicode_FromStringAndSize(node->sym->name, |
|---|
| 439 | | - node->sym->namelen)); |
|---|
| 442 | + _PyUnicode_FromStringAndSize(node->ms.sym->name, |
|---|
| 443 | + node->ms.sym->namelen)); |
|---|
| 440 | 444 | pydict_set_item_string_decref(pyelem, "sym", pysym); |
|---|
| 441 | 445 | } |
|---|
| 442 | 446 | |
|---|
| 443 | | - if (node->map) { |
|---|
| 444 | | - const char *dsoname = get_dsoname(node->map); |
|---|
| 447 | + if (node->ms.map) { |
|---|
| 448 | + const char *dsoname = get_dsoname(node->ms.map); |
|---|
| 445 | 449 | |
|---|
| 446 | 450 | pydict_set_item_string_decref(pyelem, "dso", |
|---|
| 447 | 451 | _PyUnicode_FromString(dsoname)); |
|---|
| .. | .. |
|---|
| 460 | 464 | struct thread *thread) |
|---|
| 461 | 465 | { |
|---|
| 462 | 466 | struct branch_stack *br = sample->branch_stack; |
|---|
| 467 | + struct branch_entry *entries = perf_sample__branch_entries(sample); |
|---|
| 463 | 468 | PyObject *pylist; |
|---|
| 464 | 469 | u64 i; |
|---|
| 465 | 470 | |
|---|
| .. | .. |
|---|
| 480 | 485 | Py_FatalError("couldn't create Python dictionary"); |
|---|
| 481 | 486 | |
|---|
| 482 | 487 | pydict_set_item_string_decref(pyelem, "from", |
|---|
| 483 | | - PyLong_FromUnsignedLongLong(br->entries[i].from)); |
|---|
| 488 | + PyLong_FromUnsignedLongLong(entries[i].from)); |
|---|
| 484 | 489 | pydict_set_item_string_decref(pyelem, "to", |
|---|
| 485 | | - PyLong_FromUnsignedLongLong(br->entries[i].to)); |
|---|
| 490 | + PyLong_FromUnsignedLongLong(entries[i].to)); |
|---|
| 486 | 491 | pydict_set_item_string_decref(pyelem, "mispred", |
|---|
| 487 | | - PyBool_FromLong(br->entries[i].flags.mispred)); |
|---|
| 492 | + PyBool_FromLong(entries[i].flags.mispred)); |
|---|
| 488 | 493 | pydict_set_item_string_decref(pyelem, "predicted", |
|---|
| 489 | | - PyBool_FromLong(br->entries[i].flags.predicted)); |
|---|
| 494 | + PyBool_FromLong(entries[i].flags.predicted)); |
|---|
| 490 | 495 | pydict_set_item_string_decref(pyelem, "in_tx", |
|---|
| 491 | | - PyBool_FromLong(br->entries[i].flags.in_tx)); |
|---|
| 496 | + PyBool_FromLong(entries[i].flags.in_tx)); |
|---|
| 492 | 497 | pydict_set_item_string_decref(pyelem, "abort", |
|---|
| 493 | | - PyBool_FromLong(br->entries[i].flags.abort)); |
|---|
| 498 | + PyBool_FromLong(entries[i].flags.abort)); |
|---|
| 494 | 499 | pydict_set_item_string_decref(pyelem, "cycles", |
|---|
| 495 | | - PyLong_FromUnsignedLongLong(br->entries[i].flags.cycles)); |
|---|
| 500 | + PyLong_FromUnsignedLongLong(entries[i].flags.cycles)); |
|---|
| 496 | 501 | |
|---|
| 497 | 502 | thread__find_map_fb(thread, sample->cpumode, |
|---|
| 498 | | - br->entries[i].from, &al); |
|---|
| 503 | + entries[i].from, &al); |
|---|
| 499 | 504 | dsoname = get_dsoname(al.map); |
|---|
| 500 | 505 | pydict_set_item_string_decref(pyelem, "from_dsoname", |
|---|
| 501 | 506 | _PyUnicode_FromString(dsoname)); |
|---|
| 502 | 507 | |
|---|
| 503 | 508 | thread__find_map_fb(thread, sample->cpumode, |
|---|
| 504 | | - br->entries[i].to, &al); |
|---|
| 509 | + entries[i].to, &al); |
|---|
| 505 | 510 | dsoname = get_dsoname(al.map); |
|---|
| 506 | 511 | pydict_set_item_string_decref(pyelem, "to_dsoname", |
|---|
| 507 | 512 | _PyUnicode_FromString(dsoname)); |
|---|
| .. | .. |
|---|
| 557 | 562 | struct thread *thread) |
|---|
| 558 | 563 | { |
|---|
| 559 | 564 | struct branch_stack *br = sample->branch_stack; |
|---|
| 565 | + struct branch_entry *entries = perf_sample__branch_entries(sample); |
|---|
| 560 | 566 | PyObject *pylist; |
|---|
| 561 | 567 | u64 i; |
|---|
| 562 | 568 | char bf[512]; |
|---|
| .. | .. |
|---|
| 577 | 583 | Py_FatalError("couldn't create Python dictionary"); |
|---|
| 578 | 584 | |
|---|
| 579 | 585 | thread__find_symbol_fb(thread, sample->cpumode, |
|---|
| 580 | | - br->entries[i].from, &al); |
|---|
| 586 | + entries[i].from, &al); |
|---|
| 581 | 587 | get_symoff(al.sym, &al, true, bf, sizeof(bf)); |
|---|
| 582 | 588 | pydict_set_item_string_decref(pyelem, "from", |
|---|
| 583 | 589 | _PyUnicode_FromString(bf)); |
|---|
| 584 | 590 | |
|---|
| 585 | 591 | thread__find_symbol_fb(thread, sample->cpumode, |
|---|
| 586 | | - br->entries[i].to, &al); |
|---|
| 592 | + entries[i].to, &al); |
|---|
| 587 | 593 | get_symoff(al.sym, &al, true, bf, sizeof(bf)); |
|---|
| 588 | 594 | pydict_set_item_string_decref(pyelem, "to", |
|---|
| 589 | 595 | _PyUnicode_FromString(bf)); |
|---|
| 590 | 596 | |
|---|
| 591 | | - get_br_mspred(&br->entries[i].flags, bf, sizeof(bf)); |
|---|
| 597 | + get_br_mspred(&entries[i].flags, bf, sizeof(bf)); |
|---|
| 592 | 598 | pydict_set_item_string_decref(pyelem, "pred", |
|---|
| 593 | 599 | _PyUnicode_FromString(bf)); |
|---|
| 594 | 600 | |
|---|
| 595 | | - if (br->entries[i].flags.in_tx) { |
|---|
| 601 | + if (entries[i].flags.in_tx) { |
|---|
| 596 | 602 | pydict_set_item_string_decref(pyelem, "in_tx", |
|---|
| 597 | 603 | _PyUnicode_FromString("X")); |
|---|
| 598 | 604 | } else { |
|---|
| .. | .. |
|---|
| 600 | 606 | _PyUnicode_FromString("-")); |
|---|
| 601 | 607 | } |
|---|
| 602 | 608 | |
|---|
| 603 | | - if (br->entries[i].flags.abort) { |
|---|
| 609 | + if (entries[i].flags.abort) { |
|---|
| 604 | 610 | pydict_set_item_string_decref(pyelem, "abort", |
|---|
| 605 | 611 | _PyUnicode_FromString("A")); |
|---|
| 606 | 612 | } else { |
|---|
| .. | .. |
|---|
| 630 | 636 | |
|---|
| 631 | 637 | static void set_sample_read_in_dict(PyObject *dict_sample, |
|---|
| 632 | 638 | struct perf_sample *sample, |
|---|
| 633 | | - struct perf_evsel *evsel) |
|---|
| 639 | + struct evsel *evsel) |
|---|
| 634 | 640 | { |
|---|
| 635 | | - u64 read_format = evsel->attr.read_format; |
|---|
| 641 | + u64 read_format = evsel->core.attr.read_format; |
|---|
| 636 | 642 | PyObject *values; |
|---|
| 637 | 643 | unsigned int i; |
|---|
| 638 | 644 | |
|---|
| .. | .. |
|---|
| 688 | 694 | |
|---|
| 689 | 695 | bf[0] = 0; |
|---|
| 690 | 696 | |
|---|
| 697 | + if (!regs || !regs->regs) |
|---|
| 698 | + return 0; |
|---|
| 699 | + |
|---|
| 691 | 700 | for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { |
|---|
| 692 | 701 | u64 val = regs->regs[i++]; |
|---|
| 693 | 702 | |
|---|
| .. | .. |
|---|
| 701 | 710 | |
|---|
| 702 | 711 | static void set_regs_in_dict(PyObject *dict, |
|---|
| 703 | 712 | struct perf_sample *sample, |
|---|
| 704 | | - struct perf_evsel *evsel) |
|---|
| 713 | + struct evsel *evsel) |
|---|
| 705 | 714 | { |
|---|
| 706 | | - struct perf_event_attr *attr = &evsel->attr; |
|---|
| 715 | + struct perf_event_attr *attr = &evsel->core.attr; |
|---|
| 707 | 716 | char bf[512]; |
|---|
| 708 | 717 | |
|---|
| 709 | 718 | regs_map(&sample->intr_regs, attr->sample_regs_intr, bf, sizeof(bf)); |
|---|
| .. | .. |
|---|
| 718 | 727 | } |
|---|
| 719 | 728 | |
|---|
| 720 | 729 | static PyObject *get_perf_sample_dict(struct perf_sample *sample, |
|---|
| 721 | | - struct perf_evsel *evsel, |
|---|
| 730 | + struct evsel *evsel, |
|---|
| 722 | 731 | struct addr_location *al, |
|---|
| 723 | 732 | PyObject *callchain) |
|---|
| 724 | 733 | { |
|---|
| .. | .. |
|---|
| 732 | 741 | if (!dict_sample) |
|---|
| 733 | 742 | Py_FatalError("couldn't create Python dictionary"); |
|---|
| 734 | 743 | |
|---|
| 735 | | - pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(perf_evsel__name(evsel))); |
|---|
| 736 | | - pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->attr, sizeof(evsel->attr))); |
|---|
| 744 | + pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(evsel__name(evsel))); |
|---|
| 745 | + pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->core.attr, sizeof(evsel->core.attr))); |
|---|
| 737 | 746 | |
|---|
| 738 | 747 | pydict_set_item_string_decref(dict_sample, "pid", |
|---|
| 739 | 748 | _PyLong_FromLong(sample->pid)); |
|---|
| .. | .. |
|---|
| 786 | 795 | } |
|---|
| 787 | 796 | |
|---|
| 788 | 797 | static void python_process_tracepoint(struct perf_sample *sample, |
|---|
| 789 | | - struct perf_evsel *evsel, |
|---|
| 798 | + struct evsel *evsel, |
|---|
| 790 | 799 | struct addr_location *al) |
|---|
| 791 | 800 | { |
|---|
| 792 | | - struct event_format *event = evsel->tp_format; |
|---|
| 801 | + struct tep_event *event = evsel->tp_format; |
|---|
| 793 | 802 | PyObject *handler, *context, *t, *obj = NULL, *callchain; |
|---|
| 794 | 803 | PyObject *dict = NULL, *all_entries_dict = NULL; |
|---|
| 795 | 804 | static char handler_name[256]; |
|---|
| 796 | | - struct format_field *field; |
|---|
| 805 | + struct tep_format_field *field; |
|---|
| 797 | 806 | unsigned long s, ns; |
|---|
| 798 | 807 | unsigned n = 0; |
|---|
| 799 | 808 | int pid; |
|---|
| .. | .. |
|---|
| 805 | 814 | |
|---|
| 806 | 815 | if (!event) { |
|---|
| 807 | 816 | snprintf(handler_name, sizeof(handler_name), |
|---|
| 808 | | - "ug! no event found for type %" PRIu64, (u64)evsel->attr.config); |
|---|
| 817 | + "ug! no event found for type %" PRIu64, (u64)evsel->core.attr.config); |
|---|
| 809 | 818 | Py_FatalError(handler_name); |
|---|
| 810 | 819 | } |
|---|
| 811 | 820 | |
|---|
| .. | .. |
|---|
| 835 | 844 | ns = nsecs - s * NSEC_PER_SEC; |
|---|
| 836 | 845 | |
|---|
| 837 | 846 | scripting_context->event_data = data; |
|---|
| 838 | | - scripting_context->pevent = evsel->tp_format->pevent; |
|---|
| 847 | + scripting_context->pevent = evsel->tp_format->tep; |
|---|
| 839 | 848 | |
|---|
| 840 | 849 | context = _PyCapsule_New(scripting_context, NULL, NULL); |
|---|
| 841 | 850 | |
|---|
| .. | .. |
|---|
| 866 | 875 | unsigned int offset, len; |
|---|
| 867 | 876 | unsigned long long val; |
|---|
| 868 | 877 | |
|---|
| 869 | | - if (field->flags & FIELD_IS_ARRAY) { |
|---|
| 878 | + if (field->flags & TEP_FIELD_IS_ARRAY) { |
|---|
| 870 | 879 | offset = field->offset; |
|---|
| 871 | 880 | len = field->size; |
|---|
| 872 | | - if (field->flags & FIELD_IS_DYNAMIC) { |
|---|
| 881 | + if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
|---|
| 873 | 882 | val = tep_read_number(scripting_context->pevent, |
|---|
| 874 | 883 | data + offset, len); |
|---|
| 875 | 884 | offset = val; |
|---|
| 876 | 885 | len = offset >> 16; |
|---|
| 877 | 886 | offset &= 0xffff; |
|---|
| 878 | 887 | } |
|---|
| 879 | | - if (field->flags & FIELD_IS_STRING && |
|---|
| 888 | + if (field->flags & TEP_FIELD_IS_STRING && |
|---|
| 880 | 889 | is_printable_array(data + offset, len)) { |
|---|
| 881 | 890 | obj = _PyUnicode_FromString((char *) data + offset); |
|---|
| 882 | 891 | } else { |
|---|
| 883 | 892 | obj = PyByteArray_FromStringAndSize((const char *) data + offset, len); |
|---|
| 884 | | - field->flags &= ~FIELD_IS_STRING; |
|---|
| 893 | + field->flags &= ~TEP_FIELD_IS_STRING; |
|---|
| 885 | 894 | } |
|---|
| 886 | 895 | } else { /* FIELD_IS_NUMERIC */ |
|---|
| 887 | 896 | obj = get_field_numeric_entry(event, field, data); |
|---|
| .. | .. |
|---|
| 925 | 934 | return t; |
|---|
| 926 | 935 | } |
|---|
| 927 | 936 | |
|---|
| 928 | | -static int tuple_set_u64(PyObject *t, unsigned int pos, u64 val) |
|---|
| 937 | +static int tuple_set_s64(PyObject *t, unsigned int pos, s64 val) |
|---|
| 929 | 938 | { |
|---|
| 930 | 939 | #if BITS_PER_LONG == 64 |
|---|
| 931 | 940 | return PyTuple_SetItem(t, pos, _PyLong_FromLong(val)); |
|---|
| 932 | 941 | #endif |
|---|
| 933 | 942 | #if BITS_PER_LONG == 32 |
|---|
| 934 | 943 | return PyTuple_SetItem(t, pos, PyLong_FromLongLong(val)); |
|---|
| 944 | +#endif |
|---|
| 945 | +} |
|---|
| 946 | + |
|---|
| 947 | +/* |
|---|
| 948 | + * Databases support only signed 64-bit numbers, so even though we are |
|---|
| 949 | + * exporting a u64, it must be as s64. |
|---|
| 950 | + */ |
|---|
| 951 | +#define tuple_set_d64 tuple_set_s64 |
|---|
| 952 | + |
|---|
| 953 | +static int tuple_set_u64(PyObject *t, unsigned int pos, u64 val) |
|---|
| 954 | +{ |
|---|
| 955 | +#if BITS_PER_LONG == 64 |
|---|
| 956 | + return PyTuple_SetItem(t, pos, PyLong_FromUnsignedLong(val)); |
|---|
| 957 | +#endif |
|---|
| 958 | +#if BITS_PER_LONG == 32 |
|---|
| 959 | + return PyTuple_SetItem(t, pos, PyLong_FromUnsignedLongLong(val)); |
|---|
| 935 | 960 | #endif |
|---|
| 936 | 961 | } |
|---|
| 937 | 962 | |
|---|
| .. | .. |
|---|
| 945 | 970 | return PyTuple_SetItem(t, pos, _PyUnicode_FromString(s)); |
|---|
| 946 | 971 | } |
|---|
| 947 | 972 | |
|---|
| 948 | | -static int python_export_evsel(struct db_export *dbe, struct perf_evsel *evsel) |
|---|
| 973 | +static int tuple_set_bytes(PyObject *t, unsigned int pos, void *bytes, |
|---|
| 974 | + unsigned int sz) |
|---|
| 975 | +{ |
|---|
| 976 | + return PyTuple_SetItem(t, pos, _PyBytes_FromStringAndSize(bytes, sz)); |
|---|
| 977 | +} |
|---|
| 978 | + |
|---|
| 979 | +static int python_export_evsel(struct db_export *dbe, struct evsel *evsel) |
|---|
| 949 | 980 | { |
|---|
| 950 | 981 | struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 951 | 982 | PyObject *t; |
|---|
| 952 | 983 | |
|---|
| 953 | 984 | t = tuple_new(2); |
|---|
| 954 | 985 | |
|---|
| 955 | | - tuple_set_u64(t, 0, evsel->db_id); |
|---|
| 956 | | - tuple_set_string(t, 1, perf_evsel__name(evsel)); |
|---|
| 986 | + tuple_set_d64(t, 0, evsel->db_id); |
|---|
| 987 | + tuple_set_string(t, 1, evsel__name(evsel)); |
|---|
| 957 | 988 | |
|---|
| 958 | 989 | call_object(tables->evsel_handler, t, "evsel_table"); |
|---|
| 959 | 990 | |
|---|
| .. | .. |
|---|
| 970 | 1001 | |
|---|
| 971 | 1002 | t = tuple_new(3); |
|---|
| 972 | 1003 | |
|---|
| 973 | | - tuple_set_u64(t, 0, machine->db_id); |
|---|
| 1004 | + tuple_set_d64(t, 0, machine->db_id); |
|---|
| 974 | 1005 | tuple_set_s32(t, 1, machine->pid); |
|---|
| 975 | 1006 | tuple_set_string(t, 2, machine->root_dir ? machine->root_dir : ""); |
|---|
| 976 | 1007 | |
|---|
| .. | .. |
|---|
| 989 | 1020 | |
|---|
| 990 | 1021 | t = tuple_new(5); |
|---|
| 991 | 1022 | |
|---|
| 992 | | - tuple_set_u64(t, 0, thread->db_id); |
|---|
| 993 | | - tuple_set_u64(t, 1, machine->db_id); |
|---|
| 994 | | - tuple_set_u64(t, 2, main_thread_db_id); |
|---|
| 1023 | + tuple_set_d64(t, 0, thread->db_id); |
|---|
| 1024 | + tuple_set_d64(t, 1, machine->db_id); |
|---|
| 1025 | + tuple_set_d64(t, 2, main_thread_db_id); |
|---|
| 995 | 1026 | tuple_set_s32(t, 3, thread->pid_); |
|---|
| 996 | 1027 | tuple_set_s32(t, 4, thread->tid); |
|---|
| 997 | 1028 | |
|---|
| .. | .. |
|---|
| 1002 | 1033 | return 0; |
|---|
| 1003 | 1034 | } |
|---|
| 1004 | 1035 | |
|---|
| 1005 | | -static int python_export_comm(struct db_export *dbe, struct comm *comm) |
|---|
| 1036 | +static int python_export_comm(struct db_export *dbe, struct comm *comm, |
|---|
| 1037 | + struct thread *thread) |
|---|
| 1006 | 1038 | { |
|---|
| 1007 | 1039 | struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 1008 | 1040 | PyObject *t; |
|---|
| 1009 | 1041 | |
|---|
| 1010 | | - t = tuple_new(2); |
|---|
| 1042 | + t = tuple_new(5); |
|---|
| 1011 | 1043 | |
|---|
| 1012 | | - tuple_set_u64(t, 0, comm->db_id); |
|---|
| 1044 | + tuple_set_d64(t, 0, comm->db_id); |
|---|
| 1013 | 1045 | tuple_set_string(t, 1, comm__str(comm)); |
|---|
| 1046 | + tuple_set_d64(t, 2, thread->db_id); |
|---|
| 1047 | + tuple_set_d64(t, 3, comm->start); |
|---|
| 1048 | + tuple_set_s32(t, 4, comm->exec); |
|---|
| 1014 | 1049 | |
|---|
| 1015 | 1050 | call_object(tables->comm_handler, t, "comm_table"); |
|---|
| 1016 | 1051 | |
|---|
| .. | .. |
|---|
| 1027 | 1062 | |
|---|
| 1028 | 1063 | t = tuple_new(3); |
|---|
| 1029 | 1064 | |
|---|
| 1030 | | - tuple_set_u64(t, 0, db_id); |
|---|
| 1031 | | - tuple_set_u64(t, 1, comm->db_id); |
|---|
| 1032 | | - tuple_set_u64(t, 2, thread->db_id); |
|---|
| 1065 | + tuple_set_d64(t, 0, db_id); |
|---|
| 1066 | + tuple_set_d64(t, 1, comm->db_id); |
|---|
| 1067 | + tuple_set_d64(t, 2, thread->db_id); |
|---|
| 1033 | 1068 | |
|---|
| 1034 | 1069 | call_object(tables->comm_thread_handler, t, "comm_thread_table"); |
|---|
| 1035 | 1070 | |
|---|
| .. | .. |
|---|
| 1045 | 1080 | char sbuild_id[SBUILD_ID_SIZE]; |
|---|
| 1046 | 1081 | PyObject *t; |
|---|
| 1047 | 1082 | |
|---|
| 1048 | | - build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); |
|---|
| 1083 | + build_id__sprintf(&dso->bid, sbuild_id); |
|---|
| 1049 | 1084 | |
|---|
| 1050 | 1085 | t = tuple_new(5); |
|---|
| 1051 | 1086 | |
|---|
| 1052 | | - tuple_set_u64(t, 0, dso->db_id); |
|---|
| 1053 | | - tuple_set_u64(t, 1, machine->db_id); |
|---|
| 1087 | + tuple_set_d64(t, 0, dso->db_id); |
|---|
| 1088 | + tuple_set_d64(t, 1, machine->db_id); |
|---|
| 1054 | 1089 | tuple_set_string(t, 2, dso->short_name); |
|---|
| 1055 | 1090 | tuple_set_string(t, 3, dso->long_name); |
|---|
| 1056 | 1091 | tuple_set_string(t, 4, sbuild_id); |
|---|
| .. | .. |
|---|
| 1071 | 1106 | |
|---|
| 1072 | 1107 | t = tuple_new(6); |
|---|
| 1073 | 1108 | |
|---|
| 1074 | | - tuple_set_u64(t, 0, *sym_db_id); |
|---|
| 1075 | | - tuple_set_u64(t, 1, dso->db_id); |
|---|
| 1076 | | - tuple_set_u64(t, 2, sym->start); |
|---|
| 1077 | | - tuple_set_u64(t, 3, sym->end); |
|---|
| 1109 | + tuple_set_d64(t, 0, *sym_db_id); |
|---|
| 1110 | + tuple_set_d64(t, 1, dso->db_id); |
|---|
| 1111 | + tuple_set_d64(t, 2, sym->start); |
|---|
| 1112 | + tuple_set_d64(t, 3, sym->end); |
|---|
| 1078 | 1113 | tuple_set_s32(t, 4, sym->binding); |
|---|
| 1079 | 1114 | tuple_set_string(t, 5, sym->name); |
|---|
| 1080 | 1115 | |
|---|
| .. | .. |
|---|
| 1103 | 1138 | return 0; |
|---|
| 1104 | 1139 | } |
|---|
| 1105 | 1140 | |
|---|
| 1106 | | -static int python_export_sample(struct db_export *dbe, |
|---|
| 1107 | | - struct export_sample *es) |
|---|
| 1141 | +static void python_export_sample_table(struct db_export *dbe, |
|---|
| 1142 | + struct export_sample *es) |
|---|
| 1108 | 1143 | { |
|---|
| 1109 | 1144 | struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 1110 | 1145 | PyObject *t; |
|---|
| 1111 | 1146 | |
|---|
| 1112 | | - t = tuple_new(22); |
|---|
| 1147 | + t = tuple_new(24); |
|---|
| 1113 | 1148 | |
|---|
| 1114 | | - tuple_set_u64(t, 0, es->db_id); |
|---|
| 1115 | | - tuple_set_u64(t, 1, es->evsel->db_id); |
|---|
| 1116 | | - tuple_set_u64(t, 2, es->al->machine->db_id); |
|---|
| 1117 | | - tuple_set_u64(t, 3, es->al->thread->db_id); |
|---|
| 1118 | | - tuple_set_u64(t, 4, es->comm_db_id); |
|---|
| 1119 | | - tuple_set_u64(t, 5, es->dso_db_id); |
|---|
| 1120 | | - tuple_set_u64(t, 6, es->sym_db_id); |
|---|
| 1121 | | - tuple_set_u64(t, 7, es->offset); |
|---|
| 1122 | | - tuple_set_u64(t, 8, es->sample->ip); |
|---|
| 1123 | | - tuple_set_u64(t, 9, es->sample->time); |
|---|
| 1149 | + tuple_set_d64(t, 0, es->db_id); |
|---|
| 1150 | + tuple_set_d64(t, 1, es->evsel->db_id); |
|---|
| 1151 | + tuple_set_d64(t, 2, es->al->maps->machine->db_id); |
|---|
| 1152 | + tuple_set_d64(t, 3, es->al->thread->db_id); |
|---|
| 1153 | + tuple_set_d64(t, 4, es->comm_db_id); |
|---|
| 1154 | + tuple_set_d64(t, 5, es->dso_db_id); |
|---|
| 1155 | + tuple_set_d64(t, 6, es->sym_db_id); |
|---|
| 1156 | + tuple_set_d64(t, 7, es->offset); |
|---|
| 1157 | + tuple_set_d64(t, 8, es->sample->ip); |
|---|
| 1158 | + tuple_set_d64(t, 9, es->sample->time); |
|---|
| 1124 | 1159 | tuple_set_s32(t, 10, es->sample->cpu); |
|---|
| 1125 | | - tuple_set_u64(t, 11, es->addr_dso_db_id); |
|---|
| 1126 | | - tuple_set_u64(t, 12, es->addr_sym_db_id); |
|---|
| 1127 | | - tuple_set_u64(t, 13, es->addr_offset); |
|---|
| 1128 | | - tuple_set_u64(t, 14, es->sample->addr); |
|---|
| 1129 | | - tuple_set_u64(t, 15, es->sample->period); |
|---|
| 1130 | | - tuple_set_u64(t, 16, es->sample->weight); |
|---|
| 1131 | | - tuple_set_u64(t, 17, es->sample->transaction); |
|---|
| 1132 | | - tuple_set_u64(t, 18, es->sample->data_src); |
|---|
| 1160 | + tuple_set_d64(t, 11, es->addr_dso_db_id); |
|---|
| 1161 | + tuple_set_d64(t, 12, es->addr_sym_db_id); |
|---|
| 1162 | + tuple_set_d64(t, 13, es->addr_offset); |
|---|
| 1163 | + tuple_set_d64(t, 14, es->sample->addr); |
|---|
| 1164 | + tuple_set_d64(t, 15, es->sample->period); |
|---|
| 1165 | + tuple_set_d64(t, 16, es->sample->weight); |
|---|
| 1166 | + tuple_set_d64(t, 17, es->sample->transaction); |
|---|
| 1167 | + tuple_set_d64(t, 18, es->sample->data_src); |
|---|
| 1133 | 1168 | tuple_set_s32(t, 19, es->sample->flags & PERF_BRANCH_MASK); |
|---|
| 1134 | 1169 | tuple_set_s32(t, 20, !!(es->sample->flags & PERF_IP_FLAG_IN_TX)); |
|---|
| 1135 | | - tuple_set_u64(t, 21, es->call_path_id); |
|---|
| 1170 | + tuple_set_d64(t, 21, es->call_path_id); |
|---|
| 1171 | + tuple_set_d64(t, 22, es->sample->insn_cnt); |
|---|
| 1172 | + tuple_set_d64(t, 23, es->sample->cyc_cnt); |
|---|
| 1136 | 1173 | |
|---|
| 1137 | 1174 | call_object(tables->sample_handler, t, "sample_table"); |
|---|
| 1138 | 1175 | |
|---|
| 1139 | 1176 | Py_DECREF(t); |
|---|
| 1177 | +} |
|---|
| 1178 | + |
|---|
| 1179 | +static void python_export_synth(struct db_export *dbe, struct export_sample *es) |
|---|
| 1180 | +{ |
|---|
| 1181 | + struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 1182 | + PyObject *t; |
|---|
| 1183 | + |
|---|
| 1184 | + t = tuple_new(3); |
|---|
| 1185 | + |
|---|
| 1186 | + tuple_set_d64(t, 0, es->db_id); |
|---|
| 1187 | + tuple_set_d64(t, 1, es->evsel->core.attr.config); |
|---|
| 1188 | + tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size); |
|---|
| 1189 | + |
|---|
| 1190 | + call_object(tables->synth_handler, t, "synth_data"); |
|---|
| 1191 | + |
|---|
| 1192 | + Py_DECREF(t); |
|---|
| 1193 | +} |
|---|
| 1194 | + |
|---|
| 1195 | +static int python_export_sample(struct db_export *dbe, |
|---|
| 1196 | + struct export_sample *es) |
|---|
| 1197 | +{ |
|---|
| 1198 | + struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 1199 | + |
|---|
| 1200 | + python_export_sample_table(dbe, es); |
|---|
| 1201 | + |
|---|
| 1202 | + if (es->evsel->core.attr.type == PERF_TYPE_SYNTH && tables->synth_handler) |
|---|
| 1203 | + python_export_synth(dbe, es); |
|---|
| 1140 | 1204 | |
|---|
| 1141 | 1205 | return 0; |
|---|
| 1142 | 1206 | } |
|---|
| .. | .. |
|---|
| 1152 | 1216 | |
|---|
| 1153 | 1217 | t = tuple_new(4); |
|---|
| 1154 | 1218 | |
|---|
| 1155 | | - tuple_set_u64(t, 0, cp->db_id); |
|---|
| 1156 | | - tuple_set_u64(t, 1, parent_db_id); |
|---|
| 1157 | | - tuple_set_u64(t, 2, sym_db_id); |
|---|
| 1158 | | - tuple_set_u64(t, 3, cp->ip); |
|---|
| 1219 | + tuple_set_d64(t, 0, cp->db_id); |
|---|
| 1220 | + tuple_set_d64(t, 1, parent_db_id); |
|---|
| 1221 | + tuple_set_d64(t, 2, sym_db_id); |
|---|
| 1222 | + tuple_set_d64(t, 3, cp->ip); |
|---|
| 1159 | 1223 | |
|---|
| 1160 | 1224 | call_object(tables->call_path_handler, t, "call_path_table"); |
|---|
| 1161 | 1225 | |
|---|
| .. | .. |
|---|
| 1171 | 1235 | u64 comm_db_id = cr->comm ? cr->comm->db_id : 0; |
|---|
| 1172 | 1236 | PyObject *t; |
|---|
| 1173 | 1237 | |
|---|
| 1174 | | - t = tuple_new(11); |
|---|
| 1238 | + t = tuple_new(14); |
|---|
| 1175 | 1239 | |
|---|
| 1176 | | - tuple_set_u64(t, 0, cr->db_id); |
|---|
| 1177 | | - tuple_set_u64(t, 1, cr->thread->db_id); |
|---|
| 1178 | | - tuple_set_u64(t, 2, comm_db_id); |
|---|
| 1179 | | - tuple_set_u64(t, 3, cr->cp->db_id); |
|---|
| 1180 | | - tuple_set_u64(t, 4, cr->call_time); |
|---|
| 1181 | | - tuple_set_u64(t, 5, cr->return_time); |
|---|
| 1182 | | - tuple_set_u64(t, 6, cr->branch_count); |
|---|
| 1183 | | - tuple_set_u64(t, 7, cr->call_ref); |
|---|
| 1184 | | - tuple_set_u64(t, 8, cr->return_ref); |
|---|
| 1185 | | - tuple_set_u64(t, 9, cr->cp->parent->db_id); |
|---|
| 1240 | + tuple_set_d64(t, 0, cr->db_id); |
|---|
| 1241 | + tuple_set_d64(t, 1, cr->thread->db_id); |
|---|
| 1242 | + tuple_set_d64(t, 2, comm_db_id); |
|---|
| 1243 | + tuple_set_d64(t, 3, cr->cp->db_id); |
|---|
| 1244 | + tuple_set_d64(t, 4, cr->call_time); |
|---|
| 1245 | + tuple_set_d64(t, 5, cr->return_time); |
|---|
| 1246 | + tuple_set_d64(t, 6, cr->branch_count); |
|---|
| 1247 | + tuple_set_d64(t, 7, cr->call_ref); |
|---|
| 1248 | + tuple_set_d64(t, 8, cr->return_ref); |
|---|
| 1249 | + tuple_set_d64(t, 9, cr->cp->parent->db_id); |
|---|
| 1186 | 1250 | tuple_set_s32(t, 10, cr->flags); |
|---|
| 1251 | + tuple_set_d64(t, 11, cr->parent_db_id); |
|---|
| 1252 | + tuple_set_d64(t, 12, cr->insn_count); |
|---|
| 1253 | + tuple_set_d64(t, 13, cr->cyc_count); |
|---|
| 1187 | 1254 | |
|---|
| 1188 | 1255 | call_object(tables->call_return_handler, t, "call_return_table"); |
|---|
| 1189 | 1256 | |
|---|
| .. | .. |
|---|
| 1192 | 1259 | return 0; |
|---|
| 1193 | 1260 | } |
|---|
| 1194 | 1261 | |
|---|
| 1195 | | -static int python_process_call_return(struct call_return *cr, void *data) |
|---|
| 1262 | +static int python_export_context_switch(struct db_export *dbe, u64 db_id, |
|---|
| 1263 | + struct machine *machine, |
|---|
| 1264 | + struct perf_sample *sample, |
|---|
| 1265 | + u64 th_out_id, u64 comm_out_id, |
|---|
| 1266 | + u64 th_in_id, u64 comm_in_id, int flags) |
|---|
| 1267 | +{ |
|---|
| 1268 | + struct tables *tables = container_of(dbe, struct tables, dbe); |
|---|
| 1269 | + PyObject *t; |
|---|
| 1270 | + |
|---|
| 1271 | + t = tuple_new(9); |
|---|
| 1272 | + |
|---|
| 1273 | + tuple_set_d64(t, 0, db_id); |
|---|
| 1274 | + tuple_set_d64(t, 1, machine->db_id); |
|---|
| 1275 | + tuple_set_d64(t, 2, sample->time); |
|---|
| 1276 | + tuple_set_s32(t, 3, sample->cpu); |
|---|
| 1277 | + tuple_set_d64(t, 4, th_out_id); |
|---|
| 1278 | + tuple_set_d64(t, 5, comm_out_id); |
|---|
| 1279 | + tuple_set_d64(t, 6, th_in_id); |
|---|
| 1280 | + tuple_set_d64(t, 7, comm_in_id); |
|---|
| 1281 | + tuple_set_s32(t, 8, flags); |
|---|
| 1282 | + |
|---|
| 1283 | + call_object(tables->context_switch_handler, t, "context_switch"); |
|---|
| 1284 | + |
|---|
| 1285 | + Py_DECREF(t); |
|---|
| 1286 | + |
|---|
| 1287 | + return 0; |
|---|
| 1288 | +} |
|---|
| 1289 | + |
|---|
| 1290 | +static int python_process_call_return(struct call_return *cr, u64 *parent_db_id, |
|---|
| 1291 | + void *data) |
|---|
| 1196 | 1292 | { |
|---|
| 1197 | 1293 | struct db_export *dbe = data; |
|---|
| 1198 | 1294 | |
|---|
| 1199 | | - return db_export__call_return(dbe, cr); |
|---|
| 1295 | + return db_export__call_return(dbe, cr, parent_db_id); |
|---|
| 1200 | 1296 | } |
|---|
| 1201 | 1297 | |
|---|
| 1202 | 1298 | static void python_process_general_event(struct perf_sample *sample, |
|---|
| 1203 | | - struct perf_evsel *evsel, |
|---|
| 1299 | + struct evsel *evsel, |
|---|
| 1204 | 1300 | struct addr_location *al) |
|---|
| 1205 | 1301 | { |
|---|
| 1206 | 1302 | PyObject *handler, *t, *dict, *callchain; |
|---|
| .. | .. |
|---|
| 1236 | 1332 | |
|---|
| 1237 | 1333 | static void python_process_event(union perf_event *event, |
|---|
| 1238 | 1334 | struct perf_sample *sample, |
|---|
| 1239 | | - struct perf_evsel *evsel, |
|---|
| 1335 | + struct evsel *evsel, |
|---|
| 1240 | 1336 | struct addr_location *al) |
|---|
| 1241 | 1337 | { |
|---|
| 1242 | 1338 | struct tables *tables = &tables_global; |
|---|
| 1243 | 1339 | |
|---|
| 1244 | | - switch (evsel->attr.type) { |
|---|
| 1340 | + switch (evsel->core.attr.type) { |
|---|
| 1245 | 1341 | case PERF_TYPE_TRACEPOINT: |
|---|
| 1246 | 1342 | python_process_tracepoint(sample, evsel, al); |
|---|
| 1247 | 1343 | break; |
|---|
| .. | .. |
|---|
| 1254 | 1350 | } |
|---|
| 1255 | 1351 | } |
|---|
| 1256 | 1352 | |
|---|
| 1353 | +static void python_process_switch(union perf_event *event, |
|---|
| 1354 | + struct perf_sample *sample, |
|---|
| 1355 | + struct machine *machine) |
|---|
| 1356 | +{ |
|---|
| 1357 | + struct tables *tables = &tables_global; |
|---|
| 1358 | + |
|---|
| 1359 | + if (tables->db_export_mode) |
|---|
| 1360 | + db_export__switch(&tables->dbe, event, sample, machine); |
|---|
| 1361 | +} |
|---|
| 1362 | + |
|---|
| 1257 | 1363 | static void get_handler_name(char *str, size_t size, |
|---|
| 1258 | | - struct perf_evsel *evsel) |
|---|
| 1364 | + struct evsel *evsel) |
|---|
| 1259 | 1365 | { |
|---|
| 1260 | 1366 | char *p = str; |
|---|
| 1261 | 1367 | |
|---|
| 1262 | | - scnprintf(str, size, "stat__%s", perf_evsel__name(evsel)); |
|---|
| 1368 | + scnprintf(str, size, "stat__%s", evsel__name(evsel)); |
|---|
| 1263 | 1369 | |
|---|
| 1264 | 1370 | while ((p = strchr(p, ':'))) { |
|---|
| 1265 | 1371 | *p = '_'; |
|---|
| .. | .. |
|---|
| 1268 | 1374 | } |
|---|
| 1269 | 1375 | |
|---|
| 1270 | 1376 | static void |
|---|
| 1271 | | -process_stat(struct perf_evsel *counter, int cpu, int thread, u64 tstamp, |
|---|
| 1377 | +process_stat(struct evsel *counter, int cpu, int thread, u64 tstamp, |
|---|
| 1272 | 1378 | struct perf_counts_values *count) |
|---|
| 1273 | 1379 | { |
|---|
| 1274 | 1380 | PyObject *handler, *t; |
|---|
| .. | .. |
|---|
| 1305 | 1411 | } |
|---|
| 1306 | 1412 | |
|---|
| 1307 | 1413 | static void python_process_stat(struct perf_stat_config *config, |
|---|
| 1308 | | - struct perf_evsel *counter, u64 tstamp) |
|---|
| 1414 | + struct evsel *counter, u64 tstamp) |
|---|
| 1309 | 1415 | { |
|---|
| 1310 | | - struct thread_map *threads = counter->threads; |
|---|
| 1311 | | - struct cpu_map *cpus = counter->cpus; |
|---|
| 1416 | + struct perf_thread_map *threads = counter->core.threads; |
|---|
| 1417 | + struct perf_cpu_map *cpus = counter->core.cpus; |
|---|
| 1312 | 1418 | int cpu, thread; |
|---|
| 1313 | 1419 | |
|---|
| 1314 | 1420 | if (config->aggr_mode == AGGR_GLOBAL) { |
|---|
| .. | .. |
|---|
| 1320 | 1426 | for (thread = 0; thread < threads->nr; thread++) { |
|---|
| 1321 | 1427 | for (cpu = 0; cpu < cpus->nr; cpu++) { |
|---|
| 1322 | 1428 | process_stat(counter, cpus->map[cpu], |
|---|
| 1323 | | - thread_map__pid(threads, thread), tstamp, |
|---|
| 1429 | + perf_thread_map__pid(threads, thread), tstamp, |
|---|
| 1324 | 1430 | perf_counts(counter->counts, cpu, thread)); |
|---|
| 1325 | 1431 | } |
|---|
| 1326 | 1432 | } |
|---|
| .. | .. |
|---|
| 1469 | 1575 | SET_TABLE_HANDLER(sample); |
|---|
| 1470 | 1576 | SET_TABLE_HANDLER(call_path); |
|---|
| 1471 | 1577 | SET_TABLE_HANDLER(call_return); |
|---|
| 1578 | + SET_TABLE_HANDLER(context_switch); |
|---|
| 1579 | + |
|---|
| 1580 | + /* |
|---|
| 1581 | + * Synthesized events are samples but with architecture-specific data |
|---|
| 1582 | + * stored in sample->raw_data. They are exported via |
|---|
| 1583 | + * python_export_sample() and consequently do not need a separate export |
|---|
| 1584 | + * callback. |
|---|
| 1585 | + */ |
|---|
| 1586 | + tables->synth_handler = get_handler("synth_data"); |
|---|
| 1472 | 1587 | } |
|---|
| 1473 | 1588 | |
|---|
| 1474 | 1589 | #if PY_MAJOR_VERSION < 3 |
|---|
| .. | .. |
|---|
| 1567 | 1682 | |
|---|
| 1568 | 1683 | static int python_flush_script(void) |
|---|
| 1569 | 1684 | { |
|---|
| 1570 | | - struct tables *tables = &tables_global; |
|---|
| 1571 | | - |
|---|
| 1572 | | - return db_export__flush(&tables->dbe); |
|---|
| 1685 | + return 0; |
|---|
| 1573 | 1686 | } |
|---|
| 1574 | 1687 | |
|---|
| 1575 | 1688 | /* |
|---|
| .. | .. |
|---|
| 1592 | 1705 | |
|---|
| 1593 | 1706 | static int python_generate_script(struct tep_handle *pevent, const char *outfile) |
|---|
| 1594 | 1707 | { |
|---|
| 1595 | | - struct event_format *event = NULL; |
|---|
| 1596 | | - struct format_field *f; |
|---|
| 1708 | + int i, not_first, count, nr_events; |
|---|
| 1709 | + struct tep_event **all_events; |
|---|
| 1710 | + struct tep_event *event = NULL; |
|---|
| 1711 | + struct tep_format_field *f; |
|---|
| 1597 | 1712 | char fname[PATH_MAX]; |
|---|
| 1598 | | - int not_first, count; |
|---|
| 1599 | 1713 | FILE *ofp; |
|---|
| 1600 | 1714 | |
|---|
| 1601 | 1715 | sprintf(fname, "%s.py", outfile); |
|---|
| .. | .. |
|---|
| 1640 | 1754 | fprintf(ofp, "def trace_end():\n"); |
|---|
| 1641 | 1755 | fprintf(ofp, "\tprint(\"in trace_end\")\n\n"); |
|---|
| 1642 | 1756 | |
|---|
| 1643 | | - while ((event = trace_find_next_event(pevent, event))) { |
|---|
| 1757 | + nr_events = tep_get_events_count(pevent); |
|---|
| 1758 | + all_events = tep_list_events(pevent, TEP_EVENT_SORT_ID); |
|---|
| 1759 | + |
|---|
| 1760 | + for (i = 0; all_events && i < nr_events; i++) { |
|---|
| 1761 | + event = all_events[i]; |
|---|
| 1644 | 1762 | fprintf(ofp, "def %s__%s(", event->system, event->name); |
|---|
| 1645 | 1763 | fprintf(ofp, "event_name, "); |
|---|
| 1646 | 1764 | fprintf(ofp, "context, "); |
|---|
| .. | .. |
|---|
| 1688 | 1806 | count++; |
|---|
| 1689 | 1807 | |
|---|
| 1690 | 1808 | fprintf(ofp, "%s=", f->name); |
|---|
| 1691 | | - if (f->flags & FIELD_IS_STRING || |
|---|
| 1692 | | - f->flags & FIELD_IS_FLAG || |
|---|
| 1693 | | - f->flags & FIELD_IS_ARRAY || |
|---|
| 1694 | | - f->flags & FIELD_IS_SYMBOLIC) |
|---|
| 1809 | + if (f->flags & TEP_FIELD_IS_STRING || |
|---|
| 1810 | + f->flags & TEP_FIELD_IS_FLAG || |
|---|
| 1811 | + f->flags & TEP_FIELD_IS_ARRAY || |
|---|
| 1812 | + f->flags & TEP_FIELD_IS_SYMBOLIC) |
|---|
| 1695 | 1813 | fprintf(ofp, "%%s"); |
|---|
| 1696 | | - else if (f->flags & FIELD_IS_SIGNED) |
|---|
| 1814 | + else if (f->flags & TEP_FIELD_IS_SIGNED) |
|---|
| 1697 | 1815 | fprintf(ofp, "%%d"); |
|---|
| 1698 | 1816 | else |
|---|
| 1699 | 1817 | fprintf(ofp, "%%u"); |
|---|
| .. | .. |
|---|
| 1711 | 1829 | if (++count % 5 == 0) |
|---|
| 1712 | 1830 | fprintf(ofp, "\n\t\t"); |
|---|
| 1713 | 1831 | |
|---|
| 1714 | | - if (f->flags & FIELD_IS_FLAG) { |
|---|
| 1832 | + if (f->flags & TEP_FIELD_IS_FLAG) { |
|---|
| 1715 | 1833 | if ((count - 1) % 5 != 0) { |
|---|
| 1716 | 1834 | fprintf(ofp, "\n\t\t"); |
|---|
| 1717 | 1835 | count = 4; |
|---|
| .. | .. |
|---|
| 1721 | 1839 | event->name); |
|---|
| 1722 | 1840 | fprintf(ofp, "\"%s\", %s)", f->name, |
|---|
| 1723 | 1841 | f->name); |
|---|
| 1724 | | - } else if (f->flags & FIELD_IS_SYMBOLIC) { |
|---|
| 1842 | + } else if (f->flags & TEP_FIELD_IS_SYMBOLIC) { |
|---|
| 1725 | 1843 | if ((count - 1) % 5 != 0) { |
|---|
| 1726 | 1844 | fprintf(ofp, "\n\t\t"); |
|---|
| 1727 | 1845 | count = 4; |
|---|
| .. | .. |
|---|
| 1778 | 1896 | .flush_script = python_flush_script, |
|---|
| 1779 | 1897 | .stop_script = python_stop_script, |
|---|
| 1780 | 1898 | .process_event = python_process_event, |
|---|
| 1899 | + .process_switch = python_process_switch, |
|---|
| 1781 | 1900 | .process_stat = python_process_stat, |
|---|
| 1782 | 1901 | .process_stat_interval = python_process_stat_interval, |
|---|
| 1783 | 1902 | .generate_script = python_generate_script, |
|---|