diff options
Diffstat (limited to 'tools/perf/builtin-timechart.c')
| -rw-r--r-- | tools/perf/builtin-timechart.c | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 3b75b2e21ea5..b1a8a3b841cc 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
| @@ -168,9 +168,8 @@ static struct per_pid *find_create_pid(int pid) | |||
| 168 | return cursor; | 168 | return cursor; |
| 169 | cursor = cursor->next; | 169 | cursor = cursor->next; |
| 170 | } | 170 | } |
| 171 | cursor = malloc(sizeof(struct per_pid)); | 171 | cursor = zalloc(sizeof(*cursor)); |
| 172 | assert(cursor != NULL); | 172 | assert(cursor != NULL); |
| 173 | memset(cursor, 0, sizeof(struct per_pid)); | ||
| 174 | cursor->pid = pid; | 173 | cursor->pid = pid; |
| 175 | cursor->next = all_data; | 174 | cursor->next = all_data; |
| 176 | all_data = cursor; | 175 | all_data = cursor; |
| @@ -195,9 +194,8 @@ static void pid_set_comm(int pid, char *comm) | |||
| 195 | } | 194 | } |
| 196 | c = c->next; | 195 | c = c->next; |
| 197 | } | 196 | } |
| 198 | c = malloc(sizeof(struct per_pidcomm)); | 197 | c = zalloc(sizeof(*c)); |
| 199 | assert(c != NULL); | 198 | assert(c != NULL); |
| 200 | memset(c, 0, sizeof(struct per_pidcomm)); | ||
| 201 | c->comm = strdup(comm); | 199 | c->comm = strdup(comm); |
| 202 | p->current = c; | 200 | p->current = c; |
| 203 | c->next = p->all; | 201 | c->next = p->all; |
| @@ -239,17 +237,15 @@ pid_put_sample(int pid, int type, unsigned int cpu, u64 start, u64 end) | |||
| 239 | p = find_create_pid(pid); | 237 | p = find_create_pid(pid); |
| 240 | c = p->current; | 238 | c = p->current; |
| 241 | if (!c) { | 239 | if (!c) { |
| 242 | c = malloc(sizeof(struct per_pidcomm)); | 240 | c = zalloc(sizeof(*c)); |
| 243 | assert(c != NULL); | 241 | assert(c != NULL); |
| 244 | memset(c, 0, sizeof(struct per_pidcomm)); | ||
| 245 | p->current = c; | 242 | p->current = c; |
| 246 | c->next = p->all; | 243 | c->next = p->all; |
| 247 | p->all = c; | 244 | p->all = c; |
| 248 | } | 245 | } |
| 249 | 246 | ||
| 250 | sample = malloc(sizeof(struct cpu_sample)); | 247 | sample = zalloc(sizeof(*sample)); |
| 251 | assert(sample != NULL); | 248 | assert(sample != NULL); |
| 252 | memset(sample, 0, sizeof(struct cpu_sample)); | ||
| 253 | sample->start_time = start; | 249 | sample->start_time = start; |
| 254 | sample->end_time = end; | 250 | sample->end_time = end; |
| 255 | sample->type = type; | 251 | sample->type = type; |
| @@ -275,28 +271,28 @@ static int cpus_cstate_state[MAX_CPUS]; | |||
| 275 | static u64 cpus_pstate_start_times[MAX_CPUS]; | 271 | static u64 cpus_pstate_start_times[MAX_CPUS]; |
| 276 | static u64 cpus_pstate_state[MAX_CPUS]; | 272 | static u64 cpus_pstate_state[MAX_CPUS]; |
| 277 | 273 | ||
| 278 | static int process_comm_event(struct perf_tool *tool __used, | 274 | static int process_comm_event(struct perf_tool *tool __maybe_unused, |
| 279 | union perf_event *event, | 275 | union perf_event *event, |
| 280 | struct perf_sample *sample __used, | 276 | struct perf_sample *sample __maybe_unused, |
| 281 | struct machine *machine __used) | 277 | struct machine *machine __maybe_unused) |
| 282 | { | 278 | { |
| 283 | pid_set_comm(event->comm.tid, event->comm.comm); | 279 | pid_set_comm(event->comm.tid, event->comm.comm); |
| 284 | return 0; | 280 | return 0; |
| 285 | } | 281 | } |
| 286 | 282 | ||
| 287 | static int process_fork_event(struct perf_tool *tool __used, | 283 | static int process_fork_event(struct perf_tool *tool __maybe_unused, |
| 288 | union perf_event *event, | 284 | union perf_event *event, |
| 289 | struct perf_sample *sample __used, | 285 | struct perf_sample *sample __maybe_unused, |
| 290 | struct machine *machine __used) | 286 | struct machine *machine __maybe_unused) |
| 291 | { | 287 | { |
| 292 | pid_fork(event->fork.pid, event->fork.ppid, event->fork.time); | 288 | pid_fork(event->fork.pid, event->fork.ppid, event->fork.time); |
| 293 | return 0; | 289 | return 0; |
| 294 | } | 290 | } |
| 295 | 291 | ||
| 296 | static int process_exit_event(struct perf_tool *tool __used, | 292 | static int process_exit_event(struct perf_tool *tool __maybe_unused, |
| 297 | union perf_event *event, | 293 | union perf_event *event, |
| 298 | struct perf_sample *sample __used, | 294 | struct perf_sample *sample __maybe_unused, |
| 299 | struct machine *machine __used) | 295 | struct machine *machine __maybe_unused) |
| 300 | { | 296 | { |
| 301 | pid_exit(event->fork.pid, event->fork.time); | 297 | pid_exit(event->fork.pid, event->fork.time); |
| 302 | return 0; | 298 | return 0; |
| @@ -373,11 +369,10 @@ static void c_state_start(int cpu, u64 timestamp, int state) | |||
| 373 | 369 | ||
| 374 | static void c_state_end(int cpu, u64 timestamp) | 370 | static void c_state_end(int cpu, u64 timestamp) |
| 375 | { | 371 | { |
| 376 | struct power_event *pwr; | 372 | struct power_event *pwr = zalloc(sizeof(*pwr)); |
| 377 | pwr = malloc(sizeof(struct power_event)); | 373 | |
| 378 | if (!pwr) | 374 | if (!pwr) |
| 379 | return; | 375 | return; |
| 380 | memset(pwr, 0, sizeof(struct power_event)); | ||
| 381 | 376 | ||
| 382 | pwr->state = cpus_cstate_state[cpu]; | 377 | pwr->state = cpus_cstate_state[cpu]; |
| 383 | pwr->start_time = cpus_cstate_start_times[cpu]; | 378 | pwr->start_time = cpus_cstate_start_times[cpu]; |
| @@ -392,14 +387,13 @@ static void c_state_end(int cpu, u64 timestamp) | |||
| 392 | static void p_state_change(int cpu, u64 timestamp, u64 new_freq) | 387 | static void p_state_change(int cpu, u64 timestamp, u64 new_freq) |
| 393 | { | 388 | { |
| 394 | struct power_event *pwr; | 389 | struct power_event *pwr; |
| 395 | pwr = malloc(sizeof(struct power_event)); | ||
| 396 | 390 | ||
| 397 | if (new_freq > 8000000) /* detect invalid data */ | 391 | if (new_freq > 8000000) /* detect invalid data */ |
| 398 | return; | 392 | return; |
| 399 | 393 | ||
| 394 | pwr = zalloc(sizeof(*pwr)); | ||
| 400 | if (!pwr) | 395 | if (!pwr) |
| 401 | return; | 396 | return; |
| 402 | memset(pwr, 0, sizeof(struct power_event)); | ||
| 403 | 397 | ||
| 404 | pwr->state = cpus_pstate_state[cpu]; | 398 | pwr->state = cpus_pstate_state[cpu]; |
| 405 | pwr->start_time = cpus_pstate_start_times[cpu]; | 399 | pwr->start_time = cpus_pstate_start_times[cpu]; |
| @@ -429,15 +423,13 @@ static void p_state_change(int cpu, u64 timestamp, u64 new_freq) | |||
| 429 | static void | 423 | static void |
| 430 | sched_wakeup(int cpu, u64 timestamp, int pid, struct trace_entry *te) | 424 | sched_wakeup(int cpu, u64 timestamp, int pid, struct trace_entry *te) |
| 431 | { | 425 | { |
| 432 | struct wake_event *we; | ||
| 433 | struct per_pid *p; | 426 | struct per_pid *p; |
| 434 | struct wakeup_entry *wake = (void *)te; | 427 | struct wakeup_entry *wake = (void *)te; |
| 428 | struct wake_event *we = zalloc(sizeof(*we)); | ||
| 435 | 429 | ||
| 436 | we = malloc(sizeof(struct wake_event)); | ||
| 437 | if (!we) | 430 | if (!we) |
| 438 | return; | 431 | return; |
| 439 | 432 | ||
| 440 | memset(we, 0, sizeof(struct wake_event)); | ||
| 441 | we->time = timestamp; | 433 | we->time = timestamp; |
| 442 | we->waker = pid; | 434 | we->waker = pid; |
| 443 | 435 | ||
| @@ -491,11 +483,11 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te) | |||
| 491 | } | 483 | } |
| 492 | 484 | ||
| 493 | 485 | ||
| 494 | static int process_sample_event(struct perf_tool *tool __used, | 486 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
| 495 | union perf_event *event __used, | 487 | union perf_event *event __maybe_unused, |
| 496 | struct perf_sample *sample, | 488 | struct perf_sample *sample, |
| 497 | struct perf_evsel *evsel, | 489 | struct perf_evsel *evsel, |
| 498 | struct machine *machine __used) | 490 | struct machine *machine __maybe_unused) |
| 499 | { | 491 | { |
| 500 | struct trace_entry *te; | 492 | struct trace_entry *te; |
| 501 | 493 | ||
| @@ -579,13 +571,12 @@ static void end_sample_processing(void) | |||
| 579 | struct power_event *pwr; | 571 | struct power_event *pwr; |
| 580 | 572 | ||
| 581 | for (cpu = 0; cpu <= numcpus; cpu++) { | 573 | for (cpu = 0; cpu <= numcpus; cpu++) { |
| 582 | pwr = malloc(sizeof(struct power_event)); | 574 | /* C state */ |
| 575 | #if 0 | ||
| 576 | pwr = zalloc(sizeof(*pwr)); | ||
| 583 | if (!pwr) | 577 | if (!pwr) |
| 584 | return; | 578 | return; |
| 585 | memset(pwr, 0, sizeof(struct power_event)); | ||
| 586 | 579 | ||
| 587 | /* C state */ | ||
| 588 | #if 0 | ||
| 589 | pwr->state = cpus_cstate_state[cpu]; | 580 | pwr->state = cpus_cstate_state[cpu]; |
| 590 | pwr->start_time = cpus_cstate_start_times[cpu]; | 581 | pwr->start_time = cpus_cstate_start_times[cpu]; |
| 591 | pwr->end_time = last_time; | 582 | pwr->end_time = last_time; |
| @@ -597,10 +588,9 @@ static void end_sample_processing(void) | |||
| 597 | #endif | 588 | #endif |
| 598 | /* P state */ | 589 | /* P state */ |
| 599 | 590 | ||
| 600 | pwr = malloc(sizeof(struct power_event)); | 591 | pwr = zalloc(sizeof(*pwr)); |
| 601 | if (!pwr) | 592 | if (!pwr) |
| 602 | return; | 593 | return; |
| 603 | memset(pwr, 0, sizeof(struct power_event)); | ||
| 604 | 594 | ||
| 605 | pwr->state = cpus_pstate_state[cpu]; | 595 | pwr->state = cpus_pstate_state[cpu]; |
| 606 | pwr->start_time = cpus_pstate_start_times[cpu]; | 596 | pwr->start_time = cpus_pstate_start_times[cpu]; |
| @@ -830,11 +820,9 @@ static void draw_process_bars(void) | |||
| 830 | 820 | ||
| 831 | static void add_process_filter(const char *string) | 821 | static void add_process_filter(const char *string) |
| 832 | { | 822 | { |
| 833 | struct process_filter *filt; | 823 | int pid = strtoull(string, NULL, 10); |
| 834 | int pid; | 824 | struct process_filter *filt = malloc(sizeof(*filt)); |
| 835 | 825 | ||
| 836 | pid = strtoull(string, NULL, 10); | ||
| 837 | filt = malloc(sizeof(struct process_filter)); | ||
| 838 | if (!filt) | 826 | if (!filt) |
| 839 | return; | 827 | return; |
| 840 | 828 | ||
| @@ -1081,7 +1069,8 @@ static int __cmd_record(int argc, const char **argv) | |||
| 1081 | } | 1069 | } |
| 1082 | 1070 | ||
| 1083 | static int | 1071 | static int |
| 1084 | parse_process(const struct option *opt __used, const char *arg, int __used unset) | 1072 | parse_process(const struct option *opt __maybe_unused, const char *arg, |
| 1073 | int __maybe_unused unset) | ||
| 1085 | { | 1074 | { |
| 1086 | if (arg) | 1075 | if (arg) |
| 1087 | add_process_filter(arg); | 1076 | add_process_filter(arg); |
| @@ -1106,7 +1095,8 @@ static const struct option options[] = { | |||
| 1106 | }; | 1095 | }; |
| 1107 | 1096 | ||
| 1108 | 1097 | ||
| 1109 | int cmd_timechart(int argc, const char **argv, const char *prefix __used) | 1098 | int cmd_timechart(int argc, const char **argv, |
| 1099 | const char *prefix __maybe_unused) | ||
| 1110 | { | 1100 | { |
| 1111 | argc = parse_options(argc, argv, options, timechart_usage, | 1101 | argc = parse_options(argc, argv, options, timechart_usage, |
| 1112 | PARSE_OPT_STOP_AT_NON_OPTION); | 1102 | PARSE_OPT_STOP_AT_NON_OPTION); |
