Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-timechart.c - make an svg timechart of system activity |
| 3 | * |
| 4 | * (C) Copyright 2009 Intel Corporation |
| 5 | * |
| 6 | * Authors: |
| 7 | * Arjan van de Ven <arjan@linux.intel.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; version 2 |
| 12 | * of the License. |
| 13 | */ |
| 14 | |
Jiri Olsa | c85cffa | 2013-07-11 17:28:29 +0200 | [diff] [blame] | 15 | #include <traceevent/event-parse.h> |
| 16 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 17 | #include "builtin.h" |
| 18 | |
| 19 | #include "util/util.h" |
| 20 | |
| 21 | #include "util/color.h" |
| 22 | #include <linux/list.h> |
| 23 | #include "util/cache.h" |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 24 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | e3f4260 | 2011-11-16 17:02:54 -0200 | [diff] [blame] | 25 | #include "util/evsel.h" |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 26 | #include <linux/rbtree.h> |
| 27 | #include "util/symbol.h" |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 28 | #include "util/callchain.h" |
| 29 | #include "util/strlist.h" |
| 30 | |
| 31 | #include "perf.h" |
| 32 | #include "util/header.h" |
| 33 | #include "util/parse-options.h" |
| 34 | #include "util/parse-events.h" |
Li Zefan | 5cbd080 | 2009-12-01 14:05:16 +0800 | [diff] [blame] | 35 | #include "util/event.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 36 | #include "util/session.h" |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 37 | #include "util/svghelper.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 38 | #include "util/tool.h" |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 39 | #include "util/data.h" |
Jiri Olsa | 84f5d36 | 2014-07-14 23:46:48 +0200 | [diff] [blame] | 40 | #include "util/debug.h" |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 41 | |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 42 | #define SUPPORT_OLD_POWER_EVENTS 1 |
| 43 | #define PWR_EVENT_EXIT -1 |
| 44 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 45 | struct per_pid; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 46 | struct power_event; |
Arnaldo Carvalho de Melo | 436b0da | 2013-11-28 13:26:33 -0300 | [diff] [blame] | 47 | struct wake_event; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 48 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 49 | struct timechart { |
| 50 | struct perf_tool tool; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 51 | struct per_pid *all_data; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 52 | struct power_event *power_events; |
Arnaldo Carvalho de Melo | 436b0da | 2013-11-28 13:26:33 -0300 | [diff] [blame] | 53 | struct wake_event *wake_events; |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 54 | int proc_num; |
| 55 | unsigned int numcpus; |
| 56 | u64 min_freq, /* Lowest CPU frequency seen */ |
| 57 | max_freq, /* Highest CPU frequency seen */ |
| 58 | turbo_frequency, |
| 59 | first_time, last_time; |
| 60 | bool power_only, |
| 61 | tasks_only, |
Stanislav Fomichev | c507999 | 2013-12-02 18:37:36 +0400 | [diff] [blame] | 62 | with_backtrace, |
| 63 | topology; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 64 | /* IO related settings */ |
| 65 | u64 io_events; |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 66 | bool io_only, |
| 67 | skip_eagain; |
| 68 | u64 min_time, |
| 69 | merge_dist; |
Yunlong Song | 44f7e43 | 2015-04-02 21:47:17 +0800 | [diff] [blame] | 70 | bool force; |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 71 | }; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 72 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 73 | struct per_pidcomm; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 74 | struct cpu_sample; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 75 | struct io_sample; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Datastructure layout: |
| 79 | * We keep an list of "pid"s, matching the kernels notion of a task struct. |
| 80 | * Each "pid" entry, has a list of "comm"s. |
| 81 | * this is because we want to track different programs different, while |
| 82 | * exec will reuse the original pid (by design). |
| 83 | * Each comm has a list of samples that will be used to draw |
| 84 | * final graph. |
| 85 | */ |
| 86 | |
| 87 | struct per_pid { |
| 88 | struct per_pid *next; |
| 89 | |
| 90 | int pid; |
| 91 | int ppid; |
| 92 | |
| 93 | u64 start_time; |
| 94 | u64 end_time; |
| 95 | u64 total_time; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 96 | u64 total_bytes; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 97 | int display; |
| 98 | |
| 99 | struct per_pidcomm *all; |
| 100 | struct per_pidcomm *current; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | struct per_pidcomm { |
| 105 | struct per_pidcomm *next; |
| 106 | |
| 107 | u64 start_time; |
| 108 | u64 end_time; |
| 109 | u64 total_time; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 110 | u64 max_bytes; |
| 111 | u64 total_bytes; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 112 | |
| 113 | int Y; |
| 114 | int display; |
| 115 | |
| 116 | long state; |
| 117 | u64 state_since; |
| 118 | |
| 119 | char *comm; |
| 120 | |
| 121 | struct cpu_sample *samples; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 122 | struct io_sample *io_samples; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct sample_wrapper { |
| 126 | struct sample_wrapper *next; |
| 127 | |
| 128 | u64 timestamp; |
| 129 | unsigned char data[0]; |
| 130 | }; |
| 131 | |
| 132 | #define TYPE_NONE 0 |
| 133 | #define TYPE_RUNNING 1 |
| 134 | #define TYPE_WAITING 2 |
| 135 | #define TYPE_BLOCKED 3 |
| 136 | |
| 137 | struct cpu_sample { |
| 138 | struct cpu_sample *next; |
| 139 | |
| 140 | u64 start_time; |
| 141 | u64 end_time; |
| 142 | int type; |
| 143 | int cpu; |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 144 | const char *backtrace; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 145 | }; |
| 146 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 147 | enum { |
| 148 | IOTYPE_READ, |
| 149 | IOTYPE_WRITE, |
| 150 | IOTYPE_SYNC, |
| 151 | IOTYPE_TX, |
| 152 | IOTYPE_RX, |
| 153 | IOTYPE_POLL, |
| 154 | }; |
| 155 | |
| 156 | struct io_sample { |
| 157 | struct io_sample *next; |
| 158 | |
| 159 | u64 start_time; |
| 160 | u64 end_time; |
| 161 | u64 bytes; |
| 162 | int type; |
| 163 | int fd; |
| 164 | int err; |
| 165 | int merges; |
| 166 | }; |
| 167 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 168 | #define CSTATE 1 |
| 169 | #define PSTATE 2 |
| 170 | |
| 171 | struct power_event { |
| 172 | struct power_event *next; |
| 173 | int type; |
| 174 | int state; |
| 175 | u64 start_time; |
| 176 | u64 end_time; |
| 177 | int cpu; |
| 178 | }; |
| 179 | |
| 180 | struct wake_event { |
| 181 | struct wake_event *next; |
| 182 | int waker; |
| 183 | int wakee; |
| 184 | u64 time; |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 185 | const char *backtrace; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 188 | struct process_filter { |
Li Zefan | 5cbd080 | 2009-12-01 14:05:16 +0800 | [diff] [blame] | 189 | char *name; |
| 190 | int pid; |
| 191 | struct process_filter *next; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | static struct process_filter *process_filter; |
| 195 | |
| 196 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 197 | static struct per_pid *find_create_pid(struct timechart *tchart, int pid) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 198 | { |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 199 | struct per_pid *cursor = tchart->all_data; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 200 | |
| 201 | while (cursor) { |
| 202 | if (cursor->pid == pid) |
| 203 | return cursor; |
| 204 | cursor = cursor->next; |
| 205 | } |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 206 | cursor = zalloc(sizeof(*cursor)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 207 | assert(cursor != NULL); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 208 | cursor->pid = pid; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 209 | cursor->next = tchart->all_data; |
| 210 | tchart->all_data = cursor; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 211 | return cursor; |
| 212 | } |
| 213 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 214 | static void pid_set_comm(struct timechart *tchart, int pid, char *comm) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 215 | { |
| 216 | struct per_pid *p; |
| 217 | struct per_pidcomm *c; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 218 | p = find_create_pid(tchart, pid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 219 | c = p->all; |
| 220 | while (c) { |
| 221 | if (c->comm && strcmp(c->comm, comm) == 0) { |
| 222 | p->current = c; |
| 223 | return; |
| 224 | } |
| 225 | if (!c->comm) { |
| 226 | c->comm = strdup(comm); |
| 227 | p->current = c; |
| 228 | return; |
| 229 | } |
| 230 | c = c->next; |
| 231 | } |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 232 | c = zalloc(sizeof(*c)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 233 | assert(c != NULL); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 234 | c->comm = strdup(comm); |
| 235 | p->current = c; |
| 236 | c->next = p->all; |
| 237 | p->all = c; |
| 238 | } |
| 239 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 240 | static void pid_fork(struct timechart *tchart, int pid, int ppid, u64 timestamp) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 241 | { |
| 242 | struct per_pid *p, *pp; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 243 | p = find_create_pid(tchart, pid); |
| 244 | pp = find_create_pid(tchart, ppid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 245 | p->ppid = ppid; |
| 246 | if (pp->current && pp->current->comm && !p->current) |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 247 | pid_set_comm(tchart, pid, pp->current->comm); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 248 | |
| 249 | p->start_time = timestamp; |
Stanislav Fomichev | 962e310 | 2014-07-08 20:03:42 +0400 | [diff] [blame] | 250 | if (p->current && !p->current->start_time) { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 251 | p->current->start_time = timestamp; |
| 252 | p->current->state_since = timestamp; |
| 253 | } |
| 254 | } |
| 255 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 256 | static void pid_exit(struct timechart *tchart, int pid, u64 timestamp) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 257 | { |
| 258 | struct per_pid *p; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 259 | p = find_create_pid(tchart, pid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 260 | p->end_time = timestamp; |
| 261 | if (p->current) |
| 262 | p->current->end_time = timestamp; |
| 263 | } |
| 264 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 265 | static void pid_put_sample(struct timechart *tchart, int pid, int type, |
| 266 | unsigned int cpu, u64 start, u64 end, |
| 267 | const char *backtrace) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 268 | { |
| 269 | struct per_pid *p; |
| 270 | struct per_pidcomm *c; |
| 271 | struct cpu_sample *sample; |
| 272 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 273 | p = find_create_pid(tchart, pid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 274 | c = p->current; |
| 275 | if (!c) { |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 276 | c = zalloc(sizeof(*c)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 277 | assert(c != NULL); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 278 | p->current = c; |
| 279 | c->next = p->all; |
| 280 | p->all = c; |
| 281 | } |
| 282 | |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 283 | sample = zalloc(sizeof(*sample)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 284 | assert(sample != NULL); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 285 | sample->start_time = start; |
| 286 | sample->end_time = end; |
| 287 | sample->type = type; |
| 288 | sample->next = c->samples; |
| 289 | sample->cpu = cpu; |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 290 | sample->backtrace = backtrace; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 291 | c->samples = sample; |
| 292 | |
| 293 | if (sample->type == TYPE_RUNNING && end > start && start > 0) { |
| 294 | c->total_time += (end-start); |
| 295 | p->total_time += (end-start); |
| 296 | } |
| 297 | |
| 298 | if (c->start_time == 0 || c->start_time > start) |
| 299 | c->start_time = start; |
| 300 | if (p->start_time == 0 || p->start_time > start) |
| 301 | p->start_time = start; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | #define MAX_CPUS 4096 |
| 305 | |
| 306 | static u64 cpus_cstate_start_times[MAX_CPUS]; |
| 307 | static int cpus_cstate_state[MAX_CPUS]; |
| 308 | static u64 cpus_pstate_start_times[MAX_CPUS]; |
| 309 | static u64 cpus_pstate_state[MAX_CPUS]; |
| 310 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 311 | static int process_comm_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 312 | union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 313 | struct perf_sample *sample __maybe_unused, |
| 314 | struct machine *machine __maybe_unused) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 315 | { |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 316 | struct timechart *tchart = container_of(tool, struct timechart, tool); |
| 317 | pid_set_comm(tchart, event->comm.tid, event->comm.comm); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 318 | return 0; |
| 319 | } |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 320 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 321 | static int process_fork_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 322 | union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 323 | struct perf_sample *sample __maybe_unused, |
| 324 | struct machine *machine __maybe_unused) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 325 | { |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 326 | struct timechart *tchart = container_of(tool, struct timechart, tool); |
| 327 | pid_fork(tchart, event->fork.pid, event->fork.ppid, event->fork.time); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 331 | static int process_exit_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 332 | union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 333 | struct perf_sample *sample __maybe_unused, |
| 334 | struct machine *machine __maybe_unused) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 335 | { |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 336 | struct timechart *tchart = container_of(tool, struct timechart, tool); |
| 337 | pid_exit(tchart, event->fork.pid, event->fork.time); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 341 | #ifdef SUPPORT_OLD_POWER_EVENTS |
| 342 | static int use_old_power_events; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 343 | #endif |
| 344 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 345 | static void c_state_start(int cpu, u64 timestamp, int state) |
| 346 | { |
| 347 | cpus_cstate_start_times[cpu] = timestamp; |
| 348 | cpus_cstate_state[cpu] = state; |
| 349 | } |
| 350 | |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 351 | static void c_state_end(struct timechart *tchart, int cpu, u64 timestamp) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 352 | { |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 353 | struct power_event *pwr = zalloc(sizeof(*pwr)); |
| 354 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 355 | if (!pwr) |
| 356 | return; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 357 | |
| 358 | pwr->state = cpus_cstate_state[cpu]; |
| 359 | pwr->start_time = cpus_cstate_start_times[cpu]; |
| 360 | pwr->end_time = timestamp; |
| 361 | pwr->cpu = cpu; |
| 362 | pwr->type = CSTATE; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 363 | pwr->next = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 364 | |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 365 | tchart->power_events = pwr; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 368 | static void p_state_change(struct timechart *tchart, int cpu, u64 timestamp, u64 new_freq) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 369 | { |
| 370 | struct power_event *pwr; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 371 | |
| 372 | if (new_freq > 8000000) /* detect invalid data */ |
| 373 | return; |
| 374 | |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 375 | pwr = zalloc(sizeof(*pwr)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 376 | if (!pwr) |
| 377 | return; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 378 | |
| 379 | pwr->state = cpus_pstate_state[cpu]; |
| 380 | pwr->start_time = cpus_pstate_start_times[cpu]; |
| 381 | pwr->end_time = timestamp; |
| 382 | pwr->cpu = cpu; |
| 383 | pwr->type = PSTATE; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 384 | pwr->next = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 385 | |
| 386 | if (!pwr->start_time) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 387 | pwr->start_time = tchart->first_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 388 | |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 389 | tchart->power_events = pwr; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 390 | |
| 391 | cpus_pstate_state[cpu] = new_freq; |
| 392 | cpus_pstate_start_times[cpu] = timestamp; |
| 393 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 394 | if ((u64)new_freq > tchart->max_freq) |
| 395 | tchart->max_freq = new_freq; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 396 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 397 | if (new_freq < tchart->min_freq || tchart->min_freq == 0) |
| 398 | tchart->min_freq = new_freq; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 399 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 400 | if (new_freq == tchart->max_freq - 1000) |
| 401 | tchart->turbo_frequency = tchart->max_freq; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 404 | static void sched_wakeup(struct timechart *tchart, int cpu, u64 timestamp, |
| 405 | int waker, int wakee, u8 flags, const char *backtrace) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 406 | { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 407 | struct per_pid *p; |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 408 | struct wake_event *we = zalloc(sizeof(*we)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 409 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 410 | if (!we) |
| 411 | return; |
| 412 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 413 | we->time = timestamp; |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 414 | we->waker = waker; |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 415 | we->backtrace = backtrace; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 416 | |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 417 | if ((flags & TRACE_FLAG_HARDIRQ) || (flags & TRACE_FLAG_SOFTIRQ)) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 418 | we->waker = -1; |
| 419 | |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 420 | we->wakee = wakee; |
Arnaldo Carvalho de Melo | 436b0da | 2013-11-28 13:26:33 -0300 | [diff] [blame] | 421 | we->next = tchart->wake_events; |
| 422 | tchart->wake_events = we; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 423 | p = find_create_pid(tchart, we->wakee); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 424 | |
| 425 | if (p && p->current && p->current->state == TYPE_NONE) { |
| 426 | p->current->state_since = timestamp; |
| 427 | p->current->state = TYPE_WAITING; |
| 428 | } |
| 429 | if (p && p->current && p->current->state == TYPE_BLOCKED) { |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 430 | pid_put_sample(tchart, p->pid, p->current->state, cpu, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 431 | p->current->state_since, timestamp, NULL); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 432 | p->current->state_since = timestamp; |
| 433 | p->current->state = TYPE_WAITING; |
| 434 | } |
| 435 | } |
| 436 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 437 | static void sched_switch(struct timechart *tchart, int cpu, u64 timestamp, |
| 438 | int prev_pid, int next_pid, u64 prev_state, |
| 439 | const char *backtrace) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 440 | { |
| 441 | struct per_pid *p = NULL, *prev_p; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 442 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 443 | prev_p = find_create_pid(tchart, prev_pid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 444 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 445 | p = find_create_pid(tchart, next_pid); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 446 | |
| 447 | if (prev_p->current && prev_p->current->state != TYPE_NONE) |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 448 | pid_put_sample(tchart, prev_pid, TYPE_RUNNING, cpu, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 449 | prev_p->current->state_since, timestamp, |
| 450 | backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 451 | if (p && p->current) { |
| 452 | if (p->current->state != TYPE_NONE) |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 453 | pid_put_sample(tchart, next_pid, p->current->state, cpu, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 454 | p->current->state_since, timestamp, |
| 455 | backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 456 | |
Julia Lawall | 33e26a1 | 2010-08-05 22:27:51 +0200 | [diff] [blame] | 457 | p->current->state_since = timestamp; |
| 458 | p->current->state = TYPE_RUNNING; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | if (prev_p->current) { |
| 462 | prev_p->current->state = TYPE_NONE; |
| 463 | prev_p->current->state_since = timestamp; |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 464 | if (prev_state & 2) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 465 | prev_p->current->state = TYPE_BLOCKED; |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 466 | if (prev_state == 0) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 467 | prev_p->current->state = TYPE_WAITING; |
| 468 | } |
| 469 | } |
| 470 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 471 | static const char *cat_backtrace(union perf_event *event, |
| 472 | struct perf_sample *sample, |
| 473 | struct machine *machine) |
| 474 | { |
| 475 | struct addr_location al; |
| 476 | unsigned int i; |
| 477 | char *p = NULL; |
| 478 | size_t p_len; |
| 479 | u8 cpumode = PERF_RECORD_MISC_USER; |
| 480 | struct addr_location tal; |
| 481 | struct ip_callchain *chain = sample->callchain; |
| 482 | FILE *f = open_memstream(&p, &p_len); |
| 483 | |
| 484 | if (!f) { |
| 485 | perror("open_memstream error"); |
| 486 | return NULL; |
| 487 | } |
| 488 | |
| 489 | if (!chain) |
| 490 | goto exit; |
| 491 | |
| 492 | if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { |
| 493 | fprintf(stderr, "problem processing %d event, skipping it.\n", |
| 494 | event->header.type); |
| 495 | goto exit; |
| 496 | } |
| 497 | |
| 498 | for (i = 0; i < chain->nr; i++) { |
| 499 | u64 ip; |
| 500 | |
| 501 | if (callchain_param.order == ORDER_CALLEE) |
| 502 | ip = chain->ips[i]; |
| 503 | else |
| 504 | ip = chain->ips[chain->nr - i - 1]; |
| 505 | |
| 506 | if (ip >= PERF_CONTEXT_MAX) { |
| 507 | switch (ip) { |
| 508 | case PERF_CONTEXT_HV: |
| 509 | cpumode = PERF_RECORD_MISC_HYPERVISOR; |
| 510 | break; |
| 511 | case PERF_CONTEXT_KERNEL: |
| 512 | cpumode = PERF_RECORD_MISC_KERNEL; |
| 513 | break; |
| 514 | case PERF_CONTEXT_USER: |
| 515 | cpumode = PERF_RECORD_MISC_USER; |
| 516 | break; |
| 517 | default: |
| 518 | pr_debug("invalid callchain context: " |
| 519 | "%"PRId64"\n", (s64) ip); |
| 520 | |
| 521 | /* |
| 522 | * It seems the callchain is corrupted. |
| 523 | * Discard all. |
| 524 | */ |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 525 | zfree(&p); |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 526 | goto exit; |
| 527 | } |
| 528 | continue; |
| 529 | } |
| 530 | |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 531 | tal.filtered = 0; |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 532 | thread__find_addr_location(al.thread, cpumode, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 533 | MAP__FUNCTION, ip, &tal); |
| 534 | |
| 535 | if (tal.sym) |
| 536 | fprintf(f, "..... %016" PRIx64 " %s\n", ip, |
| 537 | tal.sym->name); |
| 538 | else |
| 539 | fprintf(f, "..... %016" PRIx64 "\n", ip); |
| 540 | } |
| 541 | |
| 542 | exit: |
| 543 | fclose(f); |
| 544 | |
| 545 | return p; |
| 546 | } |
| 547 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 548 | typedef int (*tracepoint_handler)(struct timechart *tchart, |
| 549 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 550 | struct perf_sample *sample, |
| 551 | const char *backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 552 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 553 | static int process_sample_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 972ec65 | 2013-11-27 16:32:56 -0300 | [diff] [blame] | 554 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 555 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | e3f4260 | 2011-11-16 17:02:54 -0200 | [diff] [blame] | 556 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 557 | struct machine *machine) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 558 | { |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 559 | struct timechart *tchart = container_of(tool, struct timechart, tool); |
| 560 | |
Arnaldo Carvalho de Melo | e3f4260 | 2011-11-16 17:02:54 -0200 | [diff] [blame] | 561 | if (evsel->attr.sample_type & PERF_SAMPLE_TIME) { |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 562 | if (!tchart->first_time || tchart->first_time > sample->time) |
| 563 | tchart->first_time = sample->time; |
| 564 | if (tchart->last_time < sample->time) |
| 565 | tchart->last_time = sample->time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 566 | } |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 567 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 568 | if (evsel->handler != NULL) { |
| 569 | tracepoint_handler f = evsel->handler; |
Stanislav Fomichev | 58b9a18 | 2013-12-02 18:37:35 +0400 | [diff] [blame] | 570 | return f(tchart, evsel, sample, |
| 571 | cat_backtrace(event, sample, machine)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 572 | } |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 573 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 577 | static int |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 578 | process_sample_cpu_idle(struct timechart *tchart __maybe_unused, |
| 579 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 580 | struct perf_sample *sample, |
| 581 | const char *backtrace __maybe_unused) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 582 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 583 | u32 state = perf_evsel__intval(evsel, sample, "state"); |
| 584 | u32 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 585 | |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 586 | if (state == (u32)PWR_EVENT_EXIT) |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 587 | c_state_end(tchart, cpu_id, sample->time); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 588 | else |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 589 | c_state_start(cpu_id, sample->time, state); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 594 | process_sample_cpu_frequency(struct timechart *tchart, |
| 595 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 596 | struct perf_sample *sample, |
| 597 | const char *backtrace __maybe_unused) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 598 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 599 | u32 state = perf_evsel__intval(evsel, sample, "state"); |
| 600 | u32 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 601 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 602 | p_state_change(tchart, cpu_id, sample->time, state); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | static int |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 607 | process_sample_sched_wakeup(struct timechart *tchart, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 608 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 609 | struct perf_sample *sample, |
| 610 | const char *backtrace) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 611 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 612 | u8 flags = perf_evsel__intval(evsel, sample, "common_flags"); |
| 613 | int waker = perf_evsel__intval(evsel, sample, "common_pid"); |
| 614 | int wakee = perf_evsel__intval(evsel, sample, "pid"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 615 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 616 | sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 621 | process_sample_sched_switch(struct timechart *tchart, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 622 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 623 | struct perf_sample *sample, |
| 624 | const char *backtrace) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 625 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 626 | int prev_pid = perf_evsel__intval(evsel, sample, "prev_pid"); |
| 627 | int next_pid = perf_evsel__intval(evsel, sample, "next_pid"); |
| 628 | u64 prev_state = perf_evsel__intval(evsel, sample, "prev_state"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 629 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 630 | sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, |
| 631 | prev_state, backtrace); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | #ifdef SUPPORT_OLD_POWER_EVENTS |
| 636 | static int |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 637 | process_sample_power_start(struct timechart *tchart __maybe_unused, |
| 638 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 639 | struct perf_sample *sample, |
| 640 | const char *backtrace __maybe_unused) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 641 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 642 | u64 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id"); |
| 643 | u64 value = perf_evsel__intval(evsel, sample, "value"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 644 | |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 645 | c_state_start(cpu_id, sample->time, value); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static int |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 650 | process_sample_power_end(struct timechart *tchart, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 651 | struct perf_evsel *evsel __maybe_unused, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 652 | struct perf_sample *sample, |
| 653 | const char *backtrace __maybe_unused) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 654 | { |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 655 | c_state_end(tchart, sample->cpu, sample->time); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 660 | process_sample_power_frequency(struct timechart *tchart, |
| 661 | struct perf_evsel *evsel, |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 662 | struct perf_sample *sample, |
| 663 | const char *backtrace __maybe_unused) |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 664 | { |
Stanislav Fomichev | 3ed0d21 | 2013-11-27 14:45:00 +0400 | [diff] [blame] | 665 | u64 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id"); |
| 666 | u64 value = perf_evsel__intval(evsel, sample, "value"); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 667 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 668 | p_state_change(tchart, cpu_id, sample->time, value); |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 669 | return 0; |
| 670 | } |
| 671 | #endif /* SUPPORT_OLD_POWER_EVENTS */ |
| 672 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 673 | /* |
| 674 | * After the last sample we need to wrap up the current C/P state |
| 675 | * and close out each CPU for these. |
| 676 | */ |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 677 | static void end_sample_processing(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 678 | { |
| 679 | u64 cpu; |
| 680 | struct power_event *pwr; |
| 681 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 682 | for (cpu = 0; cpu <= tchart->numcpus; cpu++) { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 683 | /* C state */ |
| 684 | #if 0 |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 685 | pwr = zalloc(sizeof(*pwr)); |
| 686 | if (!pwr) |
| 687 | return; |
| 688 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 689 | pwr->state = cpus_cstate_state[cpu]; |
| 690 | pwr->start_time = cpus_cstate_start_times[cpu]; |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 691 | pwr->end_time = tchart->last_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 692 | pwr->cpu = cpu; |
| 693 | pwr->type = CSTATE; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 694 | pwr->next = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 695 | |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 696 | tchart->power_events = pwr; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 697 | #endif |
| 698 | /* P state */ |
| 699 | |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 700 | pwr = zalloc(sizeof(*pwr)); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 701 | if (!pwr) |
| 702 | return; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 703 | |
| 704 | pwr->state = cpus_pstate_state[cpu]; |
| 705 | pwr->start_time = cpus_pstate_start_times[cpu]; |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 706 | pwr->end_time = tchart->last_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 707 | pwr->cpu = cpu; |
| 708 | pwr->type = PSTATE; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 709 | pwr->next = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 710 | |
| 711 | if (!pwr->start_time) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 712 | pwr->start_time = tchart->first_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 713 | if (!pwr->state) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 714 | pwr->state = tchart->min_freq; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 715 | tchart->power_events = pwr; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 719 | static int pid_begin_io_sample(struct timechart *tchart, int pid, int type, |
| 720 | u64 start, int fd) |
| 721 | { |
| 722 | struct per_pid *p = find_create_pid(tchart, pid); |
| 723 | struct per_pidcomm *c = p->current; |
| 724 | struct io_sample *sample; |
| 725 | struct io_sample *prev; |
| 726 | |
| 727 | if (!c) { |
| 728 | c = zalloc(sizeof(*c)); |
| 729 | if (!c) |
| 730 | return -ENOMEM; |
| 731 | p->current = c; |
| 732 | c->next = p->all; |
| 733 | p->all = c; |
| 734 | } |
| 735 | |
| 736 | prev = c->io_samples; |
| 737 | |
| 738 | if (prev && prev->start_time && !prev->end_time) { |
| 739 | pr_warning("Skip invalid start event: " |
| 740 | "previous event already started!\n"); |
| 741 | |
| 742 | /* remove previous event that has been started, |
| 743 | * we are not sure we will ever get an end for it */ |
| 744 | c->io_samples = prev->next; |
| 745 | free(prev); |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | sample = zalloc(sizeof(*sample)); |
| 750 | if (!sample) |
| 751 | return -ENOMEM; |
| 752 | sample->start_time = start; |
| 753 | sample->type = type; |
| 754 | sample->fd = fd; |
| 755 | sample->next = c->io_samples; |
| 756 | c->io_samples = sample; |
| 757 | |
| 758 | if (c->start_time == 0 || c->start_time > start) |
| 759 | c->start_time = start; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int pid_end_io_sample(struct timechart *tchart, int pid, int type, |
| 765 | u64 end, long ret) |
| 766 | { |
| 767 | struct per_pid *p = find_create_pid(tchart, pid); |
| 768 | struct per_pidcomm *c = p->current; |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 769 | struct io_sample *sample, *prev; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 770 | |
| 771 | if (!c) { |
| 772 | pr_warning("Invalid pidcomm!\n"); |
| 773 | return -1; |
| 774 | } |
| 775 | |
| 776 | sample = c->io_samples; |
| 777 | |
| 778 | if (!sample) /* skip partially captured events */ |
| 779 | return 0; |
| 780 | |
| 781 | if (sample->end_time) { |
| 782 | pr_warning("Skip invalid end event: " |
| 783 | "previous event already ended!\n"); |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | if (sample->type != type) { |
| 788 | pr_warning("Skip invalid end event: invalid event type!\n"); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | sample->end_time = end; |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 793 | prev = sample->next; |
| 794 | |
| 795 | /* we want to be able to see small and fast transfers, so make them |
| 796 | * at least min_time long, but don't overlap them */ |
| 797 | if (sample->end_time - sample->start_time < tchart->min_time) |
| 798 | sample->end_time = sample->start_time + tchart->min_time; |
| 799 | if (prev && sample->start_time < prev->end_time) { |
| 800 | if (prev->err) /* try to make errors more visible */ |
| 801 | sample->start_time = prev->end_time; |
| 802 | else |
| 803 | prev->end_time = sample->start_time; |
| 804 | } |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 805 | |
| 806 | if (ret < 0) { |
| 807 | sample->err = ret; |
| 808 | } else if (type == IOTYPE_READ || type == IOTYPE_WRITE || |
| 809 | type == IOTYPE_TX || type == IOTYPE_RX) { |
| 810 | |
| 811 | if ((u64)ret > c->max_bytes) |
| 812 | c->max_bytes = ret; |
| 813 | |
| 814 | c->total_bytes += ret; |
| 815 | p->total_bytes += ret; |
| 816 | sample->bytes = ret; |
| 817 | } |
| 818 | |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 819 | /* merge two requests to make svg smaller and render-friendly */ |
| 820 | if (prev && |
| 821 | prev->type == sample->type && |
| 822 | prev->err == sample->err && |
| 823 | prev->fd == sample->fd && |
| 824 | prev->end_time + tchart->merge_dist >= sample->start_time) { |
| 825 | |
| 826 | sample->bytes += prev->bytes; |
| 827 | sample->merges += prev->merges + 1; |
| 828 | |
| 829 | sample->start_time = prev->start_time; |
| 830 | sample->next = prev->next; |
| 831 | free(prev); |
| 832 | |
| 833 | if (!sample->err && sample->bytes > c->max_bytes) |
| 834 | c->max_bytes = sample->bytes; |
| 835 | } |
| 836 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 837 | tchart->io_events++; |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static int |
| 843 | process_enter_read(struct timechart *tchart, |
| 844 | struct perf_evsel *evsel, |
| 845 | struct perf_sample *sample) |
| 846 | { |
| 847 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 848 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, |
| 849 | sample->time, fd); |
| 850 | } |
| 851 | |
| 852 | static int |
| 853 | process_exit_read(struct timechart *tchart, |
| 854 | struct perf_evsel *evsel, |
| 855 | struct perf_sample *sample) |
| 856 | { |
| 857 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 858 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, |
| 859 | sample->time, ret); |
| 860 | } |
| 861 | |
| 862 | static int |
| 863 | process_enter_write(struct timechart *tchart, |
| 864 | struct perf_evsel *evsel, |
| 865 | struct perf_sample *sample) |
| 866 | { |
| 867 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 868 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, |
| 869 | sample->time, fd); |
| 870 | } |
| 871 | |
| 872 | static int |
| 873 | process_exit_write(struct timechart *tchart, |
| 874 | struct perf_evsel *evsel, |
| 875 | struct perf_sample *sample) |
| 876 | { |
| 877 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 878 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, |
| 879 | sample->time, ret); |
| 880 | } |
| 881 | |
| 882 | static int |
| 883 | process_enter_sync(struct timechart *tchart, |
| 884 | struct perf_evsel *evsel, |
| 885 | struct perf_sample *sample) |
| 886 | { |
| 887 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 888 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, |
| 889 | sample->time, fd); |
| 890 | } |
| 891 | |
| 892 | static int |
| 893 | process_exit_sync(struct timechart *tchart, |
| 894 | struct perf_evsel *evsel, |
| 895 | struct perf_sample *sample) |
| 896 | { |
| 897 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 898 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, |
| 899 | sample->time, ret); |
| 900 | } |
| 901 | |
| 902 | static int |
| 903 | process_enter_tx(struct timechart *tchart, |
| 904 | struct perf_evsel *evsel, |
| 905 | struct perf_sample *sample) |
| 906 | { |
| 907 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 908 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, |
| 909 | sample->time, fd); |
| 910 | } |
| 911 | |
| 912 | static int |
| 913 | process_exit_tx(struct timechart *tchart, |
| 914 | struct perf_evsel *evsel, |
| 915 | struct perf_sample *sample) |
| 916 | { |
| 917 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 918 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, |
| 919 | sample->time, ret); |
| 920 | } |
| 921 | |
| 922 | static int |
| 923 | process_enter_rx(struct timechart *tchart, |
| 924 | struct perf_evsel *evsel, |
| 925 | struct perf_sample *sample) |
| 926 | { |
| 927 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 928 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, |
| 929 | sample->time, fd); |
| 930 | } |
| 931 | |
| 932 | static int |
| 933 | process_exit_rx(struct timechart *tchart, |
| 934 | struct perf_evsel *evsel, |
| 935 | struct perf_sample *sample) |
| 936 | { |
| 937 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 938 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, |
| 939 | sample->time, ret); |
| 940 | } |
| 941 | |
| 942 | static int |
| 943 | process_enter_poll(struct timechart *tchart, |
| 944 | struct perf_evsel *evsel, |
| 945 | struct perf_sample *sample) |
| 946 | { |
| 947 | long fd = perf_evsel__intval(evsel, sample, "fd"); |
| 948 | return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, |
| 949 | sample->time, fd); |
| 950 | } |
| 951 | |
| 952 | static int |
| 953 | process_exit_poll(struct timechart *tchart, |
| 954 | struct perf_evsel *evsel, |
| 955 | struct perf_sample *sample) |
| 956 | { |
| 957 | long ret = perf_evsel__intval(evsel, sample, "ret"); |
| 958 | return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, |
| 959 | sample->time, ret); |
| 960 | } |
| 961 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 962 | /* |
| 963 | * Sort the pid datastructure |
| 964 | */ |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 965 | static void sort_pids(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 966 | { |
| 967 | struct per_pid *new_list, *p, *cursor, *prev; |
| 968 | /* sort by ppid first, then by pid, lowest to highest */ |
| 969 | |
| 970 | new_list = NULL; |
| 971 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 972 | while (tchart->all_data) { |
| 973 | p = tchart->all_data; |
| 974 | tchart->all_data = p->next; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 975 | p->next = NULL; |
| 976 | |
| 977 | if (new_list == NULL) { |
| 978 | new_list = p; |
| 979 | p->next = NULL; |
| 980 | continue; |
| 981 | } |
| 982 | prev = NULL; |
| 983 | cursor = new_list; |
| 984 | while (cursor) { |
| 985 | if (cursor->ppid > p->ppid || |
| 986 | (cursor->ppid == p->ppid && cursor->pid > p->pid)) { |
| 987 | /* must insert before */ |
| 988 | if (prev) { |
| 989 | p->next = prev->next; |
| 990 | prev->next = p; |
| 991 | cursor = NULL; |
| 992 | continue; |
| 993 | } else { |
| 994 | p->next = new_list; |
| 995 | new_list = p; |
| 996 | cursor = NULL; |
| 997 | continue; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | prev = cursor; |
| 1002 | cursor = cursor->next; |
| 1003 | if (!cursor) |
| 1004 | prev->next = p; |
| 1005 | } |
| 1006 | } |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1007 | tchart->all_data = new_list; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1011 | static void draw_c_p_states(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1012 | { |
| 1013 | struct power_event *pwr; |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 1014 | pwr = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1015 | |
| 1016 | /* |
| 1017 | * two pass drawing so that the P state bars are on top of the C state blocks |
| 1018 | */ |
| 1019 | while (pwr) { |
| 1020 | if (pwr->type == CSTATE) |
| 1021 | svg_cstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state); |
| 1022 | pwr = pwr->next; |
| 1023 | } |
| 1024 | |
Arnaldo Carvalho de Melo | 66cc3ad | 2013-11-28 13:23:05 -0300 | [diff] [blame] | 1025 | pwr = tchart->power_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1026 | while (pwr) { |
| 1027 | if (pwr->type == PSTATE) { |
| 1028 | if (!pwr->state) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1029 | pwr->state = tchart->min_freq; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1030 | svg_pstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state); |
| 1031 | } |
| 1032 | pwr = pwr->next; |
| 1033 | } |
| 1034 | } |
| 1035 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1036 | static void draw_wakeups(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1037 | { |
| 1038 | struct wake_event *we; |
| 1039 | struct per_pid *p; |
| 1040 | struct per_pidcomm *c; |
| 1041 | |
Arnaldo Carvalho de Melo | 436b0da | 2013-11-28 13:26:33 -0300 | [diff] [blame] | 1042 | we = tchart->wake_events; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1043 | while (we) { |
| 1044 | int from = 0, to = 0; |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 1045 | char *task_from = NULL, *task_to = NULL; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1046 | |
| 1047 | /* locate the column of the waker and wakee */ |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1048 | p = tchart->all_data; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1049 | while (p) { |
| 1050 | if (p->pid == we->waker || p->pid == we->wakee) { |
| 1051 | c = p->all; |
| 1052 | while (c) { |
| 1053 | if (c->Y && c->start_time <= we->time && c->end_time >= we->time) { |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1054 | if (p->pid == we->waker && !from) { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1055 | from = c->Y; |
Arjan van de Ven | 3bc2a39 | 2009-10-20 06:46:49 +0900 | [diff] [blame] | 1056 | task_from = strdup(c->comm); |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 1057 | } |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1058 | if (p->pid == we->wakee && !to) { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1059 | to = c->Y; |
Arjan van de Ven | 3bc2a39 | 2009-10-20 06:46:49 +0900 | [diff] [blame] | 1060 | task_to = strdup(c->comm); |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 1061 | } |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1062 | } |
| 1063 | c = c->next; |
| 1064 | } |
Arjan van de Ven | 3bc2a39 | 2009-10-20 06:46:49 +0900 | [diff] [blame] | 1065 | c = p->all; |
| 1066 | while (c) { |
| 1067 | if (p->pid == we->waker && !from) { |
| 1068 | from = c->Y; |
| 1069 | task_from = strdup(c->comm); |
| 1070 | } |
| 1071 | if (p->pid == we->wakee && !to) { |
| 1072 | to = c->Y; |
| 1073 | task_to = strdup(c->comm); |
| 1074 | } |
| 1075 | c = c->next; |
| 1076 | } |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1077 | } |
| 1078 | p = p->next; |
| 1079 | } |
| 1080 | |
Arjan van de Ven | 3bc2a39 | 2009-10-20 06:46:49 +0900 | [diff] [blame] | 1081 | if (!task_from) { |
| 1082 | task_from = malloc(40); |
| 1083 | sprintf(task_from, "[%i]", we->waker); |
| 1084 | } |
| 1085 | if (!task_to) { |
| 1086 | task_to = malloc(40); |
| 1087 | sprintf(task_to, "[%i]", we->wakee); |
| 1088 | } |
| 1089 | |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1090 | if (we->waker == -1) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1091 | svg_interrupt(we->time, to, we->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1092 | else if (from && to && abs(from - to) == 1) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1093 | svg_wakeline(we->time, from, to, we->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1094 | else |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1095 | svg_partial_wakeline(we->time, from, task_from, to, |
| 1096 | task_to, we->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1097 | we = we->next; |
Arjan van de Ven | 3bc2a39 | 2009-10-20 06:46:49 +0900 | [diff] [blame] | 1098 | |
| 1099 | free(task_from); |
| 1100 | free(task_to); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1104 | static void draw_cpu_usage(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1105 | { |
| 1106 | struct per_pid *p; |
| 1107 | struct per_pidcomm *c; |
| 1108 | struct cpu_sample *sample; |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1109 | p = tchart->all_data; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1110 | while (p) { |
| 1111 | c = p->all; |
| 1112 | while (c) { |
| 1113 | sample = c->samples; |
| 1114 | while (sample) { |
Stanislav Fomichev | 8b6dcca | 2013-12-02 18:37:33 +0400 | [diff] [blame] | 1115 | if (sample->type == TYPE_RUNNING) { |
| 1116 | svg_process(sample->cpu, |
| 1117 | sample->start_time, |
| 1118 | sample->end_time, |
Stanislav Fomichev | de99622 | 2013-12-02 18:37:34 +0400 | [diff] [blame] | 1119 | p->pid, |
Stanislav Fomichev | 8b6dcca | 2013-12-02 18:37:33 +0400 | [diff] [blame] | 1120 | c->comm, |
| 1121 | sample->backtrace); |
| 1122 | } |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1123 | |
| 1124 | sample = sample->next; |
| 1125 | } |
| 1126 | c = c->next; |
| 1127 | } |
| 1128 | p = p->next; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1132 | static void draw_io_bars(struct timechart *tchart) |
| 1133 | { |
| 1134 | const char *suf; |
| 1135 | double bytes; |
| 1136 | char comm[256]; |
| 1137 | struct per_pid *p; |
| 1138 | struct per_pidcomm *c; |
| 1139 | struct io_sample *sample; |
| 1140 | int Y = 1; |
| 1141 | |
| 1142 | p = tchart->all_data; |
| 1143 | while (p) { |
| 1144 | c = p->all; |
| 1145 | while (c) { |
| 1146 | if (!c->display) { |
| 1147 | c->Y = 0; |
| 1148 | c = c->next; |
| 1149 | continue; |
| 1150 | } |
| 1151 | |
| 1152 | svg_box(Y, c->start_time, c->end_time, "process3"); |
| 1153 | sample = c->io_samples; |
| 1154 | for (sample = c->io_samples; sample; sample = sample->next) { |
| 1155 | double h = (double)sample->bytes / c->max_bytes; |
| 1156 | |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 1157 | if (tchart->skip_eagain && |
| 1158 | sample->err == -EAGAIN) |
| 1159 | continue; |
| 1160 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1161 | if (sample->err) |
| 1162 | h = 1; |
| 1163 | |
| 1164 | if (sample->type == IOTYPE_SYNC) |
| 1165 | svg_fbox(Y, |
| 1166 | sample->start_time, |
| 1167 | sample->end_time, |
| 1168 | 1, |
| 1169 | sample->err ? "error" : "sync", |
| 1170 | sample->fd, |
| 1171 | sample->err, |
| 1172 | sample->merges); |
| 1173 | else if (sample->type == IOTYPE_POLL) |
| 1174 | svg_fbox(Y, |
| 1175 | sample->start_time, |
| 1176 | sample->end_time, |
| 1177 | 1, |
| 1178 | sample->err ? "error" : "poll", |
| 1179 | sample->fd, |
| 1180 | sample->err, |
| 1181 | sample->merges); |
| 1182 | else if (sample->type == IOTYPE_READ) |
| 1183 | svg_ubox(Y, |
| 1184 | sample->start_time, |
| 1185 | sample->end_time, |
| 1186 | h, |
| 1187 | sample->err ? "error" : "disk", |
| 1188 | sample->fd, |
| 1189 | sample->err, |
| 1190 | sample->merges); |
| 1191 | else if (sample->type == IOTYPE_WRITE) |
| 1192 | svg_lbox(Y, |
| 1193 | sample->start_time, |
| 1194 | sample->end_time, |
| 1195 | h, |
| 1196 | sample->err ? "error" : "disk", |
| 1197 | sample->fd, |
| 1198 | sample->err, |
| 1199 | sample->merges); |
| 1200 | else if (sample->type == IOTYPE_RX) |
| 1201 | svg_ubox(Y, |
| 1202 | sample->start_time, |
| 1203 | sample->end_time, |
| 1204 | h, |
| 1205 | sample->err ? "error" : "net", |
| 1206 | sample->fd, |
| 1207 | sample->err, |
| 1208 | sample->merges); |
| 1209 | else if (sample->type == IOTYPE_TX) |
| 1210 | svg_lbox(Y, |
| 1211 | sample->start_time, |
| 1212 | sample->end_time, |
| 1213 | h, |
| 1214 | sample->err ? "error" : "net", |
| 1215 | sample->fd, |
| 1216 | sample->err, |
| 1217 | sample->merges); |
| 1218 | } |
| 1219 | |
| 1220 | suf = ""; |
| 1221 | bytes = c->total_bytes; |
| 1222 | if (bytes > 1024) { |
| 1223 | bytes = bytes / 1024; |
| 1224 | suf = "K"; |
| 1225 | } |
| 1226 | if (bytes > 1024) { |
| 1227 | bytes = bytes / 1024; |
| 1228 | suf = "M"; |
| 1229 | } |
| 1230 | if (bytes > 1024) { |
| 1231 | bytes = bytes / 1024; |
| 1232 | suf = "G"; |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | sprintf(comm, "%s:%i (%3.1f %sbytes)", c->comm ?: "", p->pid, bytes, suf); |
| 1237 | svg_text(Y, c->start_time, comm); |
| 1238 | |
| 1239 | c->Y = Y; |
| 1240 | Y++; |
| 1241 | c = c->next; |
| 1242 | } |
| 1243 | p = p->next; |
| 1244 | } |
| 1245 | } |
| 1246 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1247 | static void draw_process_bars(struct timechart *tchart) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1248 | { |
| 1249 | struct per_pid *p; |
| 1250 | struct per_pidcomm *c; |
| 1251 | struct cpu_sample *sample; |
| 1252 | int Y = 0; |
| 1253 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1254 | Y = 2 * tchart->numcpus + 2; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1255 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1256 | p = tchart->all_data; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1257 | while (p) { |
| 1258 | c = p->all; |
| 1259 | while (c) { |
| 1260 | if (!c->display) { |
| 1261 | c->Y = 0; |
| 1262 | c = c->next; |
| 1263 | continue; |
| 1264 | } |
| 1265 | |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 1266 | svg_box(Y, c->start_time, c->end_time, "process"); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1267 | sample = c->samples; |
| 1268 | while (sample) { |
| 1269 | if (sample->type == TYPE_RUNNING) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1270 | svg_running(Y, sample->cpu, |
| 1271 | sample->start_time, |
| 1272 | sample->end_time, |
| 1273 | sample->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1274 | if (sample->type == TYPE_BLOCKED) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1275 | svg_blocked(Y, sample->cpu, |
| 1276 | sample->start_time, |
| 1277 | sample->end_time, |
| 1278 | sample->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1279 | if (sample->type == TYPE_WAITING) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1280 | svg_waiting(Y, sample->cpu, |
| 1281 | sample->start_time, |
| 1282 | sample->end_time, |
| 1283 | sample->backtrace); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1284 | sample = sample->next; |
| 1285 | } |
| 1286 | |
| 1287 | if (c->comm) { |
| 1288 | char comm[256]; |
| 1289 | if (c->total_time > 5000000000) /* 5 seconds */ |
| 1290 | sprintf(comm, "%s:%i (%2.2fs)", c->comm, p->pid, c->total_time / 1000000000.0); |
| 1291 | else |
| 1292 | sprintf(comm, "%s:%i (%3.1fms)", c->comm, p->pid, c->total_time / 1000000.0); |
| 1293 | |
| 1294 | svg_text(Y, c->start_time, comm); |
| 1295 | } |
| 1296 | c->Y = Y; |
| 1297 | Y++; |
| 1298 | c = c->next; |
| 1299 | } |
| 1300 | p = p->next; |
| 1301 | } |
| 1302 | } |
| 1303 | |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1304 | static void add_process_filter(const char *string) |
| 1305 | { |
Arnaldo Carvalho de Melo | e0dcd6f | 2012-09-24 11:16:40 -0300 | [diff] [blame] | 1306 | int pid = strtoull(string, NULL, 10); |
| 1307 | struct process_filter *filt = malloc(sizeof(*filt)); |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1308 | |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1309 | if (!filt) |
| 1310 | return; |
| 1311 | |
| 1312 | filt->name = strdup(string); |
| 1313 | filt->pid = pid; |
| 1314 | filt->next = process_filter; |
| 1315 | |
| 1316 | process_filter = filt; |
| 1317 | } |
| 1318 | |
| 1319 | static int passes_filter(struct per_pid *p, struct per_pidcomm *c) |
| 1320 | { |
| 1321 | struct process_filter *filt; |
| 1322 | if (!process_filter) |
| 1323 | return 1; |
| 1324 | |
| 1325 | filt = process_filter; |
| 1326 | while (filt) { |
| 1327 | if (filt->pid && p->pid == filt->pid) |
| 1328 | return 1; |
| 1329 | if (strcmp(filt->name, c->comm) == 0) |
| 1330 | return 1; |
| 1331 | filt = filt->next; |
| 1332 | } |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1336 | static int determine_display_tasks_filtered(struct timechart *tchart) |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1337 | { |
| 1338 | struct per_pid *p; |
| 1339 | struct per_pidcomm *c; |
| 1340 | int count = 0; |
| 1341 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1342 | p = tchart->all_data; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1343 | while (p) { |
| 1344 | p->display = 0; |
| 1345 | if (p->start_time == 1) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1346 | p->start_time = tchart->first_time; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1347 | |
| 1348 | /* no exit marker, task kept running to the end */ |
| 1349 | if (p->end_time == 0) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1350 | p->end_time = tchart->last_time; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1351 | |
| 1352 | c = p->all; |
| 1353 | |
| 1354 | while (c) { |
| 1355 | c->display = 0; |
| 1356 | |
| 1357 | if (c->start_time == 1) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1358 | c->start_time = tchart->first_time; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1359 | |
| 1360 | if (passes_filter(p, c)) { |
| 1361 | c->display = 1; |
| 1362 | p->display = 1; |
| 1363 | count++; |
| 1364 | } |
| 1365 | |
| 1366 | if (c->end_time == 0) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1367 | c->end_time = tchart->last_time; |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1368 | |
| 1369 | c = c->next; |
| 1370 | } |
| 1371 | p = p->next; |
| 1372 | } |
| 1373 | return count; |
| 1374 | } |
| 1375 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1376 | static int determine_display_tasks(struct timechart *tchart, u64 threshold) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1377 | { |
| 1378 | struct per_pid *p; |
| 1379 | struct per_pidcomm *c; |
| 1380 | int count = 0; |
| 1381 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1382 | p = tchart->all_data; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1383 | while (p) { |
| 1384 | p->display = 0; |
| 1385 | if (p->start_time == 1) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1386 | p->start_time = tchart->first_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1387 | |
| 1388 | /* no exit marker, task kept running to the end */ |
| 1389 | if (p->end_time == 0) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1390 | p->end_time = tchart->last_time; |
Stanislav Fomichev | 753c505 | 2013-11-01 20:25:47 +0400 | [diff] [blame] | 1391 | if (p->total_time >= threshold) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1392 | p->display = 1; |
| 1393 | |
| 1394 | c = p->all; |
| 1395 | |
| 1396 | while (c) { |
| 1397 | c->display = 0; |
| 1398 | |
| 1399 | if (c->start_time == 1) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1400 | c->start_time = tchart->first_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1401 | |
Stanislav Fomichev | 753c505 | 2013-11-01 20:25:47 +0400 | [diff] [blame] | 1402 | if (c->total_time >= threshold) { |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1403 | c->display = 1; |
| 1404 | count++; |
| 1405 | } |
| 1406 | |
| 1407 | if (c->end_time == 0) |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1408 | c->end_time = tchart->last_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1409 | |
| 1410 | c = c->next; |
| 1411 | } |
| 1412 | p = p->next; |
| 1413 | } |
| 1414 | return count; |
| 1415 | } |
| 1416 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1417 | static int determine_display_io_tasks(struct timechart *timechart, u64 threshold) |
| 1418 | { |
| 1419 | struct per_pid *p; |
| 1420 | struct per_pidcomm *c; |
| 1421 | int count = 0; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1422 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1423 | p = timechart->all_data; |
| 1424 | while (p) { |
| 1425 | /* no exit marker, task kept running to the end */ |
| 1426 | if (p->end_time == 0) |
| 1427 | p->end_time = timechart->last_time; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1428 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1429 | c = p->all; |
| 1430 | |
| 1431 | while (c) { |
| 1432 | c->display = 0; |
| 1433 | |
| 1434 | if (c->total_bytes >= threshold) { |
| 1435 | c->display = 1; |
| 1436 | count++; |
| 1437 | } |
| 1438 | |
| 1439 | if (c->end_time == 0) |
| 1440 | c->end_time = timechart->last_time; |
| 1441 | |
| 1442 | c = c->next; |
| 1443 | } |
| 1444 | p = p->next; |
| 1445 | } |
| 1446 | return count; |
| 1447 | } |
| 1448 | |
| 1449 | #define BYTES_THRESH (1 * 1024 * 1024) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1450 | #define TIME_THRESH 10000000 |
| 1451 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1452 | static void write_svg_file(struct timechart *tchart, const char *filename) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1453 | { |
| 1454 | u64 i; |
| 1455 | int count; |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1456 | int thresh = tchart->io_events ? BYTES_THRESH : TIME_THRESH; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1457 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1458 | if (tchart->power_only) |
| 1459 | tchart->proc_num = 0; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1460 | |
Stanislav Fomichev | 0a8eb27 | 2013-11-01 20:25:45 +0400 | [diff] [blame] | 1461 | /* We'd like to show at least proc_num tasks; |
| 1462 | * be less picky if we have fewer */ |
| 1463 | do { |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1464 | if (process_filter) |
| 1465 | count = determine_display_tasks_filtered(tchart); |
| 1466 | else if (tchart->io_events) |
| 1467 | count = determine_display_io_tasks(tchart, thresh); |
| 1468 | else |
| 1469 | count = determine_display_tasks(tchart, thresh); |
Stanislav Fomichev | 0a8eb27 | 2013-11-01 20:25:45 +0400 | [diff] [blame] | 1470 | thresh /= 10; |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1471 | } while (!process_filter && thresh && count < tchart->proc_num); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1472 | |
Stanislav Fomichev | 3415d8b | 2014-01-20 15:39:38 +0400 | [diff] [blame] | 1473 | if (!tchart->proc_num) |
| 1474 | count = 0; |
| 1475 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1476 | if (tchart->io_events) { |
| 1477 | open_svg(filename, 0, count, tchart->first_time, tchart->last_time); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1478 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1479 | svg_time_grid(0.5); |
| 1480 | svg_io_legenda(); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1481 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1482 | draw_io_bars(tchart); |
| 1483 | } else { |
| 1484 | open_svg(filename, tchart->numcpus, count, tchart->first_time, tchart->last_time); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1485 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1486 | svg_time_grid(0); |
| 1487 | |
| 1488 | svg_legenda(); |
| 1489 | |
| 1490 | for (i = 0; i < tchart->numcpus; i++) |
| 1491 | svg_cpu_box(i, tchart->max_freq, tchart->turbo_frequency); |
| 1492 | |
| 1493 | draw_cpu_usage(tchart); |
| 1494 | if (tchart->proc_num) |
| 1495 | draw_process_bars(tchart); |
| 1496 | if (!tchart->tasks_only) |
| 1497 | draw_c_p_states(tchart); |
| 1498 | if (tchart->proc_num) |
| 1499 | draw_wakeups(tchart); |
| 1500 | } |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1501 | |
| 1502 | svg_close(); |
| 1503 | } |
| 1504 | |
Stanislav Fomichev | 58b9a18 | 2013-12-02 18:37:35 +0400 | [diff] [blame] | 1505 | static int process_header(struct perf_file_section *section __maybe_unused, |
| 1506 | struct perf_header *ph, |
| 1507 | int feat, |
| 1508 | int fd __maybe_unused, |
| 1509 | void *data) |
| 1510 | { |
| 1511 | struct timechart *tchart = data; |
| 1512 | |
| 1513 | switch (feat) { |
| 1514 | case HEADER_NRCPUS: |
| 1515 | tchart->numcpus = ph->env.nr_cpus_avail; |
| 1516 | break; |
Stanislav Fomichev | c507999 | 2013-12-02 18:37:36 +0400 | [diff] [blame] | 1517 | |
| 1518 | case HEADER_CPU_TOPOLOGY: |
| 1519 | if (!tchart->topology) |
| 1520 | break; |
| 1521 | |
| 1522 | if (svg_build_topology_map(ph->env.sibling_cores, |
| 1523 | ph->env.nr_sibling_cores, |
| 1524 | ph->env.sibling_threads, |
| 1525 | ph->env.nr_sibling_threads)) |
| 1526 | fprintf(stderr, "problem building topology\n"); |
| 1527 | break; |
| 1528 | |
Stanislav Fomichev | 58b9a18 | 2013-12-02 18:37:35 +0400 | [diff] [blame] | 1529 | default: |
| 1530 | break; |
| 1531 | } |
| 1532 | |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1536 | static int __cmd_timechart(struct timechart *tchart, const char *output_name) |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1537 | { |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 1538 | const struct perf_evsel_str_handler power_tracepoints[] = { |
| 1539 | { "power:cpu_idle", process_sample_cpu_idle }, |
| 1540 | { "power:cpu_frequency", process_sample_cpu_frequency }, |
| 1541 | { "sched:sched_wakeup", process_sample_sched_wakeup }, |
| 1542 | { "sched:sched_switch", process_sample_sched_switch }, |
| 1543 | #ifdef SUPPORT_OLD_POWER_EVENTS |
| 1544 | { "power:power_start", process_sample_power_start }, |
| 1545 | { "power:power_end", process_sample_power_end }, |
| 1546 | { "power:power_frequency", process_sample_power_frequency }, |
| 1547 | #endif |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1548 | |
| 1549 | { "syscalls:sys_enter_read", process_enter_read }, |
| 1550 | { "syscalls:sys_enter_pread64", process_enter_read }, |
| 1551 | { "syscalls:sys_enter_readv", process_enter_read }, |
| 1552 | { "syscalls:sys_enter_preadv", process_enter_read }, |
| 1553 | { "syscalls:sys_enter_write", process_enter_write }, |
| 1554 | { "syscalls:sys_enter_pwrite64", process_enter_write }, |
| 1555 | { "syscalls:sys_enter_writev", process_enter_write }, |
| 1556 | { "syscalls:sys_enter_pwritev", process_enter_write }, |
| 1557 | { "syscalls:sys_enter_sync", process_enter_sync }, |
| 1558 | { "syscalls:sys_enter_sync_file_range", process_enter_sync }, |
| 1559 | { "syscalls:sys_enter_fsync", process_enter_sync }, |
| 1560 | { "syscalls:sys_enter_msync", process_enter_sync }, |
| 1561 | { "syscalls:sys_enter_recvfrom", process_enter_rx }, |
| 1562 | { "syscalls:sys_enter_recvmmsg", process_enter_rx }, |
| 1563 | { "syscalls:sys_enter_recvmsg", process_enter_rx }, |
| 1564 | { "syscalls:sys_enter_sendto", process_enter_tx }, |
| 1565 | { "syscalls:sys_enter_sendmsg", process_enter_tx }, |
| 1566 | { "syscalls:sys_enter_sendmmsg", process_enter_tx }, |
| 1567 | { "syscalls:sys_enter_epoll_pwait", process_enter_poll }, |
| 1568 | { "syscalls:sys_enter_epoll_wait", process_enter_poll }, |
| 1569 | { "syscalls:sys_enter_poll", process_enter_poll }, |
| 1570 | { "syscalls:sys_enter_ppoll", process_enter_poll }, |
| 1571 | { "syscalls:sys_enter_pselect6", process_enter_poll }, |
| 1572 | { "syscalls:sys_enter_select", process_enter_poll }, |
| 1573 | |
| 1574 | { "syscalls:sys_exit_read", process_exit_read }, |
| 1575 | { "syscalls:sys_exit_pread64", process_exit_read }, |
| 1576 | { "syscalls:sys_exit_readv", process_exit_read }, |
| 1577 | { "syscalls:sys_exit_preadv", process_exit_read }, |
| 1578 | { "syscalls:sys_exit_write", process_exit_write }, |
| 1579 | { "syscalls:sys_exit_pwrite64", process_exit_write }, |
| 1580 | { "syscalls:sys_exit_writev", process_exit_write }, |
| 1581 | { "syscalls:sys_exit_pwritev", process_exit_write }, |
| 1582 | { "syscalls:sys_exit_sync", process_exit_sync }, |
| 1583 | { "syscalls:sys_exit_sync_file_range", process_exit_sync }, |
| 1584 | { "syscalls:sys_exit_fsync", process_exit_sync }, |
| 1585 | { "syscalls:sys_exit_msync", process_exit_sync }, |
| 1586 | { "syscalls:sys_exit_recvfrom", process_exit_rx }, |
| 1587 | { "syscalls:sys_exit_recvmmsg", process_exit_rx }, |
| 1588 | { "syscalls:sys_exit_recvmsg", process_exit_rx }, |
| 1589 | { "syscalls:sys_exit_sendto", process_exit_tx }, |
| 1590 | { "syscalls:sys_exit_sendmsg", process_exit_tx }, |
| 1591 | { "syscalls:sys_exit_sendmmsg", process_exit_tx }, |
| 1592 | { "syscalls:sys_exit_epoll_pwait", process_exit_poll }, |
| 1593 | { "syscalls:sys_exit_epoll_wait", process_exit_poll }, |
| 1594 | { "syscalls:sys_exit_poll", process_exit_poll }, |
| 1595 | { "syscalls:sys_exit_ppoll", process_exit_poll }, |
| 1596 | { "syscalls:sys_exit_pselect6", process_exit_poll }, |
| 1597 | { "syscalls:sys_exit_select", process_exit_poll }, |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 1598 | }; |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1599 | struct perf_data_file file = { |
| 1600 | .path = input_name, |
| 1601 | .mode = PERF_DATA_MODE_READ, |
Yunlong Song | 44f7e43 | 2015-04-02 21:47:17 +0800 | [diff] [blame] | 1602 | .force = tchart->force, |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1603 | }; |
| 1604 | |
| 1605 | struct perf_session *session = perf_session__new(&file, false, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1606 | &tchart->tool); |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1607 | int ret = -EINVAL; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1608 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1609 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 1610 | return -1; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1611 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1612 | symbol__init(&session->header.env); |
Namhyung Kim | dc5c819 | 2014-08-12 15:40:43 +0900 | [diff] [blame] | 1613 | |
Stanislav Fomichev | 58b9a18 | 2013-12-02 18:37:35 +0400 | [diff] [blame] | 1614 | (void)perf_header__process_sections(&session->header, |
| 1615 | perf_data_file__fd(session->file), |
| 1616 | tchart, |
| 1617 | process_header); |
| 1618 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1619 | if (!perf_session__has_traces(session, "timechart record")) |
| 1620 | goto out_delete; |
| 1621 | |
Jiri Olsa | 5936678 | 2013-07-11 17:28:30 +0200 | [diff] [blame] | 1622 | if (perf_session__set_tracepoints_handlers(session, |
| 1623 | power_tracepoints)) { |
| 1624 | pr_err("Initializing session tracepoint handlers failed\n"); |
| 1625 | goto out_delete; |
| 1626 | } |
| 1627 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1628 | ret = perf_session__process_events(session); |
Li Zefan | 5cbd080 | 2009-12-01 14:05:16 +0800 | [diff] [blame] | 1629 | if (ret) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1630 | goto out_delete; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1631 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1632 | end_sample_processing(tchart); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1633 | |
Arnaldo Carvalho de Melo | 5e22f6d | 2013-11-28 11:50:41 -0300 | [diff] [blame] | 1634 | sort_pids(tchart); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1635 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1636 | write_svg_file(tchart, output_name); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1637 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1638 | pr_info("Written %2.1f seconds of trace to %s.\n", |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1639 | (tchart->last_time - tchart->first_time) / 1000000000.0, output_name); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1640 | out_delete: |
| 1641 | perf_session__delete(session); |
| 1642 | return ret; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1643 | } |
| 1644 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1645 | static int timechart__io_record(int argc, const char **argv) |
| 1646 | { |
| 1647 | unsigned int rec_argc, i; |
| 1648 | const char **rec_argv; |
| 1649 | const char **p; |
| 1650 | char *filter = NULL; |
| 1651 | |
| 1652 | const char * const common_args[] = { |
| 1653 | "record", "-a", "-R", "-c", "1", |
| 1654 | }; |
| 1655 | unsigned int common_args_nr = ARRAY_SIZE(common_args); |
| 1656 | |
| 1657 | const char * const disk_events[] = { |
| 1658 | "syscalls:sys_enter_read", |
| 1659 | "syscalls:sys_enter_pread64", |
| 1660 | "syscalls:sys_enter_readv", |
| 1661 | "syscalls:sys_enter_preadv", |
| 1662 | "syscalls:sys_enter_write", |
| 1663 | "syscalls:sys_enter_pwrite64", |
| 1664 | "syscalls:sys_enter_writev", |
| 1665 | "syscalls:sys_enter_pwritev", |
| 1666 | "syscalls:sys_enter_sync", |
| 1667 | "syscalls:sys_enter_sync_file_range", |
| 1668 | "syscalls:sys_enter_fsync", |
| 1669 | "syscalls:sys_enter_msync", |
| 1670 | |
| 1671 | "syscalls:sys_exit_read", |
| 1672 | "syscalls:sys_exit_pread64", |
| 1673 | "syscalls:sys_exit_readv", |
| 1674 | "syscalls:sys_exit_preadv", |
| 1675 | "syscalls:sys_exit_write", |
| 1676 | "syscalls:sys_exit_pwrite64", |
| 1677 | "syscalls:sys_exit_writev", |
| 1678 | "syscalls:sys_exit_pwritev", |
| 1679 | "syscalls:sys_exit_sync", |
| 1680 | "syscalls:sys_exit_sync_file_range", |
| 1681 | "syscalls:sys_exit_fsync", |
| 1682 | "syscalls:sys_exit_msync", |
| 1683 | }; |
| 1684 | unsigned int disk_events_nr = ARRAY_SIZE(disk_events); |
| 1685 | |
| 1686 | const char * const net_events[] = { |
| 1687 | "syscalls:sys_enter_recvfrom", |
| 1688 | "syscalls:sys_enter_recvmmsg", |
| 1689 | "syscalls:sys_enter_recvmsg", |
| 1690 | "syscalls:sys_enter_sendto", |
| 1691 | "syscalls:sys_enter_sendmsg", |
| 1692 | "syscalls:sys_enter_sendmmsg", |
| 1693 | |
| 1694 | "syscalls:sys_exit_recvfrom", |
| 1695 | "syscalls:sys_exit_recvmmsg", |
| 1696 | "syscalls:sys_exit_recvmsg", |
| 1697 | "syscalls:sys_exit_sendto", |
| 1698 | "syscalls:sys_exit_sendmsg", |
| 1699 | "syscalls:sys_exit_sendmmsg", |
| 1700 | }; |
| 1701 | unsigned int net_events_nr = ARRAY_SIZE(net_events); |
| 1702 | |
| 1703 | const char * const poll_events[] = { |
| 1704 | "syscalls:sys_enter_epoll_pwait", |
| 1705 | "syscalls:sys_enter_epoll_wait", |
| 1706 | "syscalls:sys_enter_poll", |
| 1707 | "syscalls:sys_enter_ppoll", |
| 1708 | "syscalls:sys_enter_pselect6", |
| 1709 | "syscalls:sys_enter_select", |
| 1710 | |
| 1711 | "syscalls:sys_exit_epoll_pwait", |
| 1712 | "syscalls:sys_exit_epoll_wait", |
| 1713 | "syscalls:sys_exit_poll", |
| 1714 | "syscalls:sys_exit_ppoll", |
| 1715 | "syscalls:sys_exit_pselect6", |
| 1716 | "syscalls:sys_exit_select", |
| 1717 | }; |
| 1718 | unsigned int poll_events_nr = ARRAY_SIZE(poll_events); |
| 1719 | |
| 1720 | rec_argc = common_args_nr + |
| 1721 | disk_events_nr * 4 + |
| 1722 | net_events_nr * 4 + |
| 1723 | poll_events_nr * 4 + |
| 1724 | argc; |
| 1725 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1726 | |
| 1727 | if (rec_argv == NULL) |
| 1728 | return -ENOMEM; |
| 1729 | |
| 1730 | if (asprintf(&filter, "common_pid != %d", getpid()) < 0) |
| 1731 | return -ENOMEM; |
| 1732 | |
| 1733 | p = rec_argv; |
| 1734 | for (i = 0; i < common_args_nr; i++) |
| 1735 | *p++ = strdup(common_args[i]); |
| 1736 | |
| 1737 | for (i = 0; i < disk_events_nr; i++) { |
| 1738 | if (!is_valid_tracepoint(disk_events[i])) { |
| 1739 | rec_argc -= 4; |
| 1740 | continue; |
| 1741 | } |
| 1742 | |
| 1743 | *p++ = "-e"; |
| 1744 | *p++ = strdup(disk_events[i]); |
| 1745 | *p++ = "--filter"; |
| 1746 | *p++ = filter; |
| 1747 | } |
| 1748 | for (i = 0; i < net_events_nr; i++) { |
| 1749 | if (!is_valid_tracepoint(net_events[i])) { |
| 1750 | rec_argc -= 4; |
| 1751 | continue; |
| 1752 | } |
| 1753 | |
| 1754 | *p++ = "-e"; |
| 1755 | *p++ = strdup(net_events[i]); |
| 1756 | *p++ = "--filter"; |
| 1757 | *p++ = filter; |
| 1758 | } |
| 1759 | for (i = 0; i < poll_events_nr; i++) { |
| 1760 | if (!is_valid_tracepoint(poll_events[i])) { |
| 1761 | rec_argc -= 4; |
| 1762 | continue; |
| 1763 | } |
| 1764 | |
| 1765 | *p++ = "-e"; |
| 1766 | *p++ = strdup(poll_events[i]); |
| 1767 | *p++ = "--filter"; |
| 1768 | *p++ = filter; |
| 1769 | } |
| 1770 | |
| 1771 | for (i = 0; i < (unsigned int)argc; i++) |
| 1772 | *p++ = argv[i]; |
| 1773 | |
| 1774 | return cmd_record(rec_argc, rec_argv, NULL); |
| 1775 | } |
| 1776 | |
| 1777 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1778 | static int timechart__record(struct timechart *tchart, int argc, const char **argv) |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1779 | { |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1780 | unsigned int rec_argc, i, j; |
| 1781 | const char **rec_argv; |
| 1782 | const char **p; |
| 1783 | unsigned int record_elems; |
| 1784 | |
| 1785 | const char * const common_args[] = { |
Jiri Olsa | 4a4d371 | 2013-06-05 13:37:21 +0200 | [diff] [blame] | 1786 | "record", "-a", "-R", "-c", "1", |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1787 | }; |
| 1788 | unsigned int common_args_nr = ARRAY_SIZE(common_args); |
| 1789 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1790 | const char * const backtrace_args[] = { |
| 1791 | "-g", |
| 1792 | }; |
| 1793 | unsigned int backtrace_args_no = ARRAY_SIZE(backtrace_args); |
| 1794 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1795 | const char * const power_args[] = { |
| 1796 | "-e", "power:cpu_frequency", |
| 1797 | "-e", "power:cpu_idle", |
| 1798 | }; |
| 1799 | unsigned int power_args_nr = ARRAY_SIZE(power_args); |
| 1800 | |
| 1801 | const char * const old_power_args[] = { |
| 1802 | #ifdef SUPPORT_OLD_POWER_EVENTS |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1803 | "-e", "power:power_start", |
| 1804 | "-e", "power:power_end", |
| 1805 | "-e", "power:power_frequency", |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1806 | #endif |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1807 | }; |
| 1808 | unsigned int old_power_args_nr = ARRAY_SIZE(old_power_args); |
| 1809 | |
| 1810 | const char * const tasks_args[] = { |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1811 | "-e", "sched:sched_wakeup", |
| 1812 | "-e", "sched:sched_switch", |
| 1813 | }; |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1814 | unsigned int tasks_args_nr = ARRAY_SIZE(tasks_args); |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1815 | |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 1816 | #ifdef SUPPORT_OLD_POWER_EVENTS |
| 1817 | if (!is_valid_tracepoint("power:cpu_idle") && |
| 1818 | is_valid_tracepoint("power:power_start")) { |
| 1819 | use_old_power_events = 1; |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1820 | power_args_nr = 0; |
| 1821 | } else { |
| 1822 | old_power_args_nr = 0; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 1823 | } |
| 1824 | #endif |
| 1825 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1826 | if (tchart->power_only) |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1827 | tasks_args_nr = 0; |
| 1828 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1829 | if (tchart->tasks_only) { |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1830 | power_args_nr = 0; |
| 1831 | old_power_args_nr = 0; |
| 1832 | } |
| 1833 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1834 | if (!tchart->with_backtrace) |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1835 | backtrace_args_no = 0; |
| 1836 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1837 | record_elems = common_args_nr + tasks_args_nr + |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1838 | power_args_nr + old_power_args_nr + backtrace_args_no; |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1839 | |
| 1840 | rec_argc = record_elems + argc; |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1841 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1842 | |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 1843 | if (rec_argv == NULL) |
| 1844 | return -ENOMEM; |
| 1845 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1846 | p = rec_argv; |
| 1847 | for (i = 0; i < common_args_nr; i++) |
| 1848 | *p++ = strdup(common_args[i]); |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1849 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 1850 | for (i = 0; i < backtrace_args_no; i++) |
| 1851 | *p++ = strdup(backtrace_args[i]); |
| 1852 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1853 | for (i = 0; i < tasks_args_nr; i++) |
| 1854 | *p++ = strdup(tasks_args[i]); |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1855 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1856 | for (i = 0; i < power_args_nr; i++) |
| 1857 | *p++ = strdup(power_args[i]); |
| 1858 | |
| 1859 | for (i = 0; i < old_power_args_nr; i++) |
| 1860 | *p++ = strdup(old_power_args[i]); |
| 1861 | |
Ramkumar Ramachandra | 263f89b | 2014-03-16 12:06:05 -0400 | [diff] [blame] | 1862 | for (j = 0; j < (unsigned int)argc; j++) |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1863 | *p++ = argv[j]; |
| 1864 | |
| 1865 | return cmd_record(rec_argc, rec_argv, NULL); |
Arjan van de Ven | 3c09eeb | 2009-09-19 13:34:42 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1868 | static int |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1869 | parse_process(const struct option *opt __maybe_unused, const char *arg, |
| 1870 | int __maybe_unused unset) |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1871 | { |
| 1872 | if (arg) |
| 1873 | add_process_filter(arg); |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
Stanislav Fomichev | e57a2df | 2013-12-17 19:53:49 +0400 | [diff] [blame] | 1877 | static int |
| 1878 | parse_highlight(const struct option *opt __maybe_unused, const char *arg, |
| 1879 | int __maybe_unused unset) |
| 1880 | { |
| 1881 | unsigned long duration = strtoul(arg, NULL, 0); |
| 1882 | |
| 1883 | if (svg_highlight || svg_highlight_name) |
| 1884 | return -1; |
| 1885 | |
| 1886 | if (duration) |
| 1887 | svg_highlight = duration; |
| 1888 | else |
| 1889 | svg_highlight_name = strdup(arg); |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 1894 | static int |
| 1895 | parse_time(const struct option *opt, const char *arg, int __maybe_unused unset) |
| 1896 | { |
| 1897 | char unit = 'n'; |
| 1898 | u64 *value = opt->value; |
| 1899 | |
| 1900 | if (sscanf(arg, "%" PRIu64 "%cs", value, &unit) > 0) { |
| 1901 | switch (unit) { |
| 1902 | case 'm': |
| 1903 | *value *= 1000000; |
| 1904 | break; |
| 1905 | case 'u': |
| 1906 | *value *= 1000; |
| 1907 | break; |
| 1908 | case 'n': |
| 1909 | break; |
| 1910 | default: |
| 1911 | return -1; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1918 | int cmd_timechart(int argc, const char **argv, |
| 1919 | const char *prefix __maybe_unused) |
| 1920 | { |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1921 | struct timechart tchart = { |
| 1922 | .tool = { |
| 1923 | .comm = process_comm_event, |
| 1924 | .fork = process_fork_event, |
| 1925 | .exit = process_exit_event, |
| 1926 | .sample = process_sample_event, |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 1927 | .ordered_events = true, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1928 | }, |
| 1929 | .proc_num = 15, |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 1930 | .min_time = 1000000, |
| 1931 | .merge_dist = 1000, |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1932 | }; |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1933 | const char *output_name = "output.svg"; |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1934 | const struct option timechart_options[] = { |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1935 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
| 1936 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
| 1937 | OPT_INTEGER('w', "width", &svg_page_width, "page width"), |
Stanislav Fomichev | e57a2df | 2013-12-17 19:53:49 +0400 | [diff] [blame] | 1938 | OPT_CALLBACK(0, "highlight", NULL, "duration or task name", |
| 1939 | "highlight tasks. Pass duration in ns or process name.", |
| 1940 | parse_highlight), |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1941 | OPT_BOOLEAN('P', "power-only", &tchart.power_only, "output power data only"), |
| 1942 | OPT_BOOLEAN('T', "tasks-only", &tchart.tasks_only, |
Stanislav Fomichev | c87097d | 2013-11-01 20:25:48 +0400 | [diff] [blame] | 1943 | "output processes data only"), |
Arjan van de Ven | bbe2987 | 2009-10-20 07:09:39 +0900 | [diff] [blame] | 1944 | OPT_CALLBACK('p', "process", NULL, "process", |
| 1945 | "process selector. Pass a pid or process name.", |
| 1946 | parse_process), |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1947 | OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", |
| 1948 | "Look for files with symbols relative to this directory"), |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1949 | OPT_INTEGER('n', "proc-num", &tchart.proc_num, |
Stanislav Fomichev | 54874e3 | 2013-11-01 20:25:46 +0400 | [diff] [blame] | 1950 | "min. number of tasks to print"), |
Stanislav Fomichev | c507999 | 2013-12-02 18:37:36 +0400 | [diff] [blame] | 1951 | OPT_BOOLEAN('t', "topology", &tchart.topology, |
| 1952 | "sort CPUs according to topology"), |
Stanislav Fomichev | d243144 | 2014-07-08 20:03:43 +0400 | [diff] [blame] | 1953 | OPT_BOOLEAN(0, "io-skip-eagain", &tchart.skip_eagain, |
| 1954 | "skip EAGAIN errors"), |
| 1955 | OPT_CALLBACK(0, "io-min-time", &tchart.min_time, "time", |
| 1956 | "all IO faster than min-time will visually appear longer", |
| 1957 | parse_time), |
| 1958 | OPT_CALLBACK(0, "io-merge-dist", &tchart.merge_dist, "time", |
| 1959 | "merge events that are merge-dist us apart", |
| 1960 | parse_time), |
Yunlong Song | 44f7e43 | 2015-04-02 21:47:17 +0800 | [diff] [blame] | 1961 | OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"), |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1962 | OPT_END() |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1963 | }; |
Yunlong Song | 33ec0ca | 2015-03-18 21:35:56 +0800 | [diff] [blame] | 1964 | const char * const timechart_subcommands[] = { "record", NULL }; |
| 1965 | const char *timechart_usage[] = { |
Arnaldo Carvalho de Melo | 73bdc71 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1966 | "perf timechart [<options>] {record}", |
| 1967 | NULL |
| 1968 | }; |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1969 | |
Namhyung Kim | e5b2c20 | 2014-10-23 00:15:46 +0900 | [diff] [blame] | 1970 | const struct option timechart_record_options[] = { |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1971 | OPT_BOOLEAN('P', "power-only", &tchart.power_only, "output power data only"), |
| 1972 | OPT_BOOLEAN('T', "tasks-only", &tchart.tasks_only, |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1973 | "output processes data only"), |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 1974 | OPT_BOOLEAN('I', "io-only", &tchart.io_only, |
| 1975 | "record only IO data"), |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1976 | OPT_BOOLEAN('g', "callchain", &tchart.with_backtrace, "record callchain"), |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1977 | OPT_END() |
| 1978 | }; |
Namhyung Kim | e5b2c20 | 2014-10-23 00:15:46 +0900 | [diff] [blame] | 1979 | const char * const timechart_record_usage[] = { |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1980 | "perf timechart record [<options>]", |
| 1981 | NULL |
| 1982 | }; |
Yunlong Song | 33ec0ca | 2015-03-18 21:35:56 +0800 | [diff] [blame] | 1983 | argc = parse_options_subcommand(argc, argv, timechart_options, timechart_subcommands, |
| 1984 | timechart_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 1985 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1986 | if (tchart.power_only && tchart.tasks_only) { |
Stanislav Fomichev | c87097d | 2013-11-01 20:25:48 +0400 | [diff] [blame] | 1987 | pr_err("-P and -T options cannot be used at the same time.\n"); |
| 1988 | return -1; |
| 1989 | } |
| 1990 | |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1991 | if (argc && !strncmp(argv[0], "rec", 3)) { |
Namhyung Kim | e5b2c20 | 2014-10-23 00:15:46 +0900 | [diff] [blame] | 1992 | argc = parse_options(argc, argv, timechart_record_options, |
| 1993 | timechart_record_usage, |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1994 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 1995 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 1996 | if (tchart.power_only && tchart.tasks_only) { |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 1997 | pr_err("-P and -T options cannot be used at the same time.\n"); |
| 1998 | return -1; |
| 1999 | } |
| 2000 | |
Stanislav Fomichev | b97b59b | 2014-07-08 20:03:41 +0400 | [diff] [blame] | 2001 | if (tchart.io_only) |
| 2002 | return timechart__io_record(argc, argv); |
| 2003 | else |
| 2004 | return timechart__record(&tchart, argc, argv); |
Stanislav Fomichev | 367b315 | 2013-11-01 20:25:50 +0400 | [diff] [blame] | 2005 | } else if (argc) |
| 2006 | usage_with_options(timechart_usage, timechart_options); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 2007 | |
| 2008 | setup_pager(); |
| 2009 | |
Arnaldo Carvalho de Melo | 985b12e | 2013-11-28 11:25:19 -0300 | [diff] [blame] | 2010 | return __cmd_timechart(&tchart, output_name); |
Arjan van de Ven | 1027498 | 2009-09-12 07:53:05 +0200 | [diff] [blame] | 2011 | } |