5 #include "util/evlist.h"
6 #include "util/cache.h"
7 #include "util/evsel.h"
8 #include "util/symbol.h"
9 #include "util/thread.h"
10 #include "util/header.h"
11 #include "util/session.h"
12 #include "util/tool.h"
14 #include "util/parse-options.h"
15 #include "util/trace-event.h"
17 #include "util/debug.h"
19 #include <sys/prctl.h>
21 #include <semaphore.h>
25 static const char *input_name
;
27 static char default_sort_order
[] = "avg, max, switch, runtime";
28 static const char *sort_order
= default_sort_order
;
30 static int profile_cpu
= -1;
32 #define PR_SET_NAME 15 /* Set process name */
35 static u64 run_measurement_overhead
;
36 static u64 sleep_measurement_overhead
;
43 static unsigned long nr_tasks
;
52 unsigned long nr_events
;
53 unsigned long curr_event
;
54 struct sched_atom
**atoms
;
65 enum sched_event_type
{
69 SCHED_EVENT_MIGRATION
,
73 enum sched_event_type type
;
79 struct task_desc
*wakee
;
82 static struct task_desc
*pid_to_task
[MAX_PID
];
84 static struct task_desc
**tasks
;
86 static pthread_mutex_t start_work_mutex
= PTHREAD_MUTEX_INITIALIZER
;
87 static u64 start_time
;
89 static pthread_mutex_t work_done_wait_mutex
= PTHREAD_MUTEX_INITIALIZER
;
91 static unsigned long nr_run_events
;
92 static unsigned long nr_sleep_events
;
93 static unsigned long nr_wakeup_events
;
95 static unsigned long nr_sleep_corrections
;
96 static unsigned long nr_run_events_optimized
;
98 static unsigned long targetless_wakeups
;
99 static unsigned long multitarget_wakeups
;
101 static u64 cpu_usage
;
102 static u64 runavg_cpu_usage
;
103 static u64 parent_cpu_usage
;
104 static u64 runavg_parent_cpu_usage
;
106 static unsigned long nr_runs
;
107 static u64 sum_runtime
;
108 static u64 sum_fluct
;
111 static unsigned int replay_repeat
= 10;
112 static unsigned long nr_timestamps
;
113 static unsigned long nr_unordered_timestamps
;
114 static unsigned long nr_state_machine_bugs
;
115 static unsigned long nr_context_switch_bugs
;
116 static unsigned long nr_events
;
117 static unsigned long nr_lost_chunks
;
118 static unsigned long nr_lost_events
;
120 #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
130 struct list_head list
;
131 enum thread_state state
;
139 struct list_head work_list
;
140 struct thread
*thread
;
149 typedef int (*sort_fn_t
)(struct work_atoms
*, struct work_atoms
*);
151 static struct rb_root atom_root
, sorted_atom_root
;
153 static u64 all_runtime
;
154 static u64 all_count
;
157 static u64
get_nsecs(void)
161 clock_gettime(CLOCK_MONOTONIC
, &ts
);
163 return ts
.tv_sec
* 1000000000ULL + ts
.tv_nsec
;
166 static void burn_nsecs(u64 nsecs
)
168 u64 T0
= get_nsecs(), T1
;
172 } while (T1
+ run_measurement_overhead
< T0
+ nsecs
);
175 static void sleep_nsecs(u64 nsecs
)
179 ts
.tv_nsec
= nsecs
% 999999999;
180 ts
.tv_sec
= nsecs
/ 999999999;
182 nanosleep(&ts
, NULL
);
185 static void calibrate_run_measurement_overhead(void)
187 u64 T0
, T1
, delta
, min_delta
= 1000000000ULL;
190 for (i
= 0; i
< 10; i
++) {
195 min_delta
= min(min_delta
, delta
);
197 run_measurement_overhead
= min_delta
;
199 printf("run measurement overhead: %" PRIu64
" nsecs\n", min_delta
);
202 static void calibrate_sleep_measurement_overhead(void)
204 u64 T0
, T1
, delta
, min_delta
= 1000000000ULL;
207 for (i
= 0; i
< 10; i
++) {
212 min_delta
= min(min_delta
, delta
);
215 sleep_measurement_overhead
= min_delta
;
217 printf("sleep measurement overhead: %" PRIu64
" nsecs\n", min_delta
);
220 static struct sched_atom
*
221 get_new_event(struct task_desc
*task
, u64 timestamp
)
223 struct sched_atom
*event
= zalloc(sizeof(*event
));
224 unsigned long idx
= task
->nr_events
;
227 event
->timestamp
= timestamp
;
231 size
= sizeof(struct sched_atom
*) * task
->nr_events
;
232 task
->atoms
= realloc(task
->atoms
, size
);
233 BUG_ON(!task
->atoms
);
235 task
->atoms
[idx
] = event
;
240 static struct sched_atom
*last_event(struct task_desc
*task
)
242 if (!task
->nr_events
)
245 return task
->atoms
[task
->nr_events
- 1];
249 add_sched_event_run(struct task_desc
*task
, u64 timestamp
, u64 duration
)
251 struct sched_atom
*event
, *curr_event
= last_event(task
);
254 * optimize an existing RUN event by merging this one
257 if (curr_event
&& curr_event
->type
== SCHED_EVENT_RUN
) {
258 nr_run_events_optimized
++;
259 curr_event
->duration
+= duration
;
263 event
= get_new_event(task
, timestamp
);
265 event
->type
= SCHED_EVENT_RUN
;
266 event
->duration
= duration
;
272 add_sched_event_wakeup(struct task_desc
*task
, u64 timestamp
,
273 struct task_desc
*wakee
)
275 struct sched_atom
*event
, *wakee_event
;
277 event
= get_new_event(task
, timestamp
);
278 event
->type
= SCHED_EVENT_WAKEUP
;
279 event
->wakee
= wakee
;
281 wakee_event
= last_event(wakee
);
282 if (!wakee_event
|| wakee_event
->type
!= SCHED_EVENT_SLEEP
) {
283 targetless_wakeups
++;
286 if (wakee_event
->wait_sem
) {
287 multitarget_wakeups
++;
291 wakee_event
->wait_sem
= zalloc(sizeof(*wakee_event
->wait_sem
));
292 sem_init(wakee_event
->wait_sem
, 0, 0);
293 wakee_event
->specific_wait
= 1;
294 event
->wait_sem
= wakee_event
->wait_sem
;
300 add_sched_event_sleep(struct task_desc
*task
, u64 timestamp
,
301 u64 task_state __used
)
303 struct sched_atom
*event
= get_new_event(task
, timestamp
);
305 event
->type
= SCHED_EVENT_SLEEP
;
310 static struct task_desc
*register_pid(unsigned long pid
, const char *comm
)
312 struct task_desc
*task
;
314 BUG_ON(pid
>= MAX_PID
);
316 task
= pid_to_task
[pid
];
321 task
= zalloc(sizeof(*task
));
324 strcpy(task
->comm
, comm
);
326 * every task starts in sleeping state - this gets ignored
327 * if there's no wakeup pointing to this sleep state:
329 add_sched_event_sleep(task
, 0, 0);
331 pid_to_task
[pid
] = task
;
333 tasks
= realloc(tasks
, nr_tasks
*sizeof(struct task_task
*));
335 tasks
[task
->nr
] = task
;
338 printf("registered task #%ld, PID %ld (%s)\n", nr_tasks
, pid
, comm
);
344 static void print_task_traces(void)
346 struct task_desc
*task
;
349 for (i
= 0; i
< nr_tasks
; i
++) {
351 printf("task %6ld (%20s:%10ld), nr_events: %ld\n",
352 task
->nr
, task
->comm
, task
->pid
, task
->nr_events
);
356 static void add_cross_task_wakeups(void)
358 struct task_desc
*task1
, *task2
;
361 for (i
= 0; i
< nr_tasks
; i
++) {
367 add_sched_event_wakeup(task1
, 0, task2
);
372 process_sched_event(struct task_desc
*this_task __used
, struct sched_atom
*atom
)
376 switch (atom
->type
) {
377 case SCHED_EVENT_RUN
:
378 burn_nsecs(atom
->duration
);
380 case SCHED_EVENT_SLEEP
:
382 ret
= sem_wait(atom
->wait_sem
);
385 case SCHED_EVENT_WAKEUP
:
387 ret
= sem_post(atom
->wait_sem
);
390 case SCHED_EVENT_MIGRATION
:
397 static u64
get_cpu_usage_nsec_parent(void)
403 err
= getrusage(RUSAGE_SELF
, &ru
);
406 sum
= ru
.ru_utime
.tv_sec
*1e9
+ ru
.ru_utime
.tv_usec
*1e3
;
407 sum
+= ru
.ru_stime
.tv_sec
*1e9
+ ru
.ru_stime
.tv_usec
*1e3
;
412 static int self_open_counters(void)
414 struct perf_event_attr attr
;
417 memset(&attr
, 0, sizeof(attr
));
419 attr
.type
= PERF_TYPE_SOFTWARE
;
420 attr
.config
= PERF_COUNT_SW_TASK_CLOCK
;
422 fd
= sys_perf_event_open(&attr
, 0, -1, -1, 0);
425 die("Error: sys_perf_event_open() syscall returned"
426 "with %d (%s)\n", fd
, strerror(errno
));
430 static u64
get_cpu_usage_nsec_self(int fd
)
435 ret
= read(fd
, &runtime
, sizeof(runtime
));
436 BUG_ON(ret
!= sizeof(runtime
));
441 static void *thread_func(void *ctx
)
443 struct task_desc
*this_task
= ctx
;
444 u64 cpu_usage_0
, cpu_usage_1
;
445 unsigned long i
, ret
;
449 sprintf(comm2
, ":%s", this_task
->comm
);
450 prctl(PR_SET_NAME
, comm2
);
451 fd
= self_open_counters();
454 ret
= sem_post(&this_task
->ready_for_work
);
456 ret
= pthread_mutex_lock(&start_work_mutex
);
458 ret
= pthread_mutex_unlock(&start_work_mutex
);
461 cpu_usage_0
= get_cpu_usage_nsec_self(fd
);
463 for (i
= 0; i
< this_task
->nr_events
; i
++) {
464 this_task
->curr_event
= i
;
465 process_sched_event(this_task
, this_task
->atoms
[i
]);
468 cpu_usage_1
= get_cpu_usage_nsec_self(fd
);
469 this_task
->cpu_usage
= cpu_usage_1
- cpu_usage_0
;
470 ret
= sem_post(&this_task
->work_done_sem
);
473 ret
= pthread_mutex_lock(&work_done_wait_mutex
);
475 ret
= pthread_mutex_unlock(&work_done_wait_mutex
);
481 static void create_tasks(void)
483 struct task_desc
*task
;
488 err
= pthread_attr_init(&attr
);
490 err
= pthread_attr_setstacksize(&attr
,
491 (size_t) max(16 * 1024, PTHREAD_STACK_MIN
));
493 err
= pthread_mutex_lock(&start_work_mutex
);
495 err
= pthread_mutex_lock(&work_done_wait_mutex
);
497 for (i
= 0; i
< nr_tasks
; i
++) {
499 sem_init(&task
->sleep_sem
, 0, 0);
500 sem_init(&task
->ready_for_work
, 0, 0);
501 sem_init(&task
->work_done_sem
, 0, 0);
502 task
->curr_event
= 0;
503 err
= pthread_create(&task
->thread
, &attr
, thread_func
, task
);
508 static void wait_for_tasks(void)
510 u64 cpu_usage_0
, cpu_usage_1
;
511 struct task_desc
*task
;
512 unsigned long i
, ret
;
514 start_time
= get_nsecs();
516 pthread_mutex_unlock(&work_done_wait_mutex
);
518 for (i
= 0; i
< nr_tasks
; i
++) {
520 ret
= sem_wait(&task
->ready_for_work
);
522 sem_init(&task
->ready_for_work
, 0, 0);
524 ret
= pthread_mutex_lock(&work_done_wait_mutex
);
527 cpu_usage_0
= get_cpu_usage_nsec_parent();
529 pthread_mutex_unlock(&start_work_mutex
);
531 for (i
= 0; i
< nr_tasks
; i
++) {
533 ret
= sem_wait(&task
->work_done_sem
);
535 sem_init(&task
->work_done_sem
, 0, 0);
536 cpu_usage
+= task
->cpu_usage
;
540 cpu_usage_1
= get_cpu_usage_nsec_parent();
541 if (!runavg_cpu_usage
)
542 runavg_cpu_usage
= cpu_usage
;
543 runavg_cpu_usage
= (runavg_cpu_usage
*9 + cpu_usage
)/10;
545 parent_cpu_usage
= cpu_usage_1
- cpu_usage_0
;
546 if (!runavg_parent_cpu_usage
)
547 runavg_parent_cpu_usage
= parent_cpu_usage
;
548 runavg_parent_cpu_usage
= (runavg_parent_cpu_usage
*9 +
549 parent_cpu_usage
)/10;
551 ret
= pthread_mutex_lock(&start_work_mutex
);
554 for (i
= 0; i
< nr_tasks
; i
++) {
556 sem_init(&task
->sleep_sem
, 0, 0);
557 task
->curr_event
= 0;
561 static void run_one_test(void)
563 u64 T0
, T1
, delta
, avg_delta
, fluct
;
570 sum_runtime
+= delta
;
573 avg_delta
= sum_runtime
/ nr_runs
;
574 if (delta
< avg_delta
)
575 fluct
= avg_delta
- delta
;
577 fluct
= delta
- avg_delta
;
581 run_avg
= (run_avg
*9 + delta
)/10;
583 printf("#%-3ld: %0.3f, ",
584 nr_runs
, (double)delta
/1000000.0);
586 printf("ravg: %0.2f, ",
587 (double)run_avg
/1e6
);
589 printf("cpu: %0.2f / %0.2f",
590 (double)cpu_usage
/1e6
, (double)runavg_cpu_usage
/1e6
);
594 * rusage statistics done by the parent, these are less
595 * accurate than the sum_exec_runtime based statistics:
597 printf(" [%0.2f / %0.2f]",
598 (double)parent_cpu_usage
/1e6
,
599 (double)runavg_parent_cpu_usage
/1e6
);
604 if (nr_sleep_corrections
)
605 printf(" (%ld sleep corrections)\n", nr_sleep_corrections
);
606 nr_sleep_corrections
= 0;
609 static void test_calibrations(void)
617 printf("the run test took %" PRIu64
" nsecs\n", T1
- T0
);
623 printf("the sleep test took %" PRIu64
" nsecs\n", T1
- T0
);
626 #define FILL_FIELD(ptr, field, event, data) \
627 ptr.field = (typeof(ptr.field)) raw_field_value(event, #field, data)
629 #define FILL_ARRAY(ptr, array, event, data) \
631 void *__array = raw_field_ptr(event, #array, data); \
632 memcpy(ptr.array, __array, sizeof(ptr.array)); \
635 #define FILL_COMMON_FIELDS(ptr, event, data) \
637 FILL_FIELD(ptr, common_type, event, data); \
638 FILL_FIELD(ptr, common_flags, event, data); \
639 FILL_FIELD(ptr, common_preempt_count, event, data); \
640 FILL_FIELD(ptr, common_pid, event, data); \
641 FILL_FIELD(ptr, common_tgid, event, data); \
646 struct trace_switch_event
{
651 u8 common_preempt_count
;
664 struct trace_runtime_event
{
669 u8 common_preempt_count
;
679 struct trace_wakeup_event
{
684 u8 common_preempt_count
;
696 struct trace_fork_event
{
701 u8 common_preempt_count
;
705 char parent_comm
[16];
711 struct trace_migrate_task_event
{
716 u8 common_preempt_count
;
727 struct trace_sched_handler
{
728 void (*switch_event
)(struct trace_switch_event
*,
733 struct thread
*thread
);
735 void (*runtime_event
)(struct trace_runtime_event
*,
740 struct thread
*thread
);
742 void (*wakeup_event
)(struct trace_wakeup_event
*,
747 struct thread
*thread
);
749 void (*fork_event
)(struct trace_fork_event
*,
753 struct thread
*thread
);
755 void (*migrate_task_event
)(struct trace_migrate_task_event
*,
756 struct machine
*machine
,
760 struct thread
*thread
);
765 replay_wakeup_event(struct trace_wakeup_event
*wakeup_event
,
766 struct machine
*machine __used
,
769 u64 timestamp __used
,
770 struct thread
*thread __used
)
772 struct task_desc
*waker
, *wakee
;
775 printf("sched_wakeup event %p\n", event
);
777 printf(" ... pid %d woke up %s/%d\n",
778 wakeup_event
->common_pid
,
783 waker
= register_pid(wakeup_event
->common_pid
, "<unknown>");
784 wakee
= register_pid(wakeup_event
->pid
, wakeup_event
->comm
);
786 add_sched_event_wakeup(waker
, timestamp
, wakee
);
789 static u64 cpu_last_switched
[MAX_CPUS
];
792 replay_switch_event(struct trace_switch_event
*switch_event
,
793 struct machine
*machine __used
,
797 struct thread
*thread __used
)
799 struct task_desc
*prev
, __used
*next
;
804 printf("sched_switch event %p\n", event
);
806 if (cpu
>= MAX_CPUS
|| cpu
< 0)
809 timestamp0
= cpu_last_switched
[cpu
];
811 delta
= timestamp
- timestamp0
;
816 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
819 printf(" ... switch from %s/%d to %s/%d [ran %" PRIu64
" nsecs]\n",
820 switch_event
->prev_comm
, switch_event
->prev_pid
,
821 switch_event
->next_comm
, switch_event
->next_pid
,
825 prev
= register_pid(switch_event
->prev_pid
, switch_event
->prev_comm
);
826 next
= register_pid(switch_event
->next_pid
, switch_event
->next_comm
);
828 cpu_last_switched
[cpu
] = timestamp
;
830 add_sched_event_run(prev
, timestamp
, delta
);
831 add_sched_event_sleep(prev
, timestamp
, switch_event
->prev_state
);
836 replay_fork_event(struct trace_fork_event
*fork_event
,
839 u64 timestamp __used
,
840 struct thread
*thread __used
)
843 printf("sched_fork event %p\n", event
);
844 printf("... parent: %s/%d\n", fork_event
->parent_comm
, fork_event
->parent_pid
);
845 printf("... child: %s/%d\n", fork_event
->child_comm
, fork_event
->child_pid
);
847 register_pid(fork_event
->parent_pid
, fork_event
->parent_comm
);
848 register_pid(fork_event
->child_pid
, fork_event
->child_comm
);
851 static struct trace_sched_handler replay_ops
= {
852 .wakeup_event
= replay_wakeup_event
,
853 .switch_event
= replay_switch_event
,
854 .fork_event
= replay_fork_event
,
857 struct sort_dimension
{
860 struct list_head list
;
863 static LIST_HEAD(cmp_pid
);
866 thread_lat_cmp(struct list_head
*list
, struct work_atoms
*l
, struct work_atoms
*r
)
868 struct sort_dimension
*sort
;
871 BUG_ON(list_empty(list
));
873 list_for_each_entry(sort
, list
, list
) {
874 ret
= sort
->cmp(l
, r
);
882 static struct work_atoms
*
883 thread_atoms_search(struct rb_root
*root
, struct thread
*thread
,
884 struct list_head
*sort_list
)
886 struct rb_node
*node
= root
->rb_node
;
887 struct work_atoms key
= { .thread
= thread
};
890 struct work_atoms
*atoms
;
893 atoms
= container_of(node
, struct work_atoms
, node
);
895 cmp
= thread_lat_cmp(sort_list
, &key
, atoms
);
897 node
= node
->rb_left
;
899 node
= node
->rb_right
;
901 BUG_ON(thread
!= atoms
->thread
);
909 __thread_latency_insert(struct rb_root
*root
, struct work_atoms
*data
,
910 struct list_head
*sort_list
)
912 struct rb_node
**new = &(root
->rb_node
), *parent
= NULL
;
915 struct work_atoms
*this;
918 this = container_of(*new, struct work_atoms
, node
);
921 cmp
= thread_lat_cmp(sort_list
, data
, this);
924 new = &((*new)->rb_left
);
926 new = &((*new)->rb_right
);
929 rb_link_node(&data
->node
, parent
, new);
930 rb_insert_color(&data
->node
, root
);
933 static void thread_atoms_insert(struct thread
*thread
)
935 struct work_atoms
*atoms
= zalloc(sizeof(*atoms
));
939 atoms
->thread
= thread
;
940 INIT_LIST_HEAD(&atoms
->work_list
);
941 __thread_latency_insert(&atom_root
, atoms
, &cmp_pid
);
945 latency_fork_event(struct trace_fork_event
*fork_event __used
,
946 struct event
*event __used
,
948 u64 timestamp __used
,
949 struct thread
*thread __used
)
951 /* should insert the newcomer */
955 static char sched_out_state(struct trace_switch_event
*switch_event
)
957 const char *str
= TASK_STATE_TO_CHAR_STR
;
959 return str
[switch_event
->prev_state
];
963 add_sched_out_event(struct work_atoms
*atoms
,
967 struct work_atom
*atom
= zalloc(sizeof(*atom
));
971 atom
->sched_out_time
= timestamp
;
973 if (run_state
== 'R') {
974 atom
->state
= THREAD_WAIT_CPU
;
975 atom
->wake_up_time
= atom
->sched_out_time
;
978 list_add_tail(&atom
->list
, &atoms
->work_list
);
982 add_runtime_event(struct work_atoms
*atoms
, u64 delta
, u64 timestamp __used
)
984 struct work_atom
*atom
;
986 BUG_ON(list_empty(&atoms
->work_list
));
988 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
990 atom
->runtime
+= delta
;
991 atoms
->total_runtime
+= delta
;
995 add_sched_in_event(struct work_atoms
*atoms
, u64 timestamp
)
997 struct work_atom
*atom
;
1000 if (list_empty(&atoms
->work_list
))
1003 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1005 if (atom
->state
!= THREAD_WAIT_CPU
)
1008 if (timestamp
< atom
->wake_up_time
) {
1009 atom
->state
= THREAD_IGNORE
;
1013 atom
->state
= THREAD_SCHED_IN
;
1014 atom
->sched_in_time
= timestamp
;
1016 delta
= atom
->sched_in_time
- atom
->wake_up_time
;
1017 atoms
->total_lat
+= delta
;
1018 if (delta
> atoms
->max_lat
) {
1019 atoms
->max_lat
= delta
;
1020 atoms
->max_lat_at
= timestamp
;
1026 latency_switch_event(struct trace_switch_event
*switch_event
,
1027 struct machine
*machine
,
1028 struct event
*event __used
,
1031 struct thread
*thread __used
)
1033 struct work_atoms
*out_events
, *in_events
;
1034 struct thread
*sched_out
, *sched_in
;
1038 BUG_ON(cpu
>= MAX_CPUS
|| cpu
< 0);
1040 timestamp0
= cpu_last_switched
[cpu
];
1041 cpu_last_switched
[cpu
] = timestamp
;
1043 delta
= timestamp
- timestamp0
;
1048 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
1051 sched_out
= machine__findnew_thread(machine
, switch_event
->prev_pid
);
1052 sched_in
= machine__findnew_thread(machine
, switch_event
->next_pid
);
1054 out_events
= thread_atoms_search(&atom_root
, sched_out
, &cmp_pid
);
1056 thread_atoms_insert(sched_out
);
1057 out_events
= thread_atoms_search(&atom_root
, sched_out
, &cmp_pid
);
1059 die("out-event: Internal tree error");
1061 add_sched_out_event(out_events
, sched_out_state(switch_event
), timestamp
);
1063 in_events
= thread_atoms_search(&atom_root
, sched_in
, &cmp_pid
);
1065 thread_atoms_insert(sched_in
);
1066 in_events
= thread_atoms_search(&atom_root
, sched_in
, &cmp_pid
);
1068 die("in-event: Internal tree error");
1070 * Take came in we have not heard about yet,
1071 * add in an initial atom in runnable state:
1073 add_sched_out_event(in_events
, 'R', timestamp
);
1075 add_sched_in_event(in_events
, timestamp
);
1079 latency_runtime_event(struct trace_runtime_event
*runtime_event
,
1080 struct machine
*machine
,
1081 struct event
*event __used
,
1084 struct thread
*this_thread __used
)
1086 struct thread
*thread
= machine__findnew_thread(machine
, runtime_event
->pid
);
1087 struct work_atoms
*atoms
= thread_atoms_search(&atom_root
, thread
, &cmp_pid
);
1089 BUG_ON(cpu
>= MAX_CPUS
|| cpu
< 0);
1091 thread_atoms_insert(thread
);
1092 atoms
= thread_atoms_search(&atom_root
, thread
, &cmp_pid
);
1094 die("in-event: Internal tree error");
1095 add_sched_out_event(atoms
, 'R', timestamp
);
1098 add_runtime_event(atoms
, runtime_event
->runtime
, timestamp
);
1102 latency_wakeup_event(struct trace_wakeup_event
*wakeup_event
,
1103 struct machine
*machine
,
1104 struct event
*__event __used
,
1107 struct thread
*thread __used
)
1109 struct work_atoms
*atoms
;
1110 struct work_atom
*atom
;
1111 struct thread
*wakee
;
1113 /* Note for later, it may be interesting to observe the failing cases */
1114 if (!wakeup_event
->success
)
1117 wakee
= machine__findnew_thread(machine
, wakeup_event
->pid
);
1118 atoms
= thread_atoms_search(&atom_root
, wakee
, &cmp_pid
);
1120 thread_atoms_insert(wakee
);
1121 atoms
= thread_atoms_search(&atom_root
, wakee
, &cmp_pid
);
1123 die("wakeup-event: Internal tree error");
1124 add_sched_out_event(atoms
, 'S', timestamp
);
1127 BUG_ON(list_empty(&atoms
->work_list
));
1129 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1132 * You WILL be missing events if you've recorded only
1133 * one CPU, or are only looking at only one, so don't
1134 * make useless noise.
1136 if (profile_cpu
== -1 && atom
->state
!= THREAD_SLEEPING
)
1137 nr_state_machine_bugs
++;
1140 if (atom
->sched_out_time
> timestamp
) {
1141 nr_unordered_timestamps
++;
1145 atom
->state
= THREAD_WAIT_CPU
;
1146 atom
->wake_up_time
= timestamp
;
1150 latency_migrate_task_event(struct trace_migrate_task_event
*migrate_task_event
,
1151 struct machine
*machine
,
1152 struct event
*__event __used
,
1155 struct thread
*thread __used
)
1157 struct work_atoms
*atoms
;
1158 struct work_atom
*atom
;
1159 struct thread
*migrant
;
1162 * Only need to worry about migration when profiling one CPU.
1164 if (profile_cpu
== -1)
1167 migrant
= machine__findnew_thread(machine
, migrate_task_event
->pid
);
1168 atoms
= thread_atoms_search(&atom_root
, migrant
, &cmp_pid
);
1170 thread_atoms_insert(migrant
);
1171 register_pid(migrant
->pid
, migrant
->comm
);
1172 atoms
= thread_atoms_search(&atom_root
, migrant
, &cmp_pid
);
1174 die("migration-event: Internal tree error");
1175 add_sched_out_event(atoms
, 'R', timestamp
);
1178 BUG_ON(list_empty(&atoms
->work_list
));
1180 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1181 atom
->sched_in_time
= atom
->sched_out_time
= atom
->wake_up_time
= timestamp
;
1185 if (atom
->sched_out_time
> timestamp
)
1186 nr_unordered_timestamps
++;
1189 static struct trace_sched_handler lat_ops
= {
1190 .wakeup_event
= latency_wakeup_event
,
1191 .switch_event
= latency_switch_event
,
1192 .runtime_event
= latency_runtime_event
,
1193 .fork_event
= latency_fork_event
,
1194 .migrate_task_event
= latency_migrate_task_event
,
1197 static void output_lat_thread(struct work_atoms
*work_list
)
1203 if (!work_list
->nb_atoms
)
1206 * Ignore idle threads:
1208 if (!strcmp(work_list
->thread
->comm
, "swapper"))
1211 all_runtime
+= work_list
->total_runtime
;
1212 all_count
+= work_list
->nb_atoms
;
1214 ret
= printf(" %s:%d ", work_list
->thread
->comm
, work_list
->thread
->pid
);
1216 for (i
= 0; i
< 24 - ret
; i
++)
1219 avg
= work_list
->total_lat
/ work_list
->nb_atoms
;
1221 printf("|%11.3f ms |%9" PRIu64
" | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n",
1222 (double)work_list
->total_runtime
/ 1e6
,
1223 work_list
->nb_atoms
, (double)avg
/ 1e6
,
1224 (double)work_list
->max_lat
/ 1e6
,
1225 (double)work_list
->max_lat_at
/ 1e9
);
1228 static int pid_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1230 if (l
->thread
->pid
< r
->thread
->pid
)
1232 if (l
->thread
->pid
> r
->thread
->pid
)
1238 static struct sort_dimension pid_sort_dimension
= {
1243 static int avg_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1253 avgl
= l
->total_lat
/ l
->nb_atoms
;
1254 avgr
= r
->total_lat
/ r
->nb_atoms
;
1264 static struct sort_dimension avg_sort_dimension
= {
1269 static int max_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1271 if (l
->max_lat
< r
->max_lat
)
1273 if (l
->max_lat
> r
->max_lat
)
1279 static struct sort_dimension max_sort_dimension
= {
1284 static int switch_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1286 if (l
->nb_atoms
< r
->nb_atoms
)
1288 if (l
->nb_atoms
> r
->nb_atoms
)
1294 static struct sort_dimension switch_sort_dimension
= {
1299 static int runtime_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1301 if (l
->total_runtime
< r
->total_runtime
)
1303 if (l
->total_runtime
> r
->total_runtime
)
1309 static struct sort_dimension runtime_sort_dimension
= {
1314 static struct sort_dimension
*available_sorts
[] = {
1315 &pid_sort_dimension
,
1316 &avg_sort_dimension
,
1317 &max_sort_dimension
,
1318 &switch_sort_dimension
,
1319 &runtime_sort_dimension
,
1322 #define NB_AVAILABLE_SORTS (int)(sizeof(available_sorts) / sizeof(struct sort_dimension *))
1324 static LIST_HEAD(sort_list
);
1326 static int sort_dimension__add(const char *tok
, struct list_head
*list
)
1330 for (i
= 0; i
< NB_AVAILABLE_SORTS
; i
++) {
1331 if (!strcmp(available_sorts
[i
]->name
, tok
)) {
1332 list_add_tail(&available_sorts
[i
]->list
, list
);
1341 static void setup_sorting(void);
1343 static void sort_lat(void)
1345 struct rb_node
*node
;
1348 struct work_atoms
*data
;
1349 node
= rb_first(&atom_root
);
1353 rb_erase(node
, &atom_root
);
1354 data
= rb_entry(node
, struct work_atoms
, node
);
1355 __thread_latency_insert(&sorted_atom_root
, data
, &sort_list
);
1359 static struct trace_sched_handler
*trace_handler
;
1362 process_sched_wakeup_event(struct perf_tool
*tool __used
,
1363 struct event
*event
,
1364 struct perf_sample
*sample
,
1365 struct machine
*machine
,
1366 struct thread
*thread
)
1368 void *data
= sample
->raw_data
;
1369 struct trace_wakeup_event wakeup_event
;
1371 FILL_COMMON_FIELDS(wakeup_event
, event
, data
);
1373 FILL_ARRAY(wakeup_event
, comm
, event
, data
);
1374 FILL_FIELD(wakeup_event
, pid
, event
, data
);
1375 FILL_FIELD(wakeup_event
, prio
, event
, data
);
1376 FILL_FIELD(wakeup_event
, success
, event
, data
);
1377 FILL_FIELD(wakeup_event
, cpu
, event
, data
);
1379 if (trace_handler
->wakeup_event
)
1380 trace_handler
->wakeup_event(&wakeup_event
, machine
, event
,
1381 sample
->cpu
, sample
->time
, thread
);
1385 * Track the current task - that way we can know whether there's any
1386 * weird events, such as a task being switched away that is not current.
1390 static u32 curr_pid
[MAX_CPUS
] = { [0 ... MAX_CPUS
-1] = -1 };
1392 static struct thread
*curr_thread
[MAX_CPUS
];
1394 static char next_shortname1
= 'A';
1395 static char next_shortname2
= '0';
1398 map_switch_event(struct trace_switch_event
*switch_event
,
1399 struct machine
*machine
,
1400 struct event
*event __used
,
1403 struct thread
*thread __used
)
1405 struct thread
*sched_out __used
, *sched_in
;
1411 BUG_ON(this_cpu
>= MAX_CPUS
|| this_cpu
< 0);
1413 if (this_cpu
> max_cpu
)
1416 timestamp0
= cpu_last_switched
[this_cpu
];
1417 cpu_last_switched
[this_cpu
] = timestamp
;
1419 delta
= timestamp
- timestamp0
;
1424 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
1427 sched_out
= machine__findnew_thread(machine
, switch_event
->prev_pid
);
1428 sched_in
= machine__findnew_thread(machine
, switch_event
->next_pid
);
1430 curr_thread
[this_cpu
] = sched_in
;
1435 if (!sched_in
->shortname
[0]) {
1436 sched_in
->shortname
[0] = next_shortname1
;
1437 sched_in
->shortname
[1] = next_shortname2
;
1439 if (next_shortname1
< 'Z') {
1442 next_shortname1
='A';
1443 if (next_shortname2
< '9') {
1446 next_shortname2
='0';
1452 for (cpu
= 0; cpu
<= max_cpu
; cpu
++) {
1453 if (cpu
!= this_cpu
)
1458 if (curr_thread
[cpu
]) {
1459 if (curr_thread
[cpu
]->pid
)
1460 printf("%2s ", curr_thread
[cpu
]->shortname
);
1467 printf(" %12.6f secs ", (double)timestamp
/1e9
);
1468 if (new_shortname
) {
1469 printf("%s => %s:%d\n",
1470 sched_in
->shortname
, sched_in
->comm
, sched_in
->pid
);
1477 process_sched_switch_event(struct perf_tool
*tool __used
,
1478 struct event
*event
,
1479 struct perf_sample
*sample
,
1480 struct machine
*machine
,
1481 struct thread
*thread
)
1483 int this_cpu
= sample
->cpu
;
1484 void *data
= sample
->raw_data
;
1485 struct trace_switch_event switch_event
;
1487 FILL_COMMON_FIELDS(switch_event
, event
, data
);
1489 FILL_ARRAY(switch_event
, prev_comm
, event
, data
);
1490 FILL_FIELD(switch_event
, prev_pid
, event
, data
);
1491 FILL_FIELD(switch_event
, prev_prio
, event
, data
);
1492 FILL_FIELD(switch_event
, prev_state
, event
, data
);
1493 FILL_ARRAY(switch_event
, next_comm
, event
, data
);
1494 FILL_FIELD(switch_event
, next_pid
, event
, data
);
1495 FILL_FIELD(switch_event
, next_prio
, event
, data
);
1497 if (curr_pid
[this_cpu
] != (u32
)-1) {
1499 * Are we trying to switch away a PID that is
1502 if (curr_pid
[this_cpu
] != switch_event
.prev_pid
)
1503 nr_context_switch_bugs
++;
1505 if (trace_handler
->switch_event
)
1506 trace_handler
->switch_event(&switch_event
, machine
, event
,
1507 this_cpu
, sample
->time
, thread
);
1509 curr_pid
[this_cpu
] = switch_event
.next_pid
;
1513 process_sched_runtime_event(struct perf_tool
*tool __used
,
1514 struct event
*event
,
1515 struct perf_sample
*sample
,
1516 struct machine
*machine
,
1517 struct thread
*thread
)
1519 void *data
= sample
->raw_data
;
1520 struct trace_runtime_event runtime_event
;
1522 FILL_ARRAY(runtime_event
, comm
, event
, data
);
1523 FILL_FIELD(runtime_event
, pid
, event
, data
);
1524 FILL_FIELD(runtime_event
, runtime
, event
, data
);
1525 FILL_FIELD(runtime_event
, vruntime
, event
, data
);
1527 if (trace_handler
->runtime_event
)
1528 trace_handler
->runtime_event(&runtime_event
, machine
, event
,
1529 sample
->cpu
, sample
->time
, thread
);
1533 process_sched_fork_event(struct perf_tool
*tool __used
,
1534 struct event
*event
,
1535 struct perf_sample
*sample
,
1536 struct machine
*machine __used
,
1537 struct thread
*thread
)
1539 void *data
= sample
->raw_data
;
1540 struct trace_fork_event fork_event
;
1542 FILL_COMMON_FIELDS(fork_event
, event
, data
);
1544 FILL_ARRAY(fork_event
, parent_comm
, event
, data
);
1545 FILL_FIELD(fork_event
, parent_pid
, event
, data
);
1546 FILL_ARRAY(fork_event
, child_comm
, event
, data
);
1547 FILL_FIELD(fork_event
, child_pid
, event
, data
);
1549 if (trace_handler
->fork_event
)
1550 trace_handler
->fork_event(&fork_event
, event
,
1551 sample
->cpu
, sample
->time
, thread
);
1555 process_sched_exit_event(struct perf_tool
*tool __used
,
1556 struct event
*event
,
1557 struct perf_sample
*sample __used
,
1558 struct machine
*machine __used
,
1559 struct thread
*thread __used
)
1562 printf("sched_exit event %p\n", event
);
1566 process_sched_migrate_task_event(struct perf_tool
*tool __used
,
1567 struct event
*event
,
1568 struct perf_sample
*sample
,
1569 struct machine
*machine
,
1570 struct thread
*thread
)
1572 void *data
= sample
->raw_data
;
1573 struct trace_migrate_task_event migrate_task_event
;
1575 FILL_COMMON_FIELDS(migrate_task_event
, event
, data
);
1577 FILL_ARRAY(migrate_task_event
, comm
, event
, data
);
1578 FILL_FIELD(migrate_task_event
, pid
, event
, data
);
1579 FILL_FIELD(migrate_task_event
, prio
, event
, data
);
1580 FILL_FIELD(migrate_task_event
, cpu
, event
, data
);
1582 if (trace_handler
->migrate_task_event
)
1583 trace_handler
->migrate_task_event(&migrate_task_event
, machine
,
1585 sample
->time
, thread
);
1588 typedef void (*tracepoint_handler
)(struct perf_tool
*tool
, struct event
*event
,
1589 struct perf_sample
*sample
,
1590 struct machine
*machine
,
1591 struct thread
*thread
);
1593 static int perf_sched__process_tracepoint_sample(struct perf_tool
*tool
,
1594 union perf_event
*event __used
,
1595 struct perf_sample
*sample
,
1596 struct perf_evsel
*evsel
,
1597 struct machine
*machine
)
1599 struct thread
*thread
= machine__findnew_thread(machine
, sample
->pid
);
1601 if (thread
== NULL
) {
1602 pr_debug("problem processing %s event, skipping it.\n",
1607 evsel
->hists
.stats
.total_period
+= sample
->period
;
1608 hists__inc_nr_events(&evsel
->hists
, PERF_RECORD_SAMPLE
);
1610 if (evsel
->handler
.func
!= NULL
) {
1611 tracepoint_handler f
= evsel
->handler
.func
;
1613 if (evsel
->handler
.data
== NULL
)
1614 evsel
->handler
.data
= trace_find_event(evsel
->attr
.config
);
1616 f(tool
, evsel
->handler
.data
, sample
, machine
, thread
);
1622 static struct perf_tool perf_sched
= {
1623 .sample
= perf_sched__process_tracepoint_sample
,
1624 .comm
= perf_event__process_comm
,
1625 .lost
= perf_event__process_lost
,
1626 .fork
= perf_event__process_task
,
1627 .ordered_samples
= true,
1630 static void read_events(bool destroy
, struct perf_session
**psession
)
1633 const struct perf_evsel_str_handler handlers
[] = {
1634 { "sched:sched_switch", process_sched_switch_event
, },
1635 { "sched:sched_stat_runtime", process_sched_runtime_event
, },
1636 { "sched:sched_wakeup", process_sched_wakeup_event
, },
1637 { "sched:sched_wakeup_new", process_sched_wakeup_event
, },
1638 { "sched:sched_process_fork", process_sched_fork_event
, },
1639 { "sched:sched_process_exit", process_sched_exit_event
, },
1640 { "sched:sched_migrate_task", process_sched_migrate_task_event
, },
1642 struct perf_session
*session
= perf_session__new(input_name
, O_RDONLY
,
1643 0, false, &perf_sched
);
1644 if (session
== NULL
)
1647 err
= perf_evlist__set_tracepoints_handlers_array(session
->evlist
, handlers
);
1650 if (perf_session__has_traces(session
, "record -R")) {
1651 err
= perf_session__process_events(session
, &perf_sched
);
1653 die("Failed to process events, error %d", err
);
1655 nr_events
= session
->hists
.stats
.nr_events
[0];
1656 nr_lost_events
= session
->hists
.stats
.total_lost
;
1657 nr_lost_chunks
= session
->hists
.stats
.nr_events
[PERF_RECORD_LOST
];
1661 perf_session__delete(session
);
1664 *psession
= session
;
1667 static void print_bad_events(void)
1669 if (nr_unordered_timestamps
&& nr_timestamps
) {
1670 printf(" INFO: %.3f%% unordered timestamps (%ld out of %ld)\n",
1671 (double)nr_unordered_timestamps
/(double)nr_timestamps
*100.0,
1672 nr_unordered_timestamps
, nr_timestamps
);
1674 if (nr_lost_events
&& nr_events
) {
1675 printf(" INFO: %.3f%% lost events (%ld out of %ld, in %ld chunks)\n",
1676 (double)nr_lost_events
/(double)nr_events
*100.0,
1677 nr_lost_events
, nr_events
, nr_lost_chunks
);
1679 if (nr_state_machine_bugs
&& nr_timestamps
) {
1680 printf(" INFO: %.3f%% state machine bugs (%ld out of %ld)",
1681 (double)nr_state_machine_bugs
/(double)nr_timestamps
*100.0,
1682 nr_state_machine_bugs
, nr_timestamps
);
1684 printf(" (due to lost events?)");
1687 if (nr_context_switch_bugs
&& nr_timestamps
) {
1688 printf(" INFO: %.3f%% context switch bugs (%ld out of %ld)",
1689 (double)nr_context_switch_bugs
/(double)nr_timestamps
*100.0,
1690 nr_context_switch_bugs
, nr_timestamps
);
1692 printf(" (due to lost events?)");
1697 static void __cmd_lat(void)
1699 struct rb_node
*next
;
1700 struct perf_session
*session
;
1703 read_events(false, &session
);
1706 printf("\n ---------------------------------------------------------------------------------------------------------------\n");
1707 printf(" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n");
1708 printf(" ---------------------------------------------------------------------------------------------------------------\n");
1710 next
= rb_first(&sorted_atom_root
);
1713 struct work_atoms
*work_list
;
1715 work_list
= rb_entry(next
, struct work_atoms
, node
);
1716 output_lat_thread(work_list
);
1717 next
= rb_next(next
);
1720 printf(" -----------------------------------------------------------------------------------------\n");
1721 printf(" TOTAL: |%11.3f ms |%9" PRIu64
" |\n",
1722 (double)all_runtime
/1e6
, all_count
);
1724 printf(" ---------------------------------------------------\n");
1729 perf_session__delete(session
);
1732 static struct trace_sched_handler map_ops
= {
1733 .wakeup_event
= NULL
,
1734 .switch_event
= map_switch_event
,
1735 .runtime_event
= NULL
,
1739 static void __cmd_map(void)
1741 max_cpu
= sysconf(_SC_NPROCESSORS_CONF
);
1744 read_events(true, NULL
);
1748 static void __cmd_replay(void)
1752 calibrate_run_measurement_overhead();
1753 calibrate_sleep_measurement_overhead();
1755 test_calibrations();
1757 read_events(true, NULL
);
1759 printf("nr_run_events: %ld\n", nr_run_events
);
1760 printf("nr_sleep_events: %ld\n", nr_sleep_events
);
1761 printf("nr_wakeup_events: %ld\n", nr_wakeup_events
);
1763 if (targetless_wakeups
)
1764 printf("target-less wakeups: %ld\n", targetless_wakeups
);
1765 if (multitarget_wakeups
)
1766 printf("multi-target wakeups: %ld\n", multitarget_wakeups
);
1767 if (nr_run_events_optimized
)
1768 printf("run atoms optimized: %ld\n",
1769 nr_run_events_optimized
);
1771 print_task_traces();
1772 add_cross_task_wakeups();
1775 printf("------------------------------------------------------------\n");
1776 for (i
= 0; i
< replay_repeat
; i
++)
1781 static const char * const sched_usage
[] = {
1782 "perf sched [<options>] {record|latency|map|replay|script}",
1786 static const struct option sched_options
[] = {
1787 OPT_STRING('i', "input", &input_name
, "file",
1789 OPT_INCR('v', "verbose", &verbose
,
1790 "be more verbose (show symbol address, etc)"),
1791 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1792 "dump raw trace in ASCII"),
1796 static const char * const latency_usage
[] = {
1797 "perf sched latency [<options>]",
1801 static const struct option latency_options
[] = {
1802 OPT_STRING('s', "sort", &sort_order
, "key[,key2...]",
1803 "sort by key(s): runtime, switch, avg, max"),
1804 OPT_INCR('v', "verbose", &verbose
,
1805 "be more verbose (show symbol address, etc)"),
1806 OPT_INTEGER('C', "CPU", &profile_cpu
,
1807 "CPU to profile on"),
1808 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1809 "dump raw trace in ASCII"),
1813 static const char * const replay_usage
[] = {
1814 "perf sched replay [<options>]",
1818 static const struct option replay_options
[] = {
1819 OPT_UINTEGER('r', "repeat", &replay_repeat
,
1820 "repeat the workload replay N times (-1: infinite)"),
1821 OPT_INCR('v', "verbose", &verbose
,
1822 "be more verbose (show symbol address, etc)"),
1823 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1824 "dump raw trace in ASCII"),
1828 static void setup_sorting(void)
1830 char *tmp
, *tok
, *str
= strdup(sort_order
);
1832 for (tok
= strtok_r(str
, ", ", &tmp
);
1833 tok
; tok
= strtok_r(NULL
, ", ", &tmp
)) {
1834 if (sort_dimension__add(tok
, &sort_list
) < 0) {
1835 error("Unknown --sort key: `%s'", tok
);
1836 usage_with_options(latency_usage
, latency_options
);
1842 sort_dimension__add("pid", &cmp_pid
);
1845 static const char *record_args
[] = {
1852 "-e", "sched:sched_switch",
1853 "-e", "sched:sched_stat_wait",
1854 "-e", "sched:sched_stat_sleep",
1855 "-e", "sched:sched_stat_iowait",
1856 "-e", "sched:sched_stat_runtime",
1857 "-e", "sched:sched_process_exit",
1858 "-e", "sched:sched_process_fork",
1859 "-e", "sched:sched_wakeup",
1860 "-e", "sched:sched_migrate_task",
1863 static int __cmd_record(int argc
, const char **argv
)
1865 unsigned int rec_argc
, i
, j
;
1866 const char **rec_argv
;
1868 rec_argc
= ARRAY_SIZE(record_args
) + argc
- 1;
1869 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
1871 if (rec_argv
== NULL
)
1874 for (i
= 0; i
< ARRAY_SIZE(record_args
); i
++)
1875 rec_argv
[i
] = strdup(record_args
[i
]);
1877 for (j
= 1; j
< (unsigned int)argc
; j
++, i
++)
1878 rec_argv
[i
] = argv
[j
];
1880 BUG_ON(i
!= rec_argc
);
1882 return cmd_record(i
, rec_argv
, NULL
);
1885 int cmd_sched(int argc
, const char **argv
, const char *prefix __used
)
1887 argc
= parse_options(argc
, argv
, sched_options
, sched_usage
,
1888 PARSE_OPT_STOP_AT_NON_OPTION
);
1890 usage_with_options(sched_usage
, sched_options
);
1893 * Aliased to 'perf script' for now:
1895 if (!strcmp(argv
[0], "script"))
1896 return cmd_script(argc
, argv
, prefix
);
1899 if (!strncmp(argv
[0], "rec", 3)) {
1900 return __cmd_record(argc
, argv
);
1901 } else if (!strncmp(argv
[0], "lat", 3)) {
1902 trace_handler
= &lat_ops
;
1904 argc
= parse_options(argc
, argv
, latency_options
, latency_usage
, 0);
1906 usage_with_options(latency_usage
, latency_options
);
1910 } else if (!strcmp(argv
[0], "map")) {
1911 trace_handler
= &map_ops
;
1914 } else if (!strncmp(argv
[0], "rep", 3)) {
1915 trace_handler
= &replay_ops
;
1917 argc
= parse_options(argc
, argv
, replay_options
, replay_usage
, 0);
1919 usage_with_options(replay_usage
, replay_options
);
1923 usage_with_options(sched_usage
, sched_options
);