diff options
Diffstat (limited to 'tools/perf/builtin-trace.c')
| -rw-r--r-- | tools/perf/builtin-trace.c | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index dddf3f01b5ab..40a6a2992d15 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
| @@ -1,18 +1,22 @@ | |||
| 1 | #include "builtin.h" | 1 | #include "builtin.h" |
| 2 | 2 | ||
| 3 | #include "util/util.h" | 3 | #include "perf.h" |
| 4 | #include "util/cache.h" | 4 | #include "util/cache.h" |
| 5 | #include "util/debug.h" | ||
| 6 | #include "util/exec_cmd.h" | ||
| 7 | #include "util/header.h" | ||
| 8 | #include "util/parse-options.h" | ||
| 9 | #include "util/session.h" | ||
| 5 | #include "util/symbol.h" | 10 | #include "util/symbol.h" |
| 6 | #include "util/thread.h" | 11 | #include "util/thread.h" |
| 7 | #include "util/header.h" | ||
| 8 | #include "util/exec_cmd.h" | ||
| 9 | #include "util/trace-event.h" | 12 | #include "util/trace-event.h" |
| 10 | #include "util/session.h" | 13 | #include "util/util.h" |
| 11 | 14 | ||
| 12 | static char const *script_name; | 15 | static char const *script_name; |
| 13 | static char const *generate_script_lang; | 16 | static char const *generate_script_lang; |
| 14 | static bool debug_ordering; | 17 | static bool debug_mode; |
| 15 | static u64 last_timestamp; | 18 | static u64 last_timestamp; |
| 19 | static u64 nr_unordered; | ||
| 16 | 20 | ||
| 17 | static int default_start_script(const char *script __unused, | 21 | static int default_start_script(const char *script __unused, |
| 18 | int argc __unused, | 22 | int argc __unused, |
| @@ -58,14 +62,6 @@ static int cleanup_scripting(void) | |||
| 58 | return scripting_ops->stop_script(); | 62 | return scripting_ops->stop_script(); |
| 59 | } | 63 | } |
| 60 | 64 | ||
| 61 | #include "util/parse-options.h" | ||
| 62 | |||
| 63 | #include "perf.h" | ||
| 64 | #include "util/debug.h" | ||
| 65 | |||
| 66 | #include "util/trace-event.h" | ||
| 67 | #include "util/exec_cmd.h" | ||
| 68 | |||
| 69 | static char const *input_name = "perf.data"; | 65 | static char const *input_name = "perf.data"; |
| 70 | 66 | ||
| 71 | static int process_sample_event(event_t *event, struct perf_session *session) | 67 | static int process_sample_event(event_t *event, struct perf_session *session) |
| @@ -91,13 +87,15 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
| 91 | } | 87 | } |
| 92 | 88 | ||
| 93 | if (session->sample_type & PERF_SAMPLE_RAW) { | 89 | if (session->sample_type & PERF_SAMPLE_RAW) { |
| 94 | if (debug_ordering) { | 90 | if (debug_mode) { |
| 95 | if (data.time < last_timestamp) { | 91 | if (data.time < last_timestamp) { |
| 96 | pr_err("Samples misordered, previous: %llu " | 92 | pr_err("Samples misordered, previous: %llu " |
| 97 | "this: %llu\n", last_timestamp, | 93 | "this: %llu\n", last_timestamp, |
| 98 | data.time); | 94 | data.time); |
| 95 | nr_unordered++; | ||
| 99 | } | 96 | } |
| 100 | last_timestamp = data.time; | 97 | last_timestamp = data.time; |
| 98 | return 0; | ||
| 101 | } | 99 | } |
| 102 | /* | 100 | /* |
| 103 | * FIXME: better resolve from pid from the struct trace_entry | 101 | * FIXME: better resolve from pid from the struct trace_entry |
| @@ -113,6 +111,15 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
| 113 | return 0; | 111 | return 0; |
| 114 | } | 112 | } |
| 115 | 113 | ||
| 114 | static u64 nr_lost; | ||
| 115 | |||
| 116 | static int process_lost_event(event_t *event, struct perf_session *session __used) | ||
| 117 | { | ||
| 118 | nr_lost += event->lost.lost; | ||
| 119 | |||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
| 116 | static struct perf_event_ops event_ops = { | 123 | static struct perf_event_ops event_ops = { |
| 117 | .sample = process_sample_event, | 124 | .sample = process_sample_event, |
| 118 | .comm = event__process_comm, | 125 | .comm = event__process_comm, |
| @@ -120,6 +127,7 @@ static struct perf_event_ops event_ops = { | |||
| 120 | .event_type = event__process_event_type, | 127 | .event_type = event__process_event_type, |
| 121 | .tracing_data = event__process_tracing_data, | 128 | .tracing_data = event__process_tracing_data, |
| 122 | .build_id = event__process_build_id, | 129 | .build_id = event__process_build_id, |
| 130 | .lost = process_lost_event, | ||
| 123 | .ordered_samples = true, | 131 | .ordered_samples = true, |
| 124 | }; | 132 | }; |
| 125 | 133 | ||
| @@ -132,9 +140,18 @@ static void sig_handler(int sig __unused) | |||
| 132 | 140 | ||
| 133 | static int __cmd_trace(struct perf_session *session) | 141 | static int __cmd_trace(struct perf_session *session) |
| 134 | { | 142 | { |
| 143 | int ret; | ||
| 144 | |||
| 135 | signal(SIGINT, sig_handler); | 145 | signal(SIGINT, sig_handler); |
| 136 | 146 | ||
| 137 | return perf_session__process_events(session, &event_ops); | 147 | ret = perf_session__process_events(session, &event_ops); |
| 148 | |||
| 149 | if (debug_mode) { | ||
| 150 | pr_err("Misordered timestamps: %llu\n", nr_unordered); | ||
| 151 | pr_err("Lost events: %llu\n", nr_lost); | ||
| 152 | } | ||
| 153 | |||
| 154 | return ret; | ||
| 138 | } | 155 | } |
| 139 | 156 | ||
| 140 | struct script_spec { | 157 | struct script_spec { |
| @@ -544,8 +561,8 @@ static const struct option options[] = { | |||
| 544 | "generate perf-trace.xx script in specified language"), | 561 | "generate perf-trace.xx script in specified language"), |
| 545 | OPT_STRING('i', "input", &input_name, "file", | 562 | OPT_STRING('i', "input", &input_name, "file", |
| 546 | "input file name"), | 563 | "input file name"), |
| 547 | OPT_BOOLEAN('d', "debug-ordering", &debug_ordering, | 564 | OPT_BOOLEAN('d', "debug-mode", &debug_mode, |
| 548 | "check that samples time ordering is monotonic"), | 565 | "do various checks like samples ordering and lost events"), |
| 549 | 566 | ||
| 550 | OPT_END() | 567 | OPT_END() |
| 551 | }; | 568 | }; |
