blob: 142b3033e4be5a2f92c522848a65293cf3fc6c51 [file] [log] [blame]
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +09001#include "builtin.h"
2#include "perf.h"
3
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -03004#include "util/evsel.h"
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +09005#include "util/util.h"
6#include "util/cache.h"
7#include "util/symbol.h"
8#include "util/thread.h"
9#include "util/header.h"
10
11#include "util/parse-options.h"
12#include "util/trace-event.h"
13
14#include "util/debug.h"
15#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020016#include "util/tool.h"
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090017
18#include <sys/types.h>
19#include <sys/prctl.h>
20#include <semaphore.h>
21#include <pthread.h>
22#include <math.h>
23#include <limits.h>
24
25#include <linux/list.h>
26#include <linux/hash.h>
27
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +090028static struct perf_session *session;
29
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090030/* based on kernel/lockdep.c */
31#define LOCKHASH_BITS 12
32#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS)
33
34static struct list_head lockhash_table[LOCKHASH_SIZE];
35
36#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS)
37#define lockhashentry(key) (lockhash_table + __lockhashfn((key)))
38
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090039struct lock_stat {
Ingo Molnar59f411b2010-01-31 08:27:58 +010040 struct list_head hash_entry;
41 struct rb_node rb; /* used for sorting */
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090042
Ingo Molnar59f411b2010-01-31 08:27:58 +010043 /*
44 * FIXME: raw_field_value() returns unsigned long long,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090045 * so address of lockdep_map should be dealed as 64bit.
Ingo Molnar59f411b2010-01-31 08:27:58 +010046 * Is there more better solution?
47 */
48 void *addr; /* address of lockdep_map, used as ID */
49 char *name; /* for strcpy(), we cannot use const */
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090050
Ingo Molnar59f411b2010-01-31 08:27:58 +010051 unsigned int nr_acquire;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +090052 unsigned int nr_acquired;
Ingo Molnar59f411b2010-01-31 08:27:58 +010053 unsigned int nr_contended;
54 unsigned int nr_release;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090055
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +090056 unsigned int nr_readlock;
57 unsigned int nr_trylock;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090058 /* these times are in nano sec. */
Ingo Molnar59f411b2010-01-31 08:27:58 +010059 u64 wait_time_total;
60 u64 wait_time_min;
61 u64 wait_time_max;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +090062
63 int discard; /* flag of blacklist */
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +090064};
65
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +090066/*
67 * States of lock_seq_stat
68 *
69 * UNINITIALIZED is required for detecting first event of acquire.
70 * As the nature of lock events, there is no guarantee
71 * that the first event for the locks are acquire,
72 * it can be acquired, contended or release.
73 */
74#define SEQ_STATE_UNINITIALIZED 0 /* initial state */
75#define SEQ_STATE_RELEASED 1
76#define SEQ_STATE_ACQUIRING 2
77#define SEQ_STATE_ACQUIRED 3
78#define SEQ_STATE_READ_ACQUIRED 4
79#define SEQ_STATE_CONTENDED 5
80
81/*
82 * MAX_LOCK_DEPTH
83 * Imported from include/linux/sched.h.
84 * Should this be synchronized?
85 */
86#define MAX_LOCK_DEPTH 48
87
88/*
89 * struct lock_seq_stat:
90 * Place to put on state of one lock sequence
91 * 1) acquire -> acquired -> release
92 * 2) acquire -> contended -> acquired -> release
93 * 3) acquire (with read or try) -> release
94 * 4) Are there other patterns?
95 */
96struct lock_seq_stat {
97 struct list_head list;
98 int state;
99 u64 prev_event_time;
100 void *addr;
101
102 int read_count;
103};
104
105struct thread_stat {
106 struct rb_node rb;
107
108 u32 tid;
109 struct list_head seq_list;
110};
111
112static struct rb_root thread_stats;
113
114static struct thread_stat *thread_stat_find(u32 tid)
115{
116 struct rb_node *node;
117 struct thread_stat *st;
118
119 node = thread_stats.rb_node;
120 while (node) {
121 st = container_of(node, struct thread_stat, rb);
122 if (st->tid == tid)
123 return st;
124 else if (tid < st->tid)
125 node = node->rb_left;
126 else
127 node = node->rb_right;
128 }
129
130 return NULL;
131}
132
133static void thread_stat_insert(struct thread_stat *new)
134{
135 struct rb_node **rb = &thread_stats.rb_node;
136 struct rb_node *parent = NULL;
137 struct thread_stat *p;
138
139 while (*rb) {
140 p = container_of(*rb, struct thread_stat, rb);
141 parent = *rb;
142
143 if (new->tid < p->tid)
144 rb = &(*rb)->rb_left;
145 else if (new->tid > p->tid)
146 rb = &(*rb)->rb_right;
147 else
148 BUG_ON("inserting invalid thread_stat\n");
149 }
150
151 rb_link_node(&new->rb, parent, rb);
152 rb_insert_color(&new->rb, &thread_stats);
153}
154
155static struct thread_stat *thread_stat_findnew_after_first(u32 tid)
156{
157 struct thread_stat *st;
158
159 st = thread_stat_find(tid);
160 if (st)
161 return st;
162
163 st = zalloc(sizeof(struct thread_stat));
164 if (!st)
165 die("memory allocation failed\n");
166
167 st->tid = tid;
168 INIT_LIST_HEAD(&st->seq_list);
169
170 thread_stat_insert(st);
171
172 return st;
173}
174
175static struct thread_stat *thread_stat_findnew_first(u32 tid);
176static struct thread_stat *(*thread_stat_findnew)(u32 tid) =
177 thread_stat_findnew_first;
178
179static struct thread_stat *thread_stat_findnew_first(u32 tid)
180{
181 struct thread_stat *st;
182
183 st = zalloc(sizeof(struct thread_stat));
184 if (!st)
185 die("memory allocation failed\n");
186 st->tid = tid;
187 INIT_LIST_HEAD(&st->seq_list);
188
189 rb_link_node(&st->rb, NULL, &thread_stats.rb_node);
190 rb_insert_color(&st->rb, &thread_stats);
191
192 thread_stat_findnew = thread_stat_findnew_after_first;
193 return st;
194}
195
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900196/* build simple key function one is bigger than two */
Ingo Molnar59f411b2010-01-31 08:27:58 +0100197#define SINGLE_KEY(member) \
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900198 static int lock_stat_key_ ## member(struct lock_stat *one, \
199 struct lock_stat *two) \
200 { \
201 return one->member > two->member; \
202 }
203
204SINGLE_KEY(nr_acquired)
205SINGLE_KEY(nr_contended)
206SINGLE_KEY(wait_time_total)
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900207SINGLE_KEY(wait_time_max)
208
Marcin Slusarz9df03ab2011-02-22 18:47:15 +0100209static int lock_stat_key_wait_time_min(struct lock_stat *one,
210 struct lock_stat *two)
211{
212 u64 s1 = one->wait_time_min;
213 u64 s2 = two->wait_time_min;
214 if (s1 == ULLONG_MAX)
215 s1 = 0;
216 if (s2 == ULLONG_MAX)
217 s2 = 0;
218 return s1 > s2;
219}
220
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900221struct lock_key {
222 /*
223 * name: the value for specify by user
224 * this should be simpler than raw name of member
225 * e.g. nr_acquired -> acquired, wait_time_total -> wait_total
226 */
Ingo Molnar59f411b2010-01-31 08:27:58 +0100227 const char *name;
228 int (*key)(struct lock_stat*, struct lock_stat*);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900229};
230
Ingo Molnar59f411b2010-01-31 08:27:58 +0100231static const char *sort_key = "acquired";
232
233static int (*compare)(struct lock_stat *, struct lock_stat *);
234
235static struct rb_root result; /* place to store sorted data */
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900236
237#define DEF_KEY_LOCK(name, fn_suffix) \
238 { #name, lock_stat_key_ ## fn_suffix }
239struct lock_key keys[] = {
240 DEF_KEY_LOCK(acquired, nr_acquired),
241 DEF_KEY_LOCK(contended, nr_contended),
242 DEF_KEY_LOCK(wait_total, wait_time_total),
243 DEF_KEY_LOCK(wait_min, wait_time_min),
244 DEF_KEY_LOCK(wait_max, wait_time_max),
245
246 /* extra comparisons much complicated should be here */
247
248 { NULL, NULL }
249};
250
251static void select_key(void)
252{
253 int i;
254
255 for (i = 0; keys[i].name; i++) {
256 if (!strcmp(keys[i].name, sort_key)) {
257 compare = keys[i].key;
258 return;
259 }
260 }
261
262 die("Unknown compare key:%s\n", sort_key);
263}
264
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900265static void insert_to_result(struct lock_stat *st,
Ingo Molnar59f411b2010-01-31 08:27:58 +0100266 int (*bigger)(struct lock_stat *, struct lock_stat *))
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900267{
268 struct rb_node **rb = &result.rb_node;
269 struct rb_node *parent = NULL;
270 struct lock_stat *p;
271
272 while (*rb) {
273 p = container_of(*rb, struct lock_stat, rb);
274 parent = *rb;
275
276 if (bigger(st, p))
277 rb = &(*rb)->rb_left;
278 else
279 rb = &(*rb)->rb_right;
280 }
281
282 rb_link_node(&st->rb, parent, rb);
283 rb_insert_color(&st->rb, &result);
284}
285
286/* returns left most element of result, and erase it */
287static struct lock_stat *pop_from_result(void)
288{
289 struct rb_node *node = result.rb_node;
290
291 if (!node)
292 return NULL;
293
294 while (node->rb_left)
295 node = node->rb_left;
296
297 rb_erase(node, &result);
298 return container_of(node, struct lock_stat, rb);
299}
300
Ingo Molnar59f411b2010-01-31 08:27:58 +0100301static struct lock_stat *lock_stat_findnew(void *addr, const char *name)
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900302{
303 struct list_head *entry = lockhashentry(addr);
304 struct lock_stat *ret, *new;
305
306 list_for_each_entry(ret, entry, hash_entry) {
307 if (ret->addr == addr)
308 return ret;
309 }
310
311 new = zalloc(sizeof(struct lock_stat));
312 if (!new)
313 goto alloc_failed;
314
315 new->addr = addr;
316 new->name = zalloc(sizeof(char) * strlen(name) + 1);
317 if (!new->name)
318 goto alloc_failed;
319 strcpy(new->name, name);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900320
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900321 new->wait_time_min = ULLONG_MAX;
322
323 list_add(&new->hash_entry, entry);
324 return new;
325
326alloc_failed:
327 die("memory allocation failed\n");
328}
329
Robert Richterefad1412011-12-07 10:02:54 +0100330static const char *input_name;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900331
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900332struct raw_event_sample {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100333 u32 size;
334 char data[0];
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900335};
336
337struct trace_acquire_event {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100338 void *addr;
339 const char *name;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900340 int flag;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900341};
342
343struct trace_acquired_event {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100344 void *addr;
345 const char *name;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900346};
347
348struct trace_contended_event {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100349 void *addr;
350 const char *name;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900351};
352
353struct trace_release_event {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100354 void *addr;
355 const char *name;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900356};
357
358struct trace_lock_handler {
359 void (*acquire_event)(struct trace_acquire_event *,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200360 struct event_format *,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900361 int cpu,
362 u64 timestamp,
363 struct thread *thread);
364
365 void (*acquired_event)(struct trace_acquired_event *,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200366 struct event_format *,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900367 int cpu,
368 u64 timestamp,
369 struct thread *thread);
370
371 void (*contended_event)(struct trace_contended_event *,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200372 struct event_format *,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900373 int cpu,
374 u64 timestamp,
375 struct thread *thread);
376
377 void (*release_event)(struct trace_release_event *,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200378 struct event_format *,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900379 int cpu,
380 u64 timestamp,
381 struct thread *thread);
382};
383
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900384static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr)
385{
386 struct lock_seq_stat *seq;
387
388 list_for_each_entry(seq, &ts->seq_list, list) {
389 if (seq->addr == addr)
390 return seq;
391 }
392
393 seq = zalloc(sizeof(struct lock_seq_stat));
394 if (!seq)
395 die("Not enough memory\n");
396 seq->state = SEQ_STATE_UNINITIALIZED;
397 seq->addr = addr;
398
399 list_add(&seq->list, &ts->seq_list);
400 return seq;
401}
402
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200403enum broken_state {
404 BROKEN_ACQUIRE,
405 BROKEN_ACQUIRED,
406 BROKEN_CONTENDED,
407 BROKEN_RELEASE,
408 BROKEN_MAX,
409};
410
411static int bad_hist[BROKEN_MAX];
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900412
Frederic Weisbecker84c7a212010-05-05 23:57:25 +0200413enum acquire_flags {
414 TRY_LOCK = 1,
415 READ_LOCK = 2,
416};
417
Ingo Molnar59f411b2010-01-31 08:27:58 +0100418static void
419report_lock_acquire_event(struct trace_acquire_event *acquire_event,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200420 struct event_format *__event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900421 int cpu __used,
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900422 u64 timestamp __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900423 struct thread *thread __used)
424{
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900425 struct lock_stat *ls;
426 struct thread_stat *ts;
427 struct lock_seq_stat *seq;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900428
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900429 ls = lock_stat_findnew(acquire_event->addr, acquire_event->name);
430 if (ls->discard)
431 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900432
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900433 ts = thread_stat_findnew(thread->pid);
434 seq = get_seq(ts, acquire_event->addr);
435
436 switch (seq->state) {
437 case SEQ_STATE_UNINITIALIZED:
438 case SEQ_STATE_RELEASED:
439 if (!acquire_event->flag) {
440 seq->state = SEQ_STATE_ACQUIRING;
441 } else {
Frederic Weisbecker84c7a212010-05-05 23:57:25 +0200442 if (acquire_event->flag & TRY_LOCK)
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900443 ls->nr_trylock++;
Frederic Weisbecker84c7a212010-05-05 23:57:25 +0200444 if (acquire_event->flag & READ_LOCK)
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900445 ls->nr_readlock++;
446 seq->state = SEQ_STATE_READ_ACQUIRED;
447 seq->read_count = 1;
448 ls->nr_acquired++;
449 }
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900450 break;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900451 case SEQ_STATE_READ_ACQUIRED:
Frederic Weisbecker84c7a212010-05-05 23:57:25 +0200452 if (acquire_event->flag & READ_LOCK) {
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900453 seq->read_count++;
454 ls->nr_acquired++;
455 goto end;
456 } else {
457 goto broken;
458 }
459 break;
460 case SEQ_STATE_ACQUIRED:
461 case SEQ_STATE_ACQUIRING:
462 case SEQ_STATE_CONTENDED:
463broken:
464 /* broken lock sequence, discard it */
465 ls->discard = 1;
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200466 bad_hist[BROKEN_ACQUIRE]++;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900467 list_del(&seq->list);
468 free(seq);
469 goto end;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900470 break;
471 default:
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900472 BUG_ON("Unknown state of lock sequence found!\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900473 break;
474 }
475
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900476 ls->nr_acquire++;
477 seq->prev_event_time = timestamp;
478end:
479 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900480}
481
Ingo Molnar59f411b2010-01-31 08:27:58 +0100482static void
483report_lock_acquired_event(struct trace_acquired_event *acquired_event,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200484 struct event_format *__event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900485 int cpu __used,
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900486 u64 timestamp __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900487 struct thread *thread __used)
488{
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900489 struct lock_stat *ls;
490 struct thread_stat *ts;
491 struct lock_seq_stat *seq;
492 u64 contended_term;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900493
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900494 ls = lock_stat_findnew(acquired_event->addr, acquired_event->name);
495 if (ls->discard)
496 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900497
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900498 ts = thread_stat_findnew(thread->pid);
499 seq = get_seq(ts, acquired_event->addr);
500
501 switch (seq->state) {
502 case SEQ_STATE_UNINITIALIZED:
503 /* orphan event, do nothing */
504 return;
505 case SEQ_STATE_ACQUIRING:
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900506 break;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900507 case SEQ_STATE_CONTENDED:
508 contended_term = timestamp - seq->prev_event_time;
509 ls->wait_time_total += contended_term;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900510 if (contended_term < ls->wait_time_min)
511 ls->wait_time_min = contended_term;
Frederic Weisbecker90c0e5f2010-05-07 02:33:42 +0200512 if (ls->wait_time_max < contended_term)
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900513 ls->wait_time_max = contended_term;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900514 break;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900515 case SEQ_STATE_RELEASED:
516 case SEQ_STATE_ACQUIRED:
517 case SEQ_STATE_READ_ACQUIRED:
518 /* broken lock sequence, discard it */
519 ls->discard = 1;
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200520 bad_hist[BROKEN_ACQUIRED]++;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900521 list_del(&seq->list);
522 free(seq);
523 goto end;
524 break;
525
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900526 default:
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900527 BUG_ON("Unknown state of lock sequence found!\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900528 break;
529 }
530
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900531 seq->state = SEQ_STATE_ACQUIRED;
532 ls->nr_acquired++;
533 seq->prev_event_time = timestamp;
534end:
535 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900536}
537
Ingo Molnar59f411b2010-01-31 08:27:58 +0100538static void
539report_lock_contended_event(struct trace_contended_event *contended_event,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200540 struct event_format *__event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900541 int cpu __used,
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900542 u64 timestamp __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900543 struct thread *thread __used)
544{
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900545 struct lock_stat *ls;
546 struct thread_stat *ts;
547 struct lock_seq_stat *seq;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900548
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900549 ls = lock_stat_findnew(contended_event->addr, contended_event->name);
550 if (ls->discard)
551 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900552
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900553 ts = thread_stat_findnew(thread->pid);
554 seq = get_seq(ts, contended_event->addr);
555
556 switch (seq->state) {
557 case SEQ_STATE_UNINITIALIZED:
558 /* orphan event, do nothing */
559 return;
560 case SEQ_STATE_ACQUIRING:
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900561 break;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900562 case SEQ_STATE_RELEASED:
563 case SEQ_STATE_ACQUIRED:
564 case SEQ_STATE_READ_ACQUIRED:
565 case SEQ_STATE_CONTENDED:
566 /* broken lock sequence, discard it */
567 ls->discard = 1;
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200568 bad_hist[BROKEN_CONTENDED]++;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900569 list_del(&seq->list);
570 free(seq);
571 goto end;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900572 break;
573 default:
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900574 BUG_ON("Unknown state of lock sequence found!\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900575 break;
576 }
577
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900578 seq->state = SEQ_STATE_CONTENDED;
579 ls->nr_contended++;
580 seq->prev_event_time = timestamp;
581end:
582 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900583}
584
Ingo Molnar59f411b2010-01-31 08:27:58 +0100585static void
586report_lock_release_event(struct trace_release_event *release_event,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200587 struct event_format *__event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900588 int cpu __used,
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900589 u64 timestamp __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900590 struct thread *thread __used)
591{
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900592 struct lock_stat *ls;
593 struct thread_stat *ts;
594 struct lock_seq_stat *seq;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900595
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900596 ls = lock_stat_findnew(release_event->addr, release_event->name);
597 if (ls->discard)
598 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900599
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900600 ts = thread_stat_findnew(thread->pid);
601 seq = get_seq(ts, release_event->addr);
602
603 switch (seq->state) {
604 case SEQ_STATE_UNINITIALIZED:
605 goto end;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900606 break;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900607 case SEQ_STATE_ACQUIRED:
608 break;
609 case SEQ_STATE_READ_ACQUIRED:
610 seq->read_count--;
611 BUG_ON(seq->read_count < 0);
612 if (!seq->read_count) {
613 ls->nr_release++;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900614 goto end;
615 }
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900616 break;
617 case SEQ_STATE_ACQUIRING:
618 case SEQ_STATE_CONTENDED:
619 case SEQ_STATE_RELEASED:
620 /* broken lock sequence, discard it */
621 ls->discard = 1;
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200622 bad_hist[BROKEN_RELEASE]++;
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900623 goto free_seq;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900624 break;
625 default:
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900626 BUG_ON("Unknown state of lock sequence found!\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900627 break;
628 }
629
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900630 ls->nr_release++;
631free_seq:
632 list_del(&seq->list);
633 free(seq);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900634end:
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900635 return;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900636}
637
638/* lock oriented handlers */
639/* TODO: handlers for CPU oriented, thread oriented */
Ingo Molnar59f411b2010-01-31 08:27:58 +0100640static struct trace_lock_handler report_lock_ops = {
641 .acquire_event = report_lock_acquire_event,
642 .acquired_event = report_lock_acquired_event,
643 .contended_event = report_lock_contended_event,
644 .release_event = report_lock_release_event,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900645};
646
647static struct trace_lock_handler *trace_handler;
648
649static void
650process_lock_acquire_event(void *data,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200651 struct event_format *event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900652 int cpu __used,
653 u64 timestamp __used,
654 struct thread *thread __used)
655{
656 struct trace_acquire_event acquire_event;
657 u64 tmp; /* this is required for casting... */
658
659 tmp = raw_field_value(event, "lockdep_addr", data);
660 memcpy(&acquire_event.addr, &tmp, sizeof(void *));
661 acquire_event.name = (char *)raw_field_ptr(event, "name", data);
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900662 acquire_event.flag = (int)raw_field_value(event, "flag", data);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900663
Ingo Molnar59f411b2010-01-31 08:27:58 +0100664 if (trace_handler->acquire_event)
665 trace_handler->acquire_event(&acquire_event, event, cpu, timestamp, thread);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900666}
667
668static void
669process_lock_acquired_event(void *data,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200670 struct event_format *event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900671 int cpu __used,
672 u64 timestamp __used,
673 struct thread *thread __used)
674{
675 struct trace_acquired_event acquired_event;
676 u64 tmp; /* this is required for casting... */
677
678 tmp = raw_field_value(event, "lockdep_addr", data);
679 memcpy(&acquired_event.addr, &tmp, sizeof(void *));
680 acquired_event.name = (char *)raw_field_ptr(event, "name", data);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900681
Ingo Molnar59f411b2010-01-31 08:27:58 +0100682 if (trace_handler->acquire_event)
683 trace_handler->acquired_event(&acquired_event, event, cpu, timestamp, thread);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900684}
685
686static void
687process_lock_contended_event(void *data,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200688 struct event_format *event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900689 int cpu __used,
690 u64 timestamp __used,
691 struct thread *thread __used)
692{
693 struct trace_contended_event contended_event;
694 u64 tmp; /* this is required for casting... */
695
696 tmp = raw_field_value(event, "lockdep_addr", data);
697 memcpy(&contended_event.addr, &tmp, sizeof(void *));
698 contended_event.name = (char *)raw_field_ptr(event, "name", data);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900699
Ingo Molnar59f411b2010-01-31 08:27:58 +0100700 if (trace_handler->acquire_event)
701 trace_handler->contended_event(&contended_event, event, cpu, timestamp, thread);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900702}
703
704static void
705process_lock_release_event(void *data,
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200706 struct event_format *event __used,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900707 int cpu __used,
708 u64 timestamp __used,
709 struct thread *thread __used)
710{
711 struct trace_release_event release_event;
712 u64 tmp; /* this is required for casting... */
713
714 tmp = raw_field_value(event, "lockdep_addr", data);
715 memcpy(&release_event.addr, &tmp, sizeof(void *));
716 release_event.name = (char *)raw_field_ptr(event, "name", data);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900717
Ingo Molnar59f411b2010-01-31 08:27:58 +0100718 if (trace_handler->acquire_event)
719 trace_handler->release_event(&release_event, event, cpu, timestamp, thread);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900720}
721
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300722static void process_raw_event(struct perf_evsel *evsel, void *data, int cpu,
723 u64 timestamp, struct thread *thread)
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900724{
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300725 struct event_format *event = evsel->tp_format;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900726
727 if (!strcmp(event->name, "lock_acquire"))
728 process_lock_acquire_event(data, event, cpu, timestamp, thread);
729 if (!strcmp(event->name, "lock_acquired"))
730 process_lock_acquired_event(data, event, cpu, timestamp, thread);
731 if (!strcmp(event->name, "lock_contended"))
732 process_lock_contended_event(data, event, cpu, timestamp, thread);
733 if (!strcmp(event->name, "lock_release"))
734 process_lock_release_event(data, event, cpu, timestamp, thread);
735}
736
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200737static void print_bad_events(int bad, int total)
738{
739 /* Output for debug, this have to be removed */
740 int i;
741 const char *name[4] =
742 { "acquire", "acquired", "contended", "release" };
743
744 pr_info("\n=== output for debug===\n\n");
Frederic Weisbecker5efe08c2010-05-06 04:55:22 +0200745 pr_info("bad: %d, total: %d\n", bad, total);
746 pr_info("bad rate: %f %%\n", (double)bad / (double)total * 100);
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200747 pr_info("histogram of events caused bad sequence\n");
748 for (i = 0; i < BROKEN_MAX; i++)
749 pr_info(" %10s: %d\n", name[i], bad_hist[i]);
750}
751
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900752/* TODO: various way to print, coloring, nano or milli sec */
753static void print_result(void)
754{
755 struct lock_stat *st;
756 char cut_name[20];
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900757 int bad, total;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900758
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900759 pr_info("%20s ", "Name");
760 pr_info("%10s ", "acquired");
761 pr_info("%10s ", "contended");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900762
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900763 pr_info("%15s ", "total wait (ns)");
764 pr_info("%15s ", "max wait (ns)");
765 pr_info("%15s ", "min wait (ns)");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900766
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900767 pr_info("\n\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900768
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900769 bad = total = 0;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900770 while ((st = pop_from_result())) {
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900771 total++;
772 if (st->discard) {
773 bad++;
774 continue;
775 }
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900776 bzero(cut_name, 20);
777
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900778 if (strlen(st->name) < 16) {
779 /* output raw name */
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900780 pr_info("%20s ", st->name);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900781 } else {
782 strncpy(cut_name, st->name, 16);
783 cut_name[16] = '.';
784 cut_name[17] = '.';
785 cut_name[18] = '.';
786 cut_name[19] = '\0';
787 /* cut off name for saving output style */
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900788 pr_info("%20s ", cut_name);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900789 }
790
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900791 pr_info("%10u ", st->nr_acquired);
792 pr_info("%10u ", st->nr_contended);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900793
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200794 pr_info("%15" PRIu64 " ", st->wait_time_total);
795 pr_info("%15" PRIu64 " ", st->wait_time_max);
796 pr_info("%15" PRIu64 " ", st->wait_time_min == ULLONG_MAX ?
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900797 0 : st->wait_time_min);
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900798 pr_info("\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900799 }
Hitoshi Mitakee4cef1f2010-04-21 21:23:54 +0900800
Frederic Weisbecker10350ec2010-05-05 23:47:28 +0200801 print_bad_events(bad, total);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900802}
803
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300804static bool info_threads, info_map;
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900805
806static void dump_threads(void)
807{
808 struct thread_stat *st;
809 struct rb_node *node;
810 struct thread *t;
811
812 pr_info("%10s: comm\n", "Thread ID");
813
814 node = rb_first(&thread_stats);
815 while (node) {
816 st = container_of(node, struct thread_stat, rb);
817 t = perf_session__findnew(session, st->tid);
818 pr_info("%10d: %s\n", st->tid, t->comm);
819 node = rb_next(node);
820 };
821}
822
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900823static void dump_map(void)
824{
825 unsigned int i;
826 struct lock_stat *st;
827
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900828 pr_info("Address of instance: name of class\n");
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900829 for (i = 0; i < LOCKHASH_SIZE; i++) {
830 list_for_each_entry(st, &lockhash_table[i], hash_entry) {
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900831 pr_info(" %p: %s\n", st->addr, st->name);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900832 }
833 }
834}
835
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900836static void dump_info(void)
837{
838 if (info_threads)
839 dump_threads();
840 else if (info_map)
841 dump_map();
842 else
843 die("Unknown type of information\n");
844}
845
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200846static int process_sample_event(struct perf_tool *tool __used,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200847 union perf_event *event,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300848 struct perf_sample *sample,
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300849 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200850 struct machine *machine)
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200851{
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200852 struct thread *thread = machine__findnew_thread(machine, sample->tid);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200853
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200854 if (thread == NULL) {
855 pr_debug("problem processing %d event, skipping it.\n",
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200856 event->header.type);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200857 return -1;
858 }
859
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300860 process_raw_event(evsel, sample->raw_data, sample->cpu, sample->time, thread);
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200861
862 return 0;
863}
864
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200865static struct perf_tool eops = {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100866 .sample = process_sample_event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200867 .comm = perf_event__process_comm,
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +0200868 .ordered_samples = true,
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900869};
870
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900871static int read_events(void)
872{
Ian Munsie21ef97f2010-12-10 14:09:16 +1100873 session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900874 if (!session)
875 die("Initializing perf session failed\n");
876
877 return perf_session__process_events(session, &eops);
878}
879
880static void sort_result(void)
881{
882 unsigned int i;
883 struct lock_stat *st;
884
885 for (i = 0; i < LOCKHASH_SIZE; i++) {
886 list_for_each_entry(st, &lockhash_table[i], hash_entry) {
887 insert_to_result(st, compare);
888 }
889 }
890}
891
Ingo Molnar59f411b2010-01-31 08:27:58 +0100892static void __cmd_report(void)
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900893{
894 setup_pager();
895 select_key();
896 read_events();
897 sort_result();
898 print_result();
899}
900
Ingo Molnar59f411b2010-01-31 08:27:58 +0100901static const char * const report_usage[] = {
902 "perf lock report [<options>]",
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900903 NULL
904};
905
Ingo Molnar59f411b2010-01-31 08:27:58 +0100906static const struct option report_options[] = {
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900907 OPT_STRING('k', "key", &sort_key, "acquired",
Marcin Slusarz9826e832011-02-22 21:53:12 +0100908 "key for sorting (acquired / contended / wait_total / wait_max / wait_min)"),
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900909 /* TODO: type */
910 OPT_END()
911};
912
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900913static const char * const info_usage[] = {
914 "perf lock info [<options>]",
915 NULL
916};
917
918static const struct option info_options[] = {
919 OPT_BOOLEAN('t', "threads", &info_threads,
920 "dump thread list in perf.data"),
921 OPT_BOOLEAN('m', "map", &info_map,
Namhyung Kimd1eec3e2012-01-29 17:55:56 +0900922 "map of lock instances (address:name table)"),
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900923 OPT_END()
924};
925
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900926static const char * const lock_usage[] = {
Namhyung Kimd1eec3e2012-01-29 17:55:56 +0900927 "perf lock [<options>] {record|report|script|info}",
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900928 NULL
929};
930
931static const struct option lock_options[] = {
Ingo Molnar59f411b2010-01-31 08:27:58 +0100932 OPT_STRING('i', "input", &input_name, "file", "input file name"),
Ian Munsiec0555642010-04-13 18:37:33 +1000933 OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
Ingo Molnar59f411b2010-01-31 08:27:58 +0100934 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900935 OPT_END()
936};
937
938static const char *record_args[] = {
939 "record",
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900940 "-R",
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900941 "-f",
942 "-m", "1024",
943 "-c", "1",
Zhu Yanhaicf8dc9f2011-07-30 22:13:52 +0800944 "-e", "lock:lock_acquire",
945 "-e", "lock:lock_acquired",
946 "-e", "lock:lock_contended",
947 "-e", "lock:lock_release",
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900948};
949
950static int __cmd_record(int argc, const char **argv)
951{
952 unsigned int rec_argc, i, j;
953 const char **rec_argv;
954
955 rec_argc = ARRAY_SIZE(record_args) + argc - 1;
956 rec_argv = calloc(rec_argc + 1, sizeof(char *));
957
Chris Samuelce47dc52010-11-13 13:35:06 +1100958 if (rec_argv == NULL)
959 return -ENOMEM;
960
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900961 for (i = 0; i < ARRAY_SIZE(record_args); i++)
962 rec_argv[i] = strdup(record_args[i]);
963
964 for (j = 1; j < (unsigned int)argc; j++, i++)
965 rec_argv[i] = argv[j];
966
967 BUG_ON(i != rec_argc);
968
969 return cmd_record(i, rec_argv, NULL);
970}
971
972int cmd_lock(int argc, const char **argv, const char *prefix __used)
973{
974 unsigned int i;
975
976 symbol__init();
977 for (i = 0; i < LOCKHASH_SIZE; i++)
978 INIT_LIST_HEAD(lockhash_table + i);
979
980 argc = parse_options(argc, argv, lock_options, lock_usage,
981 PARSE_OPT_STOP_AT_NON_OPTION);
982 if (!argc)
983 usage_with_options(lock_usage, lock_options);
984
985 if (!strncmp(argv[0], "rec", 3)) {
986 return __cmd_record(argc, argv);
Ingo Molnar59f411b2010-01-31 08:27:58 +0100987 } else if (!strncmp(argv[0], "report", 6)) {
988 trace_handler = &report_lock_ops;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900989 if (argc) {
990 argc = parse_options(argc, argv,
Ingo Molnar59f411b2010-01-31 08:27:58 +0100991 report_options, report_usage, 0);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900992 if (argc)
Ingo Molnar59f411b2010-01-31 08:27:58 +0100993 usage_with_options(report_usage, report_options);
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +0900994 }
Ingo Molnar59f411b2010-01-31 08:27:58 +0100995 __cmd_report();
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100996 } else if (!strcmp(argv[0], "script")) {
997 /* Aliased to 'perf script' */
998 return cmd_script(argc, argv, prefix);
Hitoshi Mitake26242d82010-05-03 14:12:00 +0900999 } else if (!strcmp(argv[0], "info")) {
1000 if (argc) {
1001 argc = parse_options(argc, argv,
1002 info_options, info_usage, 0);
1003 if (argc)
1004 usage_with_options(info_usage, info_options);
1005 }
Ingo Molnar59f411b2010-01-31 08:27:58 +01001006 /* recycling report_lock_ops */
1007 trace_handler = &report_lock_ops;
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +09001008 setup_pager();
1009 read_events();
Hitoshi Mitake26242d82010-05-03 14:12:00 +09001010 dump_info();
Hitoshi Mitake9b5e3502010-01-30 20:43:33 +09001011 } else {
1012 usage_with_options(lock_usage, lock_options);
1013 }
1014
1015 return 0;
1016}