aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 92d4658f56fb..9c333ff3dfeb 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -24,6 +24,7 @@ static u64 last_timestamp;
24static u64 nr_unordered; 24static u64 nr_unordered;
25extern const struct option record_options[]; 25extern const struct option record_options[];
26static bool no_callchain; 26static bool no_callchain;
27static bool latency_format;
27static bool system_wide; 28static bool system_wide;
28static const char *cpu_list; 29static const char *cpu_list;
29static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 30static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -65,6 +66,7 @@ struct output_option {
65static struct { 66static struct {
66 bool user_set; 67 bool user_set;
67 bool wildcard_set; 68 bool wildcard_set;
69 unsigned int print_ip_opts;
68 u64 fields; 70 u64 fields;
69 u64 invalid_fields; 71 u64 invalid_fields;
70} output[PERF_TYPE_MAX] = { 72} output[PERF_TYPE_MAX] = {
@@ -234,6 +236,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
234{ 236{
235 int j; 237 int j;
236 struct perf_evsel *evsel; 238 struct perf_evsel *evsel;
239 struct perf_event_attr *attr;
237 240
238 for (j = 0; j < PERF_TYPE_MAX; ++j) { 241 for (j = 0; j < PERF_TYPE_MAX; ++j) {
239 evsel = perf_session__find_first_evtype(session, j); 242 evsel = perf_session__find_first_evtype(session, j);
@@ -252,6 +255,24 @@ static int perf_session__check_output_opt(struct perf_session *session)
252 if (evsel && output[j].fields && 255 if (evsel && output[j].fields &&
253 perf_evsel__check_attr(evsel, session)) 256 perf_evsel__check_attr(evsel, session))
254 return -1; 257 return -1;
258
259 if (evsel == NULL)
260 continue;
261
262 attr = &evsel->attr;
263
264 output[j].print_ip_opts = 0;
265 if (PRINT_FIELD(IP))
266 output[j].print_ip_opts |= PRINT_IP_OPT_IP;
267
268 if (PRINT_FIELD(SYM))
269 output[j].print_ip_opts |= PRINT_IP_OPT_SYM;
270
271 if (PRINT_FIELD(DSO))
272 output[j].print_ip_opts |= PRINT_IP_OPT_DSO;
273
274 if (PRINT_FIELD(SYMOFFSET))
275 output[j].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
255 } 276 }
256 277
257 return 0; 278 return 0;
@@ -381,8 +402,8 @@ static void print_sample_bts(union perf_event *event,
381 else 402 else
382 printf("\n"); 403 printf("\n");
383 perf_evsel__print_ip(evsel, event, sample, machine, 404 perf_evsel__print_ip(evsel, event, sample, machine,
384 PRINT_FIELD(SYM), PRINT_FIELD(DSO), 405 output[attr->type].print_ip_opts,
385 PRINT_FIELD(SYMOFFSET)); 406 PERF_MAX_STACK_DEPTH);
386 } 407 }
387 408
388 printf(" => "); 409 printf(" => ");
@@ -396,10 +417,10 @@ static void print_sample_bts(union perf_event *event,
396 417
397static void process_event(union perf_event *event, struct perf_sample *sample, 418static void process_event(union perf_event *event, struct perf_sample *sample,
398 struct perf_evsel *evsel, struct machine *machine, 419 struct perf_evsel *evsel, struct machine *machine,
399 struct addr_location *al) 420 struct thread *thread,
421 struct addr_location *al __maybe_unused)
400{ 422{
401 struct perf_event_attr *attr = &evsel->attr; 423 struct perf_event_attr *attr = &evsel->attr;
402 struct thread *thread = al->thread;
403 424
404 if (output[attr->type].fields == 0) 425 if (output[attr->type].fields == 0)
405 return; 426 return;
@@ -422,9 +443,10 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
422 printf(" "); 443 printf(" ");
423 else 444 else
424 printf("\n"); 445 printf("\n");
446
425 perf_evsel__print_ip(evsel, event, sample, machine, 447 perf_evsel__print_ip(evsel, event, sample, machine,
426 PRINT_FIELD(SYM), PRINT_FIELD(DSO), 448 output[attr->type].print_ip_opts,
427 PRINT_FIELD(SYMOFFSET)); 449 PERF_MAX_STACK_DEPTH);
428 } 450 }
429 451
430 printf("\n"); 452 printf("\n");
@@ -479,7 +501,8 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
479 struct machine *machine) 501 struct machine *machine)
480{ 502{
481 struct addr_location al; 503 struct addr_location al;
482 struct thread *thread = machine__findnew_thread(machine, event->ip.tid); 504 struct thread *thread = machine__findnew_thread(machine, sample->pid,
505 sample->tid);
483 506
484 if (thread == NULL) { 507 if (thread == NULL) {
485 pr_debug("problem processing %d event, skipping it.\n", 508 pr_debug("problem processing %d event, skipping it.\n",
@@ -498,7 +521,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
498 return 0; 521 return 0;
499 } 522 }
500 523
501 if (perf_event__preprocess_sample(event, machine, &al, sample, 0) < 0) { 524 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
502 pr_err("problem processing %d event, skipping it.\n", 525 pr_err("problem processing %d event, skipping it.\n",
503 event->header.type); 526 event->header.type);
504 return -1; 527 return -1;
@@ -510,7 +533,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
510 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 533 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
511 return 0; 534 return 0;
512 535
513 scripting_ops->process_event(event, sample, evsel, machine, &al); 536 scripting_ops->process_event(event, sample, evsel, machine, thread, &al);
514 537
515 evsel->hists.stats.total_period += sample->period; 538 evsel->hists.stats.total_period += sample->period;
516 return 0; 539 return 0;
@@ -519,19 +542,17 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
519static struct perf_tool perf_script = { 542static struct perf_tool perf_script = {
520 .sample = process_sample_event, 543 .sample = process_sample_event,
521 .mmap = perf_event__process_mmap, 544 .mmap = perf_event__process_mmap,
545 .mmap2 = perf_event__process_mmap2,
522 .comm = perf_event__process_comm, 546 .comm = perf_event__process_comm,
523 .exit = perf_event__process_exit, 547 .exit = perf_event__process_exit,
524 .fork = perf_event__process_fork, 548 .fork = perf_event__process_fork,
525 .attr = perf_event__process_attr, 549 .attr = perf_event__process_attr,
526 .event_type = perf_event__process_event_type,
527 .tracing_data = perf_event__process_tracing_data, 550 .tracing_data = perf_event__process_tracing_data,
528 .build_id = perf_event__process_build_id, 551 .build_id = perf_event__process_build_id,
529 .ordered_samples = true, 552 .ordered_samples = true,
530 .ordering_requires_timestamps = true, 553 .ordering_requires_timestamps = true,
531}; 554};
532 555
533extern volatile int session_done;
534
535static void sig_handler(int sig __maybe_unused) 556static void sig_handler(int sig __maybe_unused)
536{ 557{
537 session_done = 1; 558 session_done = 1;