GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / tools / perf / builtin-timechart.c
blob53dc047c8a3b180f5c5c13edcbe92c4ddd5af9dc
1 /*
2 * builtin-timechart.c - make an svg timechart of system activity
4 * (C) Copyright 2009 Intel Corporation
6 * Authors:
7 * Arjan van de Ven <arjan@linux.intel.com>
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.
15 #include "builtin.h"
17 #include "util/util.h"
19 #include "util/color.h"
20 #include <linux/list.h>
21 #include "util/cache.h"
22 #include <linux/rbtree.h>
23 #include "util/symbol.h"
24 #include "util/callchain.h"
25 #include "util/strlist.h"
27 #include "perf.h"
28 #include "util/header.h"
29 #include "util/parse-options.h"
30 #include "util/parse-events.h"
31 #include "util/event.h"
32 #include "util/session.h"
33 #include "util/svghelper.h"
35 static char const *input_name = "perf.data";
36 static char const *output_name = "output.svg";
38 static unsigned int numcpus;
39 static u64 min_freq; /* Lowest CPU frequency seen */
40 static u64 max_freq; /* Highest CPU frequency seen */
41 static u64 turbo_frequency;
43 static u64 first_time, last_time;
45 static bool power_only;
48 struct per_pid;
49 struct per_pidcomm;
51 struct cpu_sample;
52 struct power_event;
53 struct wake_event;
55 struct sample_wrapper;
58 * Datastructure layout:
59 * We keep an list of "pid"s, matching the kernels notion of a task struct.
60 * Each "pid" entry, has a list of "comm"s.
61 * this is because we want to track different programs different, while
62 * exec will reuse the original pid (by design).
63 * Each comm has a list of samples that will be used to draw
64 * final graph.
67 struct per_pid {
68 struct per_pid *next;
70 int pid;
71 int ppid;
73 u64 start_time;
74 u64 end_time;
75 u64 total_time;
76 int display;
78 struct per_pidcomm *all;
79 struct per_pidcomm *current;
83 struct per_pidcomm {
84 struct per_pidcomm *next;
86 u64 start_time;
87 u64 end_time;
88 u64 total_time;
90 int Y;
91 int display;
93 long state;
94 u64 state_since;
96 char *comm;
98 struct cpu_sample *samples;
101 struct sample_wrapper {
102 struct sample_wrapper *next;
104 u64 timestamp;
105 unsigned char data[0];
108 #define TYPE_NONE 0
109 #define TYPE_RUNNING 1
110 #define TYPE_WAITING 2
111 #define TYPE_BLOCKED 3
113 struct cpu_sample {
114 struct cpu_sample *next;
116 u64 start_time;
117 u64 end_time;
118 int type;
119 int cpu;
122 static struct per_pid *all_data;
124 #define CSTATE 1
125 #define PSTATE 2
127 struct power_event {
128 struct power_event *next;
129 int type;
130 int state;
131 u64 start_time;
132 u64 end_time;
133 int cpu;
136 struct wake_event {
137 struct wake_event *next;
138 int waker;
139 int wakee;
140 u64 time;
143 static struct power_event *power_events;
144 static struct wake_event *wake_events;
146 struct process_filter;
147 struct process_filter {
148 char *name;
149 int pid;
150 struct process_filter *next;
153 static struct process_filter *process_filter;
156 static struct per_pid *find_create_pid(int pid)
158 struct per_pid *cursor = all_data;
160 while (cursor) {
161 if (cursor->pid == pid)
162 return cursor;
163 cursor = cursor->next;
165 cursor = malloc(sizeof(struct per_pid));
166 assert(cursor != NULL);
167 memset(cursor, 0, sizeof(struct per_pid));
168 cursor->pid = pid;
169 cursor->next = all_data;
170 all_data = cursor;
171 return cursor;
174 static void pid_set_comm(int pid, char *comm)
176 struct per_pid *p;
177 struct per_pidcomm *c;
178 p = find_create_pid(pid);
179 c = p->all;
180 while (c) {
181 if (c->comm && strcmp(c->comm, comm) == 0) {
182 p->current = c;
183 return;
185 if (!c->comm) {
186 c->comm = strdup(comm);
187 p->current = c;
188 return;
190 c = c->next;
192 c = malloc(sizeof(struct per_pidcomm));
193 assert(c != NULL);
194 memset(c, 0, sizeof(struct per_pidcomm));
195 c->comm = strdup(comm);
196 p->current = c;
197 c->next = p->all;
198 p->all = c;
201 static void pid_fork(int pid, int ppid, u64 timestamp)
203 struct per_pid *p, *pp;
204 p = find_create_pid(pid);
205 pp = find_create_pid(ppid);
206 p->ppid = ppid;
207 if (pp->current && pp->current->comm && !p->current)
208 pid_set_comm(pid, pp->current->comm);
210 p->start_time = timestamp;
211 if (p->current) {
212 p->current->start_time = timestamp;
213 p->current->state_since = timestamp;
217 static void pid_exit(int pid, u64 timestamp)
219 struct per_pid *p;
220 p = find_create_pid(pid);
221 p->end_time = timestamp;
222 if (p->current)
223 p->current->end_time = timestamp;
226 static void
227 pid_put_sample(int pid, int type, unsigned int cpu, u64 start, u64 end)
229 struct per_pid *p;
230 struct per_pidcomm *c;
231 struct cpu_sample *sample;
233 p = find_create_pid(pid);
234 c = p->current;
235 if (!c) {
236 c = malloc(sizeof(struct per_pidcomm));
237 assert(c != NULL);
238 memset(c, 0, sizeof(struct per_pidcomm));
239 p->current = c;
240 c->next = p->all;
241 p->all = c;
244 sample = malloc(sizeof(struct cpu_sample));
245 assert(sample != NULL);
246 memset(sample, 0, sizeof(struct cpu_sample));
247 sample->start_time = start;
248 sample->end_time = end;
249 sample->type = type;
250 sample->next = c->samples;
251 sample->cpu = cpu;
252 c->samples = sample;
254 if (sample->type == TYPE_RUNNING && end > start && start > 0) {
255 c->total_time += (end-start);
256 p->total_time += (end-start);
259 if (c->start_time == 0 || c->start_time > start)
260 c->start_time = start;
261 if (p->start_time == 0 || p->start_time > start)
262 p->start_time = start;
264 if (cpu > numcpus)
265 numcpus = cpu;
268 #define MAX_CPUS 4096
270 static u64 cpus_cstate_start_times[MAX_CPUS];
271 static int cpus_cstate_state[MAX_CPUS];
272 static u64 cpus_pstate_start_times[MAX_CPUS];
273 static u64 cpus_pstate_state[MAX_CPUS];
275 static int process_comm_event(event_t *event, struct perf_session *session __used)
277 pid_set_comm(event->comm.tid, event->comm.comm);
278 return 0;
281 static int process_fork_event(event_t *event, struct perf_session *session __used)
283 pid_fork(event->fork.pid, event->fork.ppid, event->fork.time);
284 return 0;
287 static int process_exit_event(event_t *event, struct perf_session *session __used)
289 pid_exit(event->fork.pid, event->fork.time);
290 return 0;
293 struct trace_entry {
294 unsigned short type;
295 unsigned char flags;
296 unsigned char preempt_count;
297 int pid;
298 int lock_depth;
301 struct power_entry {
302 struct trace_entry te;
303 u64 type;
304 u64 value;
305 u64 cpu_id;
308 #define TASK_COMM_LEN 16
309 struct wakeup_entry {
310 struct trace_entry te;
311 char comm[TASK_COMM_LEN];
312 int pid;
313 int prio;
314 int success;
318 * trace_flag_type is an enumeration that holds different
319 * states when a trace occurs. These are:
320 * IRQS_OFF - interrupts were disabled
321 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
322 * NEED_RESCED - reschedule is requested
323 * HARDIRQ - inside an interrupt handler
324 * SOFTIRQ - inside a softirq handler
326 enum trace_flag_type {
327 TRACE_FLAG_IRQS_OFF = 0x01,
328 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
329 TRACE_FLAG_NEED_RESCHED = 0x04,
330 TRACE_FLAG_HARDIRQ = 0x08,
331 TRACE_FLAG_SOFTIRQ = 0x10,
336 struct sched_switch {
337 struct trace_entry te;
338 char prev_comm[TASK_COMM_LEN];
339 int prev_pid;
340 int prev_prio;
341 long prev_state; /* Arjan weeps. */
342 char next_comm[TASK_COMM_LEN];
343 int next_pid;
344 int next_prio;
347 static void c_state_start(int cpu, u64 timestamp, int state)
349 cpus_cstate_start_times[cpu] = timestamp;
350 cpus_cstate_state[cpu] = state;
353 static void c_state_end(int cpu, u64 timestamp)
355 struct power_event *pwr;
356 pwr = malloc(sizeof(struct power_event));
357 if (!pwr)
358 return;
359 memset(pwr, 0, sizeof(struct power_event));
361 pwr->state = cpus_cstate_state[cpu];
362 pwr->start_time = cpus_cstate_start_times[cpu];
363 pwr->end_time = timestamp;
364 pwr->cpu = cpu;
365 pwr->type = CSTATE;
366 pwr->next = power_events;
368 power_events = pwr;
371 static void p_state_change(int cpu, u64 timestamp, u64 new_freq)
373 struct power_event *pwr;
374 pwr = malloc(sizeof(struct power_event));
376 if (new_freq > 8000000) /* detect invalid data */
377 return;
379 if (!pwr)
380 return;
381 memset(pwr, 0, sizeof(struct power_event));
383 pwr->state = cpus_pstate_state[cpu];
384 pwr->start_time = cpus_pstate_start_times[cpu];
385 pwr->end_time = timestamp;
386 pwr->cpu = cpu;
387 pwr->type = PSTATE;
388 pwr->next = power_events;
390 if (!pwr->start_time)
391 pwr->start_time = first_time;
393 power_events = pwr;
395 cpus_pstate_state[cpu] = new_freq;
396 cpus_pstate_start_times[cpu] = timestamp;
398 if ((u64)new_freq > max_freq)
399 max_freq = new_freq;
401 if (new_freq < min_freq || min_freq == 0)
402 min_freq = new_freq;
404 if (new_freq == max_freq - 1000)
405 turbo_frequency = max_freq;
408 static void
409 sched_wakeup(int cpu, u64 timestamp, int pid, struct trace_entry *te)
411 struct wake_event *we;
412 struct per_pid *p;
413 struct wakeup_entry *wake = (void *)te;
415 we = malloc(sizeof(struct wake_event));
416 if (!we)
417 return;
419 memset(we, 0, sizeof(struct wake_event));
420 we->time = timestamp;
421 we->waker = pid;
423 if ((te->flags & TRACE_FLAG_HARDIRQ) || (te->flags & TRACE_FLAG_SOFTIRQ))
424 we->waker = -1;
426 we->wakee = wake->pid;
427 we->next = wake_events;
428 wake_events = we;
429 p = find_create_pid(we->wakee);
431 if (p && p->current && p->current->state == TYPE_NONE) {
432 p->current->state_since = timestamp;
433 p->current->state = TYPE_WAITING;
435 if (p && p->current && p->current->state == TYPE_BLOCKED) {
436 pid_put_sample(p->pid, p->current->state, cpu, p->current->state_since, timestamp);
437 p->current->state_since = timestamp;
438 p->current->state = TYPE_WAITING;
442 static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)
444 struct per_pid *p = NULL, *prev_p;
445 struct sched_switch *sw = (void *)te;
448 prev_p = find_create_pid(sw->prev_pid);
450 p = find_create_pid(sw->next_pid);
452 if (prev_p->current && prev_p->current->state != TYPE_NONE)
453 pid_put_sample(sw->prev_pid, TYPE_RUNNING, cpu, prev_p->current->state_since, timestamp);
454 if (p && p->current) {
455 if (p->current->state != TYPE_NONE)
456 pid_put_sample(sw->next_pid, p->current->state, cpu, p->current->state_since, timestamp);
458 p->current->state_since = timestamp;
459 p->current->state = TYPE_RUNNING;
462 if (prev_p->current) {
463 prev_p->current->state = TYPE_NONE;
464 prev_p->current->state_since = timestamp;
465 if (sw->prev_state & 2)
466 prev_p->current->state = TYPE_BLOCKED;
467 if (sw->prev_state == 0)
468 prev_p->current->state = TYPE_WAITING;
473 static int process_sample_event(event_t *event, struct perf_session *session)
475 struct sample_data data;
476 struct trace_entry *te;
478 memset(&data, 0, sizeof(data));
480 event__parse_sample(event, session->sample_type, &data);
482 if (session->sample_type & PERF_SAMPLE_TIME) {
483 if (!first_time || first_time > data.time)
484 first_time = data.time;
485 if (last_time < data.time)
486 last_time = data.time;
489 te = (void *)data.raw_data;
490 if (session->sample_type & PERF_SAMPLE_RAW && data.raw_size > 0) {
491 char *event_str;
492 struct power_entry *pe;
494 pe = (void *)te;
496 event_str = perf_header__find_event(te->type);
498 if (!event_str)
499 return 0;
501 if (strcmp(event_str, "power:power_start") == 0)
502 c_state_start(pe->cpu_id, data.time, pe->value);
504 if (strcmp(event_str, "power:power_end") == 0)
505 c_state_end(pe->cpu_id, data.time);
507 if (strcmp(event_str, "power:power_frequency") == 0)
508 p_state_change(pe->cpu_id, data.time, pe->value);
510 if (strcmp(event_str, "sched:sched_wakeup") == 0)
511 sched_wakeup(data.cpu, data.time, data.pid, te);
513 if (strcmp(event_str, "sched:sched_switch") == 0)
514 sched_switch(data.cpu, data.time, te);
516 return 0;
520 * After the last sample we need to wrap up the current C/P state
521 * and close out each CPU for these.
523 static void end_sample_processing(void)
525 u64 cpu;
526 struct power_event *pwr;
528 for (cpu = 0; cpu <= numcpus; cpu++) {
529 pwr = malloc(sizeof(struct power_event));
530 if (!pwr)
531 return;
532 memset(pwr, 0, sizeof(struct power_event));
534 /* C state */
535 /* P state */
537 pwr = malloc(sizeof(struct power_event));
538 if (!pwr)
539 return;
540 memset(pwr, 0, sizeof(struct power_event));
542 pwr->state = cpus_pstate_state[cpu];
543 pwr->start_time = cpus_pstate_start_times[cpu];
544 pwr->end_time = last_time;
545 pwr->cpu = cpu;
546 pwr->type = PSTATE;
547 pwr->next = power_events;
549 if (!pwr->start_time)
550 pwr->start_time = first_time;
551 if (!pwr->state)
552 pwr->state = min_freq;
553 power_events = pwr;
558 * Sort the pid datastructure
560 static void sort_pids(void)
562 struct per_pid *new_list, *p, *cursor, *prev;
563 /* sort by ppid first, then by pid, lowest to highest */
565 new_list = NULL;
567 while (all_data) {
568 p = all_data;
569 all_data = p->next;
570 p->next = NULL;
572 if (new_list == NULL) {
573 new_list = p;
574 p->next = NULL;
575 continue;
577 prev = NULL;
578 cursor = new_list;
579 while (cursor) {
580 if (cursor->ppid > p->ppid ||
581 (cursor->ppid == p->ppid && cursor->pid > p->pid)) {
582 /* must insert before */
583 if (prev) {
584 p->next = prev->next;
585 prev->next = p;
586 cursor = NULL;
587 continue;
588 } else {
589 p->next = new_list;
590 new_list = p;
591 cursor = NULL;
592 continue;
596 prev = cursor;
597 cursor = cursor->next;
598 if (!cursor)
599 prev->next = p;
602 all_data = new_list;
606 static void draw_c_p_states(void)
608 struct power_event *pwr;
609 pwr = power_events;
612 * two pass drawing so that the P state bars are on top of the C state blocks
614 while (pwr) {
615 if (pwr->type == CSTATE)
616 svg_cstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state);
617 pwr = pwr->next;
620 pwr = power_events;
621 while (pwr) {
622 if (pwr->type == PSTATE) {
623 if (!pwr->state)
624 pwr->state = min_freq;
625 svg_pstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state);
627 pwr = pwr->next;
631 static void draw_wakeups(void)
633 struct wake_event *we;
634 struct per_pid *p;
635 struct per_pidcomm *c;
637 we = wake_events;
638 while (we) {
639 int from = 0, to = 0;
640 char *task_from = NULL, *task_to = NULL;
642 /* locate the column of the waker and wakee */
643 p = all_data;
644 while (p) {
645 if (p->pid == we->waker || p->pid == we->wakee) {
646 c = p->all;
647 while (c) {
648 if (c->Y && c->start_time <= we->time && c->end_time >= we->time) {
649 if (p->pid == we->waker && !from) {
650 from = c->Y;
651 task_from = strdup(c->comm);
653 if (p->pid == we->wakee && !to) {
654 to = c->Y;
655 task_to = strdup(c->comm);
658 c = c->next;
660 c = p->all;
661 while (c) {
662 if (p->pid == we->waker && !from) {
663 from = c->Y;
664 task_from = strdup(c->comm);
666 if (p->pid == we->wakee && !to) {
667 to = c->Y;
668 task_to = strdup(c->comm);
670 c = c->next;
673 p = p->next;
676 if (!task_from) {
677 task_from = malloc(40);
678 sprintf(task_from, "[%i]", we->waker);
680 if (!task_to) {
681 task_to = malloc(40);
682 sprintf(task_to, "[%i]", we->wakee);
685 if (we->waker == -1)
686 svg_interrupt(we->time, to);
687 else if (from && to && abs(from - to) == 1)
688 svg_wakeline(we->time, from, to);
689 else
690 svg_partial_wakeline(we->time, from, task_from, to, task_to);
691 we = we->next;
693 free(task_from);
694 free(task_to);
698 static void draw_cpu_usage(void)
700 struct per_pid *p;
701 struct per_pidcomm *c;
702 struct cpu_sample *sample;
703 p = all_data;
704 while (p) {
705 c = p->all;
706 while (c) {
707 sample = c->samples;
708 while (sample) {
709 if (sample->type == TYPE_RUNNING)
710 svg_process(sample->cpu, sample->start_time, sample->end_time, "sample", c->comm);
712 sample = sample->next;
714 c = c->next;
716 p = p->next;
720 static void draw_process_bars(void)
722 struct per_pid *p;
723 struct per_pidcomm *c;
724 struct cpu_sample *sample;
725 int Y = 0;
727 Y = 2 * numcpus + 2;
729 p = all_data;
730 while (p) {
731 c = p->all;
732 while (c) {
733 if (!c->display) {
734 c->Y = 0;
735 c = c->next;
736 continue;
739 svg_box(Y, c->start_time, c->end_time, "process");
740 sample = c->samples;
741 while (sample) {
742 if (sample->type == TYPE_RUNNING)
743 svg_sample(Y, sample->cpu, sample->start_time, sample->end_time);
744 if (sample->type == TYPE_BLOCKED)
745 svg_box(Y, sample->start_time, sample->end_time, "blocked");
746 if (sample->type == TYPE_WAITING)
747 svg_waiting(Y, sample->start_time, sample->end_time);
748 sample = sample->next;
751 if (c->comm) {
752 char comm[256];
753 if (c->total_time > 5000000000) /* 5 seconds */
754 sprintf(comm, "%s:%i (%2.2fs)", c->comm, p->pid, c->total_time / 1000000000.0);
755 else
756 sprintf(comm, "%s:%i (%3.1fms)", c->comm, p->pid, c->total_time / 1000000.0);
758 svg_text(Y, c->start_time, comm);
760 c->Y = Y;
761 Y++;
762 c = c->next;
764 p = p->next;
768 static void add_process_filter(const char *string)
770 struct process_filter *filt;
771 int pid;
773 pid = strtoull(string, NULL, 10);
774 filt = malloc(sizeof(struct process_filter));
775 if (!filt)
776 return;
778 filt->name = strdup(string);
779 filt->pid = pid;
780 filt->next = process_filter;
782 process_filter = filt;
785 static int passes_filter(struct per_pid *p, struct per_pidcomm *c)
787 struct process_filter *filt;
788 if (!process_filter)
789 return 1;
791 filt = process_filter;
792 while (filt) {
793 if (filt->pid && p->pid == filt->pid)
794 return 1;
795 if (strcmp(filt->name, c->comm) == 0)
796 return 1;
797 filt = filt->next;
799 return 0;
802 static int determine_display_tasks_filtered(void)
804 struct per_pid *p;
805 struct per_pidcomm *c;
806 int count = 0;
808 p = all_data;
809 while (p) {
810 p->display = 0;
811 if (p->start_time == 1)
812 p->start_time = first_time;
814 /* no exit marker, task kept running to the end */
815 if (p->end_time == 0)
816 p->end_time = last_time;
818 c = p->all;
820 while (c) {
821 c->display = 0;
823 if (c->start_time == 1)
824 c->start_time = first_time;
826 if (passes_filter(p, c)) {
827 c->display = 1;
828 p->display = 1;
829 count++;
832 if (c->end_time == 0)
833 c->end_time = last_time;
835 c = c->next;
837 p = p->next;
839 return count;
842 static int determine_display_tasks(u64 threshold)
844 struct per_pid *p;
845 struct per_pidcomm *c;
846 int count = 0;
848 if (process_filter)
849 return determine_display_tasks_filtered();
851 p = all_data;
852 while (p) {
853 p->display = 0;
854 if (p->start_time == 1)
855 p->start_time = first_time;
857 /* no exit marker, task kept running to the end */
858 if (p->end_time == 0)
859 p->end_time = last_time;
860 if (p->total_time >= threshold && !power_only)
861 p->display = 1;
863 c = p->all;
865 while (c) {
866 c->display = 0;
868 if (c->start_time == 1)
869 c->start_time = first_time;
871 if (c->total_time >= threshold && !power_only) {
872 c->display = 1;
873 count++;
876 if (c->end_time == 0)
877 c->end_time = last_time;
879 c = c->next;
881 p = p->next;
883 return count;
888 #define TIME_THRESH 10000000
890 static void write_svg_file(const char *filename)
892 u64 i;
893 int count;
895 numcpus++;
898 count = determine_display_tasks(TIME_THRESH);
900 /* We'd like to show at least 15 tasks; be less picky if we have fewer */
901 if (count < 15)
902 count = determine_display_tasks(TIME_THRESH / 10);
904 open_svg(filename, numcpus, count, first_time, last_time);
906 svg_time_grid();
907 svg_legenda();
909 for (i = 0; i < numcpus; i++)
910 svg_cpu_box(i, max_freq, turbo_frequency);
912 draw_cpu_usage();
913 draw_process_bars();
914 draw_c_p_states();
915 draw_wakeups();
917 svg_close();
920 static struct perf_event_ops event_ops = {
921 .comm = process_comm_event,
922 .fork = process_fork_event,
923 .exit = process_exit_event,
924 .sample = process_sample_event,
925 .ordered_samples = true,
928 static int __cmd_timechart(void)
930 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
931 int ret = -EINVAL;
933 if (session == NULL)
934 return -ENOMEM;
936 if (!perf_session__has_traces(session, "timechart record"))
937 goto out_delete;
939 ret = perf_session__process_events(session, &event_ops);
940 if (ret)
941 goto out_delete;
943 end_sample_processing();
945 sort_pids();
947 write_svg_file(output_name);
949 pr_info("Written %2.1f seconds of trace to %s.\n",
950 (last_time - first_time) / 1000000000.0, output_name);
951 out_delete:
952 perf_session__delete(session);
953 return ret;
956 static const char * const timechart_usage[] = {
957 "perf timechart [<options>] {record}",
958 NULL
961 static const char *record_args[] = {
962 "record",
963 "-a",
964 "-R",
965 "-f",
966 "-c", "1",
967 "-e", "power:power_start",
968 "-e", "power:power_end",
969 "-e", "power:power_frequency",
970 "-e", "sched:sched_wakeup",
971 "-e", "sched:sched_switch",
974 static int __cmd_record(int argc, const char **argv)
976 unsigned int rec_argc, i, j;
977 const char **rec_argv;
979 rec_argc = ARRAY_SIZE(record_args) + argc - 1;
980 rec_argv = calloc(rec_argc + 1, sizeof(char *));
982 for (i = 0; i < ARRAY_SIZE(record_args); i++)
983 rec_argv[i] = strdup(record_args[i]);
985 for (j = 1; j < (unsigned int)argc; j++, i++)
986 rec_argv[i] = argv[j];
988 return cmd_record(i, rec_argv, NULL);
991 static int
992 parse_process(const struct option *opt __used, const char *arg, int __used unset)
994 if (arg)
995 add_process_filter(arg);
996 return 0;
999 static const struct option options[] = {
1000 OPT_STRING('i', "input", &input_name, "file",
1001 "input file name"),
1002 OPT_STRING('o', "output", &output_name, "file",
1003 "output file name"),
1004 OPT_INTEGER('w', "width", &svg_page_width,
1005 "page width"),
1006 OPT_BOOLEAN('P', "power-only", &power_only,
1007 "output power data only"),
1008 OPT_CALLBACK('p', "process", NULL, "process",
1009 "process selector. Pass a pid or process name.",
1010 parse_process),
1011 OPT_END()
1015 int cmd_timechart(int argc, const char **argv, const char *prefix __used)
1017 argc = parse_options(argc, argv, options, timechart_usage,
1018 PARSE_OPT_STOP_AT_NON_OPTION);
1020 symbol__init();
1022 if (argc && !strncmp(argv[0], "rec", 3))
1023 return __cmd_record(argc, argv);
1024 else if (argc)
1025 usage_with_options(timechart_usage, options);
1027 setup_pager();
1029 return __cmd_timechart();