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>
20 #include <sys/resource.h>
22 #include <semaphore.h>
26 static const char *input_name
;
28 static char default_sort_order
[] = "avg, max, switch, runtime";
29 static const char *sort_order
= default_sort_order
;
31 static int profile_cpu
= -1;
33 #define PR_SET_NAME 15 /* Set process name */
36 static u64 run_measurement_overhead
;
37 static u64 sleep_measurement_overhead
;
44 static unsigned long nr_tasks
;
47 struct perf_tool tool
;
48 struct perf_session
*session
;
58 unsigned long nr_events
;
59 unsigned long curr_event
;
60 struct sched_atom
**atoms
;
71 enum sched_event_type
{
75 SCHED_EVENT_MIGRATION
,
79 enum sched_event_type type
;
85 struct task_desc
*wakee
;
88 static struct task_desc
*pid_to_task
[MAX_PID
];
90 static struct task_desc
**tasks
;
92 static pthread_mutex_t start_work_mutex
= PTHREAD_MUTEX_INITIALIZER
;
93 static u64 start_time
;
95 static pthread_mutex_t work_done_wait_mutex
= PTHREAD_MUTEX_INITIALIZER
;
97 static unsigned long nr_run_events
;
98 static unsigned long nr_sleep_events
;
99 static unsigned long nr_wakeup_events
;
101 static unsigned long nr_sleep_corrections
;
102 static unsigned long nr_run_events_optimized
;
104 static unsigned long targetless_wakeups
;
105 static unsigned long multitarget_wakeups
;
107 static u64 cpu_usage
;
108 static u64 runavg_cpu_usage
;
109 static u64 parent_cpu_usage
;
110 static u64 runavg_parent_cpu_usage
;
112 static unsigned long nr_runs
;
113 static u64 sum_runtime
;
114 static u64 sum_fluct
;
117 static unsigned int replay_repeat
= 10;
118 static unsigned long nr_timestamps
;
119 static unsigned long nr_unordered_timestamps
;
120 static unsigned long nr_state_machine_bugs
;
121 static unsigned long nr_context_switch_bugs
;
122 static unsigned long nr_events
;
123 static unsigned long nr_lost_chunks
;
124 static unsigned long nr_lost_events
;
126 #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
136 struct list_head list
;
137 enum thread_state state
;
145 struct list_head work_list
;
146 struct thread
*thread
;
155 typedef int (*sort_fn_t
)(struct work_atoms
*, struct work_atoms
*);
157 static struct rb_root atom_root
, sorted_atom_root
;
159 static u64 all_runtime
;
160 static u64 all_count
;
163 static u64
get_nsecs(void)
167 clock_gettime(CLOCK_MONOTONIC
, &ts
);
169 return ts
.tv_sec
* 1000000000ULL + ts
.tv_nsec
;
172 static void burn_nsecs(u64 nsecs
)
174 u64 T0
= get_nsecs(), T1
;
178 } while (T1
+ run_measurement_overhead
< T0
+ nsecs
);
181 static void sleep_nsecs(u64 nsecs
)
185 ts
.tv_nsec
= nsecs
% 999999999;
186 ts
.tv_sec
= nsecs
/ 999999999;
188 nanosleep(&ts
, NULL
);
191 static void calibrate_run_measurement_overhead(void)
193 u64 T0
, T1
, delta
, min_delta
= 1000000000ULL;
196 for (i
= 0; i
< 10; i
++) {
201 min_delta
= min(min_delta
, delta
);
203 run_measurement_overhead
= min_delta
;
205 printf("run measurement overhead: %" PRIu64
" nsecs\n", min_delta
);
208 static void calibrate_sleep_measurement_overhead(void)
210 u64 T0
, T1
, delta
, min_delta
= 1000000000ULL;
213 for (i
= 0; i
< 10; i
++) {
218 min_delta
= min(min_delta
, delta
);
221 sleep_measurement_overhead
= min_delta
;
223 printf("sleep measurement overhead: %" PRIu64
" nsecs\n", min_delta
);
226 static struct sched_atom
*
227 get_new_event(struct task_desc
*task
, u64 timestamp
)
229 struct sched_atom
*event
= zalloc(sizeof(*event
));
230 unsigned long idx
= task
->nr_events
;
233 event
->timestamp
= timestamp
;
237 size
= sizeof(struct sched_atom
*) * task
->nr_events
;
238 task
->atoms
= realloc(task
->atoms
, size
);
239 BUG_ON(!task
->atoms
);
241 task
->atoms
[idx
] = event
;
246 static struct sched_atom
*last_event(struct task_desc
*task
)
248 if (!task
->nr_events
)
251 return task
->atoms
[task
->nr_events
- 1];
255 add_sched_event_run(struct task_desc
*task
, u64 timestamp
, u64 duration
)
257 struct sched_atom
*event
, *curr_event
= last_event(task
);
260 * optimize an existing RUN event by merging this one
263 if (curr_event
&& curr_event
->type
== SCHED_EVENT_RUN
) {
264 nr_run_events_optimized
++;
265 curr_event
->duration
+= duration
;
269 event
= get_new_event(task
, timestamp
);
271 event
->type
= SCHED_EVENT_RUN
;
272 event
->duration
= duration
;
278 add_sched_event_wakeup(struct task_desc
*task
, u64 timestamp
,
279 struct task_desc
*wakee
)
281 struct sched_atom
*event
, *wakee_event
;
283 event
= get_new_event(task
, timestamp
);
284 event
->type
= SCHED_EVENT_WAKEUP
;
285 event
->wakee
= wakee
;
287 wakee_event
= last_event(wakee
);
288 if (!wakee_event
|| wakee_event
->type
!= SCHED_EVENT_SLEEP
) {
289 targetless_wakeups
++;
292 if (wakee_event
->wait_sem
) {
293 multitarget_wakeups
++;
297 wakee_event
->wait_sem
= zalloc(sizeof(*wakee_event
->wait_sem
));
298 sem_init(wakee_event
->wait_sem
, 0, 0);
299 wakee_event
->specific_wait
= 1;
300 event
->wait_sem
= wakee_event
->wait_sem
;
306 add_sched_event_sleep(struct task_desc
*task
, u64 timestamp
,
307 u64 task_state __used
)
309 struct sched_atom
*event
= get_new_event(task
, timestamp
);
311 event
->type
= SCHED_EVENT_SLEEP
;
316 static struct task_desc
*register_pid(unsigned long pid
, const char *comm
)
318 struct task_desc
*task
;
320 BUG_ON(pid
>= MAX_PID
);
322 task
= pid_to_task
[pid
];
327 task
= zalloc(sizeof(*task
));
330 strcpy(task
->comm
, comm
);
332 * every task starts in sleeping state - this gets ignored
333 * if there's no wakeup pointing to this sleep state:
335 add_sched_event_sleep(task
, 0, 0);
337 pid_to_task
[pid
] = task
;
339 tasks
= realloc(tasks
, nr_tasks
*sizeof(struct task_task
*));
341 tasks
[task
->nr
] = task
;
344 printf("registered task #%ld, PID %ld (%s)\n", nr_tasks
, pid
, comm
);
350 static void print_task_traces(void)
352 struct task_desc
*task
;
355 for (i
= 0; i
< nr_tasks
; i
++) {
357 printf("task %6ld (%20s:%10ld), nr_events: %ld\n",
358 task
->nr
, task
->comm
, task
->pid
, task
->nr_events
);
362 static void add_cross_task_wakeups(void)
364 struct task_desc
*task1
, *task2
;
367 for (i
= 0; i
< nr_tasks
; i
++) {
373 add_sched_event_wakeup(task1
, 0, task2
);
378 process_sched_event(struct task_desc
*this_task __used
, struct sched_atom
*atom
)
382 switch (atom
->type
) {
383 case SCHED_EVENT_RUN
:
384 burn_nsecs(atom
->duration
);
386 case SCHED_EVENT_SLEEP
:
388 ret
= sem_wait(atom
->wait_sem
);
391 case SCHED_EVENT_WAKEUP
:
393 ret
= sem_post(atom
->wait_sem
);
396 case SCHED_EVENT_MIGRATION
:
403 static u64
get_cpu_usage_nsec_parent(void)
409 err
= getrusage(RUSAGE_SELF
, &ru
);
412 sum
= ru
.ru_utime
.tv_sec
*1e9
+ ru
.ru_utime
.tv_usec
*1e3
;
413 sum
+= ru
.ru_stime
.tv_sec
*1e9
+ ru
.ru_stime
.tv_usec
*1e3
;
418 static int self_open_counters(void)
420 struct perf_event_attr attr
;
423 memset(&attr
, 0, sizeof(attr
));
425 attr
.type
= PERF_TYPE_SOFTWARE
;
426 attr
.config
= PERF_COUNT_SW_TASK_CLOCK
;
428 fd
= sys_perf_event_open(&attr
, 0, -1, -1, 0);
431 die("Error: sys_perf_event_open() syscall returned"
432 "with %d (%s)\n", fd
, strerror(errno
));
436 static u64
get_cpu_usage_nsec_self(int fd
)
441 ret
= read(fd
, &runtime
, sizeof(runtime
));
442 BUG_ON(ret
!= sizeof(runtime
));
447 static void *thread_func(void *ctx
)
449 struct task_desc
*this_task
= ctx
;
450 u64 cpu_usage_0
, cpu_usage_1
;
451 unsigned long i
, ret
;
455 sprintf(comm2
, ":%s", this_task
->comm
);
456 prctl(PR_SET_NAME
, comm2
);
457 fd
= self_open_counters();
460 ret
= sem_post(&this_task
->ready_for_work
);
462 ret
= pthread_mutex_lock(&start_work_mutex
);
464 ret
= pthread_mutex_unlock(&start_work_mutex
);
467 cpu_usage_0
= get_cpu_usage_nsec_self(fd
);
469 for (i
= 0; i
< this_task
->nr_events
; i
++) {
470 this_task
->curr_event
= i
;
471 process_sched_event(this_task
, this_task
->atoms
[i
]);
474 cpu_usage_1
= get_cpu_usage_nsec_self(fd
);
475 this_task
->cpu_usage
= cpu_usage_1
- cpu_usage_0
;
476 ret
= sem_post(&this_task
->work_done_sem
);
479 ret
= pthread_mutex_lock(&work_done_wait_mutex
);
481 ret
= pthread_mutex_unlock(&work_done_wait_mutex
);
487 static void create_tasks(void)
489 struct task_desc
*task
;
494 err
= pthread_attr_init(&attr
);
496 err
= pthread_attr_setstacksize(&attr
,
497 (size_t) max(16 * 1024, PTHREAD_STACK_MIN
));
499 err
= pthread_mutex_lock(&start_work_mutex
);
501 err
= pthread_mutex_lock(&work_done_wait_mutex
);
503 for (i
= 0; i
< nr_tasks
; i
++) {
505 sem_init(&task
->sleep_sem
, 0, 0);
506 sem_init(&task
->ready_for_work
, 0, 0);
507 sem_init(&task
->work_done_sem
, 0, 0);
508 task
->curr_event
= 0;
509 err
= pthread_create(&task
->thread
, &attr
, thread_func
, task
);
514 static void wait_for_tasks(void)
516 u64 cpu_usage_0
, cpu_usage_1
;
517 struct task_desc
*task
;
518 unsigned long i
, ret
;
520 start_time
= get_nsecs();
522 pthread_mutex_unlock(&work_done_wait_mutex
);
524 for (i
= 0; i
< nr_tasks
; i
++) {
526 ret
= sem_wait(&task
->ready_for_work
);
528 sem_init(&task
->ready_for_work
, 0, 0);
530 ret
= pthread_mutex_lock(&work_done_wait_mutex
);
533 cpu_usage_0
= get_cpu_usage_nsec_parent();
535 pthread_mutex_unlock(&start_work_mutex
);
537 for (i
= 0; i
< nr_tasks
; i
++) {
539 ret
= sem_wait(&task
->work_done_sem
);
541 sem_init(&task
->work_done_sem
, 0, 0);
542 cpu_usage
+= task
->cpu_usage
;
546 cpu_usage_1
= get_cpu_usage_nsec_parent();
547 if (!runavg_cpu_usage
)
548 runavg_cpu_usage
= cpu_usage
;
549 runavg_cpu_usage
= (runavg_cpu_usage
*9 + cpu_usage
)/10;
551 parent_cpu_usage
= cpu_usage_1
- cpu_usage_0
;
552 if (!runavg_parent_cpu_usage
)
553 runavg_parent_cpu_usage
= parent_cpu_usage
;
554 runavg_parent_cpu_usage
= (runavg_parent_cpu_usage
*9 +
555 parent_cpu_usage
)/10;
557 ret
= pthread_mutex_lock(&start_work_mutex
);
560 for (i
= 0; i
< nr_tasks
; i
++) {
562 sem_init(&task
->sleep_sem
, 0, 0);
563 task
->curr_event
= 0;
567 static void run_one_test(void)
569 u64 T0
, T1
, delta
, avg_delta
, fluct
;
576 sum_runtime
+= delta
;
579 avg_delta
= sum_runtime
/ nr_runs
;
580 if (delta
< avg_delta
)
581 fluct
= avg_delta
- delta
;
583 fluct
= delta
- avg_delta
;
587 run_avg
= (run_avg
*9 + delta
)/10;
589 printf("#%-3ld: %0.3f, ",
590 nr_runs
, (double)delta
/1000000.0);
592 printf("ravg: %0.2f, ",
593 (double)run_avg
/1e6
);
595 printf("cpu: %0.2f / %0.2f",
596 (double)cpu_usage
/1e6
, (double)runavg_cpu_usage
/1e6
);
600 * rusage statistics done by the parent, these are less
601 * accurate than the sum_exec_runtime based statistics:
603 printf(" [%0.2f / %0.2f]",
604 (double)parent_cpu_usage
/1e6
,
605 (double)runavg_parent_cpu_usage
/1e6
);
610 if (nr_sleep_corrections
)
611 printf(" (%ld sleep corrections)\n", nr_sleep_corrections
);
612 nr_sleep_corrections
= 0;
615 static void test_calibrations(void)
623 printf("the run test took %" PRIu64
" nsecs\n", T1
- T0
);
629 printf("the sleep test took %" PRIu64
" nsecs\n", T1
- T0
);
632 #define FILL_FIELD(ptr, field, event, data) \
633 ptr.field = (typeof(ptr.field)) raw_field_value(event, #field, data)
635 #define FILL_ARRAY(ptr, array, event, data) \
637 void *__array = raw_field_ptr(event, #array, data); \
638 memcpy(ptr.array, __array, sizeof(ptr.array)); \
641 #define FILL_COMMON_FIELDS(ptr, event, data) \
643 FILL_FIELD(ptr, common_type, event, data); \
644 FILL_FIELD(ptr, common_flags, event, data); \
645 FILL_FIELD(ptr, common_preempt_count, event, data); \
646 FILL_FIELD(ptr, common_pid, event, data); \
647 FILL_FIELD(ptr, common_tgid, event, data); \
652 struct trace_switch_event
{
657 u8 common_preempt_count
;
670 struct trace_runtime_event
{
675 u8 common_preempt_count
;
685 struct trace_wakeup_event
{
690 u8 common_preempt_count
;
702 struct trace_fork_event
{
707 u8 common_preempt_count
;
711 char parent_comm
[16];
717 struct trace_migrate_task_event
{
722 u8 common_preempt_count
;
733 struct trace_sched_handler
{
734 void (*switch_event
)(struct trace_switch_event
*,
736 struct event_format
*,
739 struct thread
*thread
);
741 void (*runtime_event
)(struct trace_runtime_event
*,
743 struct event_format
*,
746 struct thread
*thread
);
748 void (*wakeup_event
)(struct trace_wakeup_event
*,
750 struct event_format
*,
753 struct thread
*thread
);
755 void (*fork_event
)(struct trace_fork_event
*,
756 struct event_format
*,
759 struct thread
*thread
);
761 void (*migrate_task_event
)(struct trace_migrate_task_event
*,
762 struct machine
*machine
,
763 struct event_format
*,
766 struct thread
*thread
);
771 replay_wakeup_event(struct trace_wakeup_event
*wakeup_event
,
772 struct machine
*machine __used
,
773 struct event_format
*event
,
775 u64 timestamp __used
,
776 struct thread
*thread __used
)
778 struct task_desc
*waker
, *wakee
;
781 printf("sched_wakeup event %p\n", event
);
783 printf(" ... pid %d woke up %s/%d\n",
784 wakeup_event
->common_pid
,
789 waker
= register_pid(wakeup_event
->common_pid
, "<unknown>");
790 wakee
= register_pid(wakeup_event
->pid
, wakeup_event
->comm
);
792 add_sched_event_wakeup(waker
, timestamp
, wakee
);
795 static u64 cpu_last_switched
[MAX_CPUS
];
798 replay_switch_event(struct trace_switch_event
*switch_event
,
799 struct machine
*machine __used
,
800 struct event_format
*event
,
803 struct thread
*thread __used
)
805 struct task_desc
*prev
, __used
*next
;
810 printf("sched_switch event %p\n", event
);
812 if (cpu
>= MAX_CPUS
|| cpu
< 0)
815 timestamp0
= cpu_last_switched
[cpu
];
817 delta
= timestamp
- timestamp0
;
822 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
825 printf(" ... switch from %s/%d to %s/%d [ran %" PRIu64
" nsecs]\n",
826 switch_event
->prev_comm
, switch_event
->prev_pid
,
827 switch_event
->next_comm
, switch_event
->next_pid
,
831 prev
= register_pid(switch_event
->prev_pid
, switch_event
->prev_comm
);
832 next
= register_pid(switch_event
->next_pid
, switch_event
->next_comm
);
834 cpu_last_switched
[cpu
] = timestamp
;
836 add_sched_event_run(prev
, timestamp
, delta
);
837 add_sched_event_sleep(prev
, timestamp
, switch_event
->prev_state
);
842 replay_fork_event(struct trace_fork_event
*fork_event
,
843 struct event_format
*event
,
845 u64 timestamp __used
,
846 struct thread
*thread __used
)
849 printf("sched_fork event %p\n", event
);
850 printf("... parent: %s/%d\n", fork_event
->parent_comm
, fork_event
->parent_pid
);
851 printf("... child: %s/%d\n", fork_event
->child_comm
, fork_event
->child_pid
);
853 register_pid(fork_event
->parent_pid
, fork_event
->parent_comm
);
854 register_pid(fork_event
->child_pid
, fork_event
->child_comm
);
857 static struct trace_sched_handler replay_ops
= {
858 .wakeup_event
= replay_wakeup_event
,
859 .switch_event
= replay_switch_event
,
860 .fork_event
= replay_fork_event
,
863 struct sort_dimension
{
866 struct list_head list
;
869 static LIST_HEAD(cmp_pid
);
872 thread_lat_cmp(struct list_head
*list
, struct work_atoms
*l
, struct work_atoms
*r
)
874 struct sort_dimension
*sort
;
877 BUG_ON(list_empty(list
));
879 list_for_each_entry(sort
, list
, list
) {
880 ret
= sort
->cmp(l
, r
);
888 static struct work_atoms
*
889 thread_atoms_search(struct rb_root
*root
, struct thread
*thread
,
890 struct list_head
*sort_list
)
892 struct rb_node
*node
= root
->rb_node
;
893 struct work_atoms key
= { .thread
= thread
};
896 struct work_atoms
*atoms
;
899 atoms
= container_of(node
, struct work_atoms
, node
);
901 cmp
= thread_lat_cmp(sort_list
, &key
, atoms
);
903 node
= node
->rb_left
;
905 node
= node
->rb_right
;
907 BUG_ON(thread
!= atoms
->thread
);
915 __thread_latency_insert(struct rb_root
*root
, struct work_atoms
*data
,
916 struct list_head
*sort_list
)
918 struct rb_node
**new = &(root
->rb_node
), *parent
= NULL
;
921 struct work_atoms
*this;
924 this = container_of(*new, struct work_atoms
, node
);
927 cmp
= thread_lat_cmp(sort_list
, data
, this);
930 new = &((*new)->rb_left
);
932 new = &((*new)->rb_right
);
935 rb_link_node(&data
->node
, parent
, new);
936 rb_insert_color(&data
->node
, root
);
939 static void thread_atoms_insert(struct thread
*thread
)
941 struct work_atoms
*atoms
= zalloc(sizeof(*atoms
));
945 atoms
->thread
= thread
;
946 INIT_LIST_HEAD(&atoms
->work_list
);
947 __thread_latency_insert(&atom_root
, atoms
, &cmp_pid
);
951 latency_fork_event(struct trace_fork_event
*fork_event __used
,
952 struct event_format
*event __used
,
954 u64 timestamp __used
,
955 struct thread
*thread __used
)
957 /* should insert the newcomer */
961 static char sched_out_state(struct trace_switch_event
*switch_event
)
963 const char *str
= TASK_STATE_TO_CHAR_STR
;
965 return str
[switch_event
->prev_state
];
969 add_sched_out_event(struct work_atoms
*atoms
,
973 struct work_atom
*atom
= zalloc(sizeof(*atom
));
977 atom
->sched_out_time
= timestamp
;
979 if (run_state
== 'R') {
980 atom
->state
= THREAD_WAIT_CPU
;
981 atom
->wake_up_time
= atom
->sched_out_time
;
984 list_add_tail(&atom
->list
, &atoms
->work_list
);
988 add_runtime_event(struct work_atoms
*atoms
, u64 delta
, u64 timestamp __used
)
990 struct work_atom
*atom
;
992 BUG_ON(list_empty(&atoms
->work_list
));
994 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
996 atom
->runtime
+= delta
;
997 atoms
->total_runtime
+= delta
;
1001 add_sched_in_event(struct work_atoms
*atoms
, u64 timestamp
)
1003 struct work_atom
*atom
;
1006 if (list_empty(&atoms
->work_list
))
1009 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1011 if (atom
->state
!= THREAD_WAIT_CPU
)
1014 if (timestamp
< atom
->wake_up_time
) {
1015 atom
->state
= THREAD_IGNORE
;
1019 atom
->state
= THREAD_SCHED_IN
;
1020 atom
->sched_in_time
= timestamp
;
1022 delta
= atom
->sched_in_time
- atom
->wake_up_time
;
1023 atoms
->total_lat
+= delta
;
1024 if (delta
> atoms
->max_lat
) {
1025 atoms
->max_lat
= delta
;
1026 atoms
->max_lat_at
= timestamp
;
1032 latency_switch_event(struct trace_switch_event
*switch_event
,
1033 struct machine
*machine
,
1034 struct event_format
*event __used
,
1037 struct thread
*thread __used
)
1039 struct work_atoms
*out_events
, *in_events
;
1040 struct thread
*sched_out
, *sched_in
;
1044 BUG_ON(cpu
>= MAX_CPUS
|| cpu
< 0);
1046 timestamp0
= cpu_last_switched
[cpu
];
1047 cpu_last_switched
[cpu
] = timestamp
;
1049 delta
= timestamp
- timestamp0
;
1054 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
1057 sched_out
= machine__findnew_thread(machine
, switch_event
->prev_pid
);
1058 sched_in
= machine__findnew_thread(machine
, switch_event
->next_pid
);
1060 out_events
= thread_atoms_search(&atom_root
, sched_out
, &cmp_pid
);
1062 thread_atoms_insert(sched_out
);
1063 out_events
= thread_atoms_search(&atom_root
, sched_out
, &cmp_pid
);
1065 die("out-event: Internal tree error");
1067 add_sched_out_event(out_events
, sched_out_state(switch_event
), timestamp
);
1069 in_events
= thread_atoms_search(&atom_root
, sched_in
, &cmp_pid
);
1071 thread_atoms_insert(sched_in
);
1072 in_events
= thread_atoms_search(&atom_root
, sched_in
, &cmp_pid
);
1074 die("in-event: Internal tree error");
1076 * Take came in we have not heard about yet,
1077 * add in an initial atom in runnable state:
1079 add_sched_out_event(in_events
, 'R', timestamp
);
1081 add_sched_in_event(in_events
, timestamp
);
1085 latency_runtime_event(struct trace_runtime_event
*runtime_event
,
1086 struct machine
*machine
,
1087 struct event_format
*event __used
,
1090 struct thread
*this_thread __used
)
1092 struct thread
*thread
= machine__findnew_thread(machine
, runtime_event
->pid
);
1093 struct work_atoms
*atoms
= thread_atoms_search(&atom_root
, thread
, &cmp_pid
);
1095 BUG_ON(cpu
>= MAX_CPUS
|| cpu
< 0);
1097 thread_atoms_insert(thread
);
1098 atoms
= thread_atoms_search(&atom_root
, thread
, &cmp_pid
);
1100 die("in-event: Internal tree error");
1101 add_sched_out_event(atoms
, 'R', timestamp
);
1104 add_runtime_event(atoms
, runtime_event
->runtime
, timestamp
);
1108 latency_wakeup_event(struct trace_wakeup_event
*wakeup_event
,
1109 struct machine
*machine
,
1110 struct event_format
*__event __used
,
1113 struct thread
*thread __used
)
1115 struct work_atoms
*atoms
;
1116 struct work_atom
*atom
;
1117 struct thread
*wakee
;
1119 /* Note for later, it may be interesting to observe the failing cases */
1120 if (!wakeup_event
->success
)
1123 wakee
= machine__findnew_thread(machine
, wakeup_event
->pid
);
1124 atoms
= thread_atoms_search(&atom_root
, wakee
, &cmp_pid
);
1126 thread_atoms_insert(wakee
);
1127 atoms
= thread_atoms_search(&atom_root
, wakee
, &cmp_pid
);
1129 die("wakeup-event: Internal tree error");
1130 add_sched_out_event(atoms
, 'S', timestamp
);
1133 BUG_ON(list_empty(&atoms
->work_list
));
1135 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1138 * You WILL be missing events if you've recorded only
1139 * one CPU, or are only looking at only one, so don't
1140 * make useless noise.
1142 if (profile_cpu
== -1 && atom
->state
!= THREAD_SLEEPING
)
1143 nr_state_machine_bugs
++;
1146 if (atom
->sched_out_time
> timestamp
) {
1147 nr_unordered_timestamps
++;
1151 atom
->state
= THREAD_WAIT_CPU
;
1152 atom
->wake_up_time
= timestamp
;
1156 latency_migrate_task_event(struct trace_migrate_task_event
*migrate_task_event
,
1157 struct machine
*machine
,
1158 struct event_format
*__event __used
,
1161 struct thread
*thread __used
)
1163 struct work_atoms
*atoms
;
1164 struct work_atom
*atom
;
1165 struct thread
*migrant
;
1168 * Only need to worry about migration when profiling one CPU.
1170 if (profile_cpu
== -1)
1173 migrant
= machine__findnew_thread(machine
, migrate_task_event
->pid
);
1174 atoms
= thread_atoms_search(&atom_root
, migrant
, &cmp_pid
);
1176 thread_atoms_insert(migrant
);
1177 register_pid(migrant
->pid
, migrant
->comm
);
1178 atoms
= thread_atoms_search(&atom_root
, migrant
, &cmp_pid
);
1180 die("migration-event: Internal tree error");
1181 add_sched_out_event(atoms
, 'R', timestamp
);
1184 BUG_ON(list_empty(&atoms
->work_list
));
1186 atom
= list_entry(atoms
->work_list
.prev
, struct work_atom
, list
);
1187 atom
->sched_in_time
= atom
->sched_out_time
= atom
->wake_up_time
= timestamp
;
1191 if (atom
->sched_out_time
> timestamp
)
1192 nr_unordered_timestamps
++;
1195 static struct trace_sched_handler lat_ops
= {
1196 .wakeup_event
= latency_wakeup_event
,
1197 .switch_event
= latency_switch_event
,
1198 .runtime_event
= latency_runtime_event
,
1199 .fork_event
= latency_fork_event
,
1200 .migrate_task_event
= latency_migrate_task_event
,
1203 static void output_lat_thread(struct work_atoms
*work_list
)
1209 if (!work_list
->nb_atoms
)
1212 * Ignore idle threads:
1214 if (!strcmp(work_list
->thread
->comm
, "swapper"))
1217 all_runtime
+= work_list
->total_runtime
;
1218 all_count
+= work_list
->nb_atoms
;
1220 ret
= printf(" %s:%d ", work_list
->thread
->comm
, work_list
->thread
->pid
);
1222 for (i
= 0; i
< 24 - ret
; i
++)
1225 avg
= work_list
->total_lat
/ work_list
->nb_atoms
;
1227 printf("|%11.3f ms |%9" PRIu64
" | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n",
1228 (double)work_list
->total_runtime
/ 1e6
,
1229 work_list
->nb_atoms
, (double)avg
/ 1e6
,
1230 (double)work_list
->max_lat
/ 1e6
,
1231 (double)work_list
->max_lat_at
/ 1e9
);
1234 static int pid_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1236 if (l
->thread
->pid
< r
->thread
->pid
)
1238 if (l
->thread
->pid
> r
->thread
->pid
)
1244 static struct sort_dimension pid_sort_dimension
= {
1249 static int avg_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1259 avgl
= l
->total_lat
/ l
->nb_atoms
;
1260 avgr
= r
->total_lat
/ r
->nb_atoms
;
1270 static struct sort_dimension avg_sort_dimension
= {
1275 static int max_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1277 if (l
->max_lat
< r
->max_lat
)
1279 if (l
->max_lat
> r
->max_lat
)
1285 static struct sort_dimension max_sort_dimension
= {
1290 static int switch_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1292 if (l
->nb_atoms
< r
->nb_atoms
)
1294 if (l
->nb_atoms
> r
->nb_atoms
)
1300 static struct sort_dimension switch_sort_dimension
= {
1305 static int runtime_cmp(struct work_atoms
*l
, struct work_atoms
*r
)
1307 if (l
->total_runtime
< r
->total_runtime
)
1309 if (l
->total_runtime
> r
->total_runtime
)
1315 static struct sort_dimension runtime_sort_dimension
= {
1320 static struct sort_dimension
*available_sorts
[] = {
1321 &pid_sort_dimension
,
1322 &avg_sort_dimension
,
1323 &max_sort_dimension
,
1324 &switch_sort_dimension
,
1325 &runtime_sort_dimension
,
1328 #define NB_AVAILABLE_SORTS (int)(sizeof(available_sorts) / sizeof(struct sort_dimension *))
1330 static LIST_HEAD(sort_list
);
1332 static int sort_dimension__add(const char *tok
, struct list_head
*list
)
1336 for (i
= 0; i
< NB_AVAILABLE_SORTS
; i
++) {
1337 if (!strcmp(available_sorts
[i
]->name
, tok
)) {
1338 list_add_tail(&available_sorts
[i
]->list
, list
);
1347 static void setup_sorting(void);
1349 static void sort_lat(void)
1351 struct rb_node
*node
;
1354 struct work_atoms
*data
;
1355 node
= rb_first(&atom_root
);
1359 rb_erase(node
, &atom_root
);
1360 data
= rb_entry(node
, struct work_atoms
, node
);
1361 __thread_latency_insert(&sorted_atom_root
, data
, &sort_list
);
1365 static struct trace_sched_handler
*trace_handler
;
1368 process_sched_wakeup_event(struct perf_tool
*tool __used
,
1369 struct event_format
*event
,
1370 struct perf_sample
*sample
,
1371 struct machine
*machine
,
1372 struct thread
*thread
)
1374 void *data
= sample
->raw_data
;
1375 struct trace_wakeup_event wakeup_event
;
1377 FILL_COMMON_FIELDS(wakeup_event
, event
, data
);
1379 FILL_ARRAY(wakeup_event
, comm
, event
, data
);
1380 FILL_FIELD(wakeup_event
, pid
, event
, data
);
1381 FILL_FIELD(wakeup_event
, prio
, event
, data
);
1382 FILL_FIELD(wakeup_event
, success
, event
, data
);
1383 FILL_FIELD(wakeup_event
, cpu
, event
, data
);
1385 if (trace_handler
->wakeup_event
)
1386 trace_handler
->wakeup_event(&wakeup_event
, machine
, event
,
1387 sample
->cpu
, sample
->time
, thread
);
1391 * Track the current task - that way we can know whether there's any
1392 * weird events, such as a task being switched away that is not current.
1396 static u32 curr_pid
[MAX_CPUS
] = { [0 ... MAX_CPUS
-1] = -1 };
1398 static struct thread
*curr_thread
[MAX_CPUS
];
1400 static char next_shortname1
= 'A';
1401 static char next_shortname2
= '0';
1404 map_switch_event(struct trace_switch_event
*switch_event
,
1405 struct machine
*machine
,
1406 struct event_format
*event __used
,
1409 struct thread
*thread __used
)
1411 struct thread
*sched_out __used
, *sched_in
;
1417 BUG_ON(this_cpu
>= MAX_CPUS
|| this_cpu
< 0);
1419 if (this_cpu
> max_cpu
)
1422 timestamp0
= cpu_last_switched
[this_cpu
];
1423 cpu_last_switched
[this_cpu
] = timestamp
;
1425 delta
= timestamp
- timestamp0
;
1430 die("hm, delta: %" PRIu64
" < 0 ?\n", delta
);
1433 sched_out
= machine__findnew_thread(machine
, switch_event
->prev_pid
);
1434 sched_in
= machine__findnew_thread(machine
, switch_event
->next_pid
);
1436 curr_thread
[this_cpu
] = sched_in
;
1441 if (!sched_in
->shortname
[0]) {
1442 sched_in
->shortname
[0] = next_shortname1
;
1443 sched_in
->shortname
[1] = next_shortname2
;
1445 if (next_shortname1
< 'Z') {
1448 next_shortname1
='A';
1449 if (next_shortname2
< '9') {
1452 next_shortname2
='0';
1458 for (cpu
= 0; cpu
<= max_cpu
; cpu
++) {
1459 if (cpu
!= this_cpu
)
1464 if (curr_thread
[cpu
]) {
1465 if (curr_thread
[cpu
]->pid
)
1466 printf("%2s ", curr_thread
[cpu
]->shortname
);
1473 printf(" %12.6f secs ", (double)timestamp
/1e9
);
1474 if (new_shortname
) {
1475 printf("%s => %s:%d\n",
1476 sched_in
->shortname
, sched_in
->comm
, sched_in
->pid
);
1483 process_sched_switch_event(struct perf_tool
*tool __used
,
1484 struct event_format
*event
,
1485 struct perf_sample
*sample
,
1486 struct machine
*machine
,
1487 struct thread
*thread
)
1489 int this_cpu
= sample
->cpu
;
1490 void *data
= sample
->raw_data
;
1491 struct trace_switch_event switch_event
;
1493 FILL_COMMON_FIELDS(switch_event
, event
, data
);
1495 FILL_ARRAY(switch_event
, prev_comm
, event
, data
);
1496 FILL_FIELD(switch_event
, prev_pid
, event
, data
);
1497 FILL_FIELD(switch_event
, prev_prio
, event
, data
);
1498 FILL_FIELD(switch_event
, prev_state
, event
, data
);
1499 FILL_ARRAY(switch_event
, next_comm
, event
, data
);
1500 FILL_FIELD(switch_event
, next_pid
, event
, data
);
1501 FILL_FIELD(switch_event
, next_prio
, event
, data
);
1503 if (curr_pid
[this_cpu
] != (u32
)-1) {
1505 * Are we trying to switch away a PID that is
1508 if (curr_pid
[this_cpu
] != switch_event
.prev_pid
)
1509 nr_context_switch_bugs
++;
1511 if (trace_handler
->switch_event
)
1512 trace_handler
->switch_event(&switch_event
, machine
, event
,
1513 this_cpu
, sample
->time
, thread
);
1515 curr_pid
[this_cpu
] = switch_event
.next_pid
;
1519 process_sched_runtime_event(struct perf_tool
*tool __used
,
1520 struct event_format
*event
,
1521 struct perf_sample
*sample
,
1522 struct machine
*machine
,
1523 struct thread
*thread
)
1525 void *data
= sample
->raw_data
;
1526 struct trace_runtime_event runtime_event
;
1528 FILL_ARRAY(runtime_event
, comm
, event
, data
);
1529 FILL_FIELD(runtime_event
, pid
, event
, data
);
1530 FILL_FIELD(runtime_event
, runtime
, event
, data
);
1531 FILL_FIELD(runtime_event
, vruntime
, event
, data
);
1533 if (trace_handler
->runtime_event
)
1534 trace_handler
->runtime_event(&runtime_event
, machine
, event
,
1535 sample
->cpu
, sample
->time
, thread
);
1539 process_sched_fork_event(struct perf_tool
*tool __used
,
1540 struct event_format
*event
,
1541 struct perf_sample
*sample
,
1542 struct machine
*machine __used
,
1543 struct thread
*thread
)
1545 void *data
= sample
->raw_data
;
1546 struct trace_fork_event fork_event
;
1548 FILL_COMMON_FIELDS(fork_event
, event
, data
);
1550 FILL_ARRAY(fork_event
, parent_comm
, event
, data
);
1551 FILL_FIELD(fork_event
, parent_pid
, event
, data
);
1552 FILL_ARRAY(fork_event
, child_comm
, event
, data
);
1553 FILL_FIELD(fork_event
, child_pid
, event
, data
);
1555 if (trace_handler
->fork_event
)
1556 trace_handler
->fork_event(&fork_event
, event
,
1557 sample
->cpu
, sample
->time
, thread
);
1561 process_sched_exit_event(struct perf_tool
*tool __used
,
1562 struct event_format
*event
,
1563 struct perf_sample
*sample __used
,
1564 struct machine
*machine __used
,
1565 struct thread
*thread __used
)
1568 printf("sched_exit event %p\n", event
);
1572 process_sched_migrate_task_event(struct perf_tool
*tool __used
,
1573 struct event_format
*event
,
1574 struct perf_sample
*sample
,
1575 struct machine
*machine
,
1576 struct thread
*thread
)
1578 void *data
= sample
->raw_data
;
1579 struct trace_migrate_task_event migrate_task_event
;
1581 FILL_COMMON_FIELDS(migrate_task_event
, event
, data
);
1583 FILL_ARRAY(migrate_task_event
, comm
, event
, data
);
1584 FILL_FIELD(migrate_task_event
, pid
, event
, data
);
1585 FILL_FIELD(migrate_task_event
, prio
, event
, data
);
1586 FILL_FIELD(migrate_task_event
, cpu
, event
, data
);
1588 if (trace_handler
->migrate_task_event
)
1589 trace_handler
->migrate_task_event(&migrate_task_event
, machine
,
1591 sample
->time
, thread
);
1594 typedef void (*tracepoint_handler
)(struct perf_tool
*tool
, struct event_format
*event
,
1595 struct perf_sample
*sample
,
1596 struct machine
*machine
,
1597 struct thread
*thread
);
1599 static int perf_sched__process_tracepoint_sample(struct perf_tool
*tool
,
1600 union perf_event
*event __used
,
1601 struct perf_sample
*sample
,
1602 struct perf_evsel
*evsel
,
1603 struct machine
*machine
)
1605 struct perf_sched
*sched
= container_of(tool
, struct perf_sched
, tool
);
1606 struct pevent
*pevent
= sched
->session
->pevent
;
1607 struct thread
*thread
= machine__findnew_thread(machine
, sample
->pid
);
1609 if (thread
== NULL
) {
1610 pr_debug("problem processing %s event, skipping it.\n",
1611 perf_evsel__name(evsel
));
1615 evsel
->hists
.stats
.total_period
+= sample
->period
;
1616 hists__inc_nr_events(&evsel
->hists
, PERF_RECORD_SAMPLE
);
1618 if (evsel
->handler
.func
!= NULL
) {
1619 tracepoint_handler f
= evsel
->handler
.func
;
1621 if (evsel
->handler
.data
== NULL
)
1622 evsel
->handler
.data
= pevent_find_event(pevent
,
1623 evsel
->attr
.config
);
1625 f(tool
, evsel
->handler
.data
, sample
, machine
, thread
);
1631 static struct perf_sched perf_sched
= {
1633 .sample
= perf_sched__process_tracepoint_sample
,
1634 .comm
= perf_event__process_comm
,
1635 .lost
= perf_event__process_lost
,
1636 .fork
= perf_event__process_task
,
1637 .ordered_samples
= true,
1641 static void read_events(bool destroy
, struct perf_session
**psession
)
1644 const struct perf_evsel_str_handler handlers
[] = {
1645 { "sched:sched_switch", process_sched_switch_event
, },
1646 { "sched:sched_stat_runtime", process_sched_runtime_event
, },
1647 { "sched:sched_wakeup", process_sched_wakeup_event
, },
1648 { "sched:sched_wakeup_new", process_sched_wakeup_event
, },
1649 { "sched:sched_process_fork", process_sched_fork_event
, },
1650 { "sched:sched_process_exit", process_sched_exit_event
, },
1651 { "sched:sched_migrate_task", process_sched_migrate_task_event
, },
1653 struct perf_session
*session
;
1655 session
= perf_session__new(input_name
, O_RDONLY
, 0, false,
1657 if (session
== NULL
)
1660 perf_sched
.session
= session
;
1662 err
= perf_session__set_tracepoints_handlers(session
, handlers
);
1665 if (perf_session__has_traces(session
, "record -R")) {
1666 err
= perf_session__process_events(session
, &perf_sched
.tool
);
1668 die("Failed to process events, error %d", err
);
1670 nr_events
= session
->hists
.stats
.nr_events
[0];
1671 nr_lost_events
= session
->hists
.stats
.total_lost
;
1672 nr_lost_chunks
= session
->hists
.stats
.nr_events
[PERF_RECORD_LOST
];
1676 perf_session__delete(session
);
1679 *psession
= session
;
1682 static void print_bad_events(void)
1684 if (nr_unordered_timestamps
&& nr_timestamps
) {
1685 printf(" INFO: %.3f%% unordered timestamps (%ld out of %ld)\n",
1686 (double)nr_unordered_timestamps
/(double)nr_timestamps
*100.0,
1687 nr_unordered_timestamps
, nr_timestamps
);
1689 if (nr_lost_events
&& nr_events
) {
1690 printf(" INFO: %.3f%% lost events (%ld out of %ld, in %ld chunks)\n",
1691 (double)nr_lost_events
/(double)nr_events
*100.0,
1692 nr_lost_events
, nr_events
, nr_lost_chunks
);
1694 if (nr_state_machine_bugs
&& nr_timestamps
) {
1695 printf(" INFO: %.3f%% state machine bugs (%ld out of %ld)",
1696 (double)nr_state_machine_bugs
/(double)nr_timestamps
*100.0,
1697 nr_state_machine_bugs
, nr_timestamps
);
1699 printf(" (due to lost events?)");
1702 if (nr_context_switch_bugs
&& nr_timestamps
) {
1703 printf(" INFO: %.3f%% context switch bugs (%ld out of %ld)",
1704 (double)nr_context_switch_bugs
/(double)nr_timestamps
*100.0,
1705 nr_context_switch_bugs
, nr_timestamps
);
1707 printf(" (due to lost events?)");
1712 static void __cmd_lat(void)
1714 struct rb_node
*next
;
1715 struct perf_session
*session
;
1718 read_events(false, &session
);
1721 printf("\n ---------------------------------------------------------------------------------------------------------------\n");
1722 printf(" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n");
1723 printf(" ---------------------------------------------------------------------------------------------------------------\n");
1725 next
= rb_first(&sorted_atom_root
);
1728 struct work_atoms
*work_list
;
1730 work_list
= rb_entry(next
, struct work_atoms
, node
);
1731 output_lat_thread(work_list
);
1732 next
= rb_next(next
);
1735 printf(" -----------------------------------------------------------------------------------------\n");
1736 printf(" TOTAL: |%11.3f ms |%9" PRIu64
" |\n",
1737 (double)all_runtime
/1e6
, all_count
);
1739 printf(" ---------------------------------------------------\n");
1744 perf_session__delete(session
);
1747 static struct trace_sched_handler map_ops
= {
1748 .wakeup_event
= NULL
,
1749 .switch_event
= map_switch_event
,
1750 .runtime_event
= NULL
,
1754 static void __cmd_map(void)
1756 max_cpu
= sysconf(_SC_NPROCESSORS_CONF
);
1759 read_events(true, NULL
);
1763 static void __cmd_replay(void)
1767 calibrate_run_measurement_overhead();
1768 calibrate_sleep_measurement_overhead();
1770 test_calibrations();
1772 read_events(true, NULL
);
1774 printf("nr_run_events: %ld\n", nr_run_events
);
1775 printf("nr_sleep_events: %ld\n", nr_sleep_events
);
1776 printf("nr_wakeup_events: %ld\n", nr_wakeup_events
);
1778 if (targetless_wakeups
)
1779 printf("target-less wakeups: %ld\n", targetless_wakeups
);
1780 if (multitarget_wakeups
)
1781 printf("multi-target wakeups: %ld\n", multitarget_wakeups
);
1782 if (nr_run_events_optimized
)
1783 printf("run atoms optimized: %ld\n",
1784 nr_run_events_optimized
);
1786 print_task_traces();
1787 add_cross_task_wakeups();
1790 printf("------------------------------------------------------------\n");
1791 for (i
= 0; i
< replay_repeat
; i
++)
1796 static const char * const sched_usage
[] = {
1797 "perf sched [<options>] {record|latency|map|replay|script}",
1801 static const struct option sched_options
[] = {
1802 OPT_STRING('i', "input", &input_name
, "file",
1804 OPT_INCR('v', "verbose", &verbose
,
1805 "be more verbose (show symbol address, etc)"),
1806 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1807 "dump raw trace in ASCII"),
1811 static const char * const latency_usage
[] = {
1812 "perf sched latency [<options>]",
1816 static const struct option latency_options
[] = {
1817 OPT_STRING('s', "sort", &sort_order
, "key[,key2...]",
1818 "sort by key(s): runtime, switch, avg, max"),
1819 OPT_INCR('v', "verbose", &verbose
,
1820 "be more verbose (show symbol address, etc)"),
1821 OPT_INTEGER('C', "CPU", &profile_cpu
,
1822 "CPU to profile on"),
1823 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1824 "dump raw trace in ASCII"),
1828 static const char * const replay_usage
[] = {
1829 "perf sched replay [<options>]",
1833 static const struct option replay_options
[] = {
1834 OPT_UINTEGER('r', "repeat", &replay_repeat
,
1835 "repeat the workload replay N times (-1: infinite)"),
1836 OPT_INCR('v', "verbose", &verbose
,
1837 "be more verbose (show symbol address, etc)"),
1838 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
1839 "dump raw trace in ASCII"),
1843 static void setup_sorting(void)
1845 char *tmp
, *tok
, *str
= strdup(sort_order
);
1847 for (tok
= strtok_r(str
, ", ", &tmp
);
1848 tok
; tok
= strtok_r(NULL
, ", ", &tmp
)) {
1849 if (sort_dimension__add(tok
, &sort_list
) < 0) {
1850 error("Unknown --sort key: `%s'", tok
);
1851 usage_with_options(latency_usage
, latency_options
);
1857 sort_dimension__add("pid", &cmp_pid
);
1860 static const char *record_args
[] = {
1867 "-e", "sched:sched_switch",
1868 "-e", "sched:sched_stat_wait",
1869 "-e", "sched:sched_stat_sleep",
1870 "-e", "sched:sched_stat_iowait",
1871 "-e", "sched:sched_stat_runtime",
1872 "-e", "sched:sched_process_exit",
1873 "-e", "sched:sched_process_fork",
1874 "-e", "sched:sched_wakeup",
1875 "-e", "sched:sched_migrate_task",
1878 static int __cmd_record(int argc
, const char **argv
)
1880 unsigned int rec_argc
, i
, j
;
1881 const char **rec_argv
;
1883 rec_argc
= ARRAY_SIZE(record_args
) + argc
- 1;
1884 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
1886 if (rec_argv
== NULL
)
1889 for (i
= 0; i
< ARRAY_SIZE(record_args
); i
++)
1890 rec_argv
[i
] = strdup(record_args
[i
]);
1892 for (j
= 1; j
< (unsigned int)argc
; j
++, i
++)
1893 rec_argv
[i
] = argv
[j
];
1895 BUG_ON(i
!= rec_argc
);
1897 return cmd_record(i
, rec_argv
, NULL
);
1900 int cmd_sched(int argc
, const char **argv
, const char *prefix __used
)
1902 argc
= parse_options(argc
, argv
, sched_options
, sched_usage
,
1903 PARSE_OPT_STOP_AT_NON_OPTION
);
1905 usage_with_options(sched_usage
, sched_options
);
1908 * Aliased to 'perf script' for now:
1910 if (!strcmp(argv
[0], "script"))
1911 return cmd_script(argc
, argv
, prefix
);
1914 if (!strncmp(argv
[0], "rec", 3)) {
1915 return __cmd_record(argc
, argv
);
1916 } else if (!strncmp(argv
[0], "lat", 3)) {
1917 trace_handler
= &lat_ops
;
1919 argc
= parse_options(argc
, argv
, latency_options
, latency_usage
, 0);
1921 usage_with_options(latency_usage
, latency_options
);
1925 } else if (!strcmp(argv
[0], "map")) {
1926 trace_handler
= &map_ops
;
1929 } else if (!strncmp(argv
[0], "rep", 3)) {
1930 trace_handler
= &replay_ops
;
1932 argc
= parse_options(argc
, argv
, replay_options
, replay_usage
, 0);
1934 usage_with_options(replay_usage
, replay_options
);
1938 usage_with_options(sched_usage
, sched_options
);