Commit 59f411b6 authored by Ingo Molnar's avatar Ingo Molnar

perf lock: Clean up various details

Fix up a few small stylistic details:

 - use consistent vertical spacing/alignment
 - remove line80 artifacts
 - group some global variables better
 - remove dead code

Plus rename 'prof' to 'report' to make it more in line with other
tools, and remove the line/file keying as we really want to use
IPs like the other tools do.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <1264851813-8413-12-git-send-email-mitake@dcl.info.waseda.ac.jp>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 9b5e350c
...@@ -39,13 +39,13 @@ struct lock_stat { ...@@ -39,13 +39,13 @@ struct lock_stat {
struct list_head hash_entry; struct list_head hash_entry;
struct rb_node rb; /* used for sorting */ struct rb_node rb; /* used for sorting */
/* FIXME: raw_field_value() returns unsigned long long, /*
* FIXME: raw_field_value() returns unsigned long long,
* so address of lockdep_map should be dealed as 64bit. * so address of lockdep_map should be dealed as 64bit.
* Is there more better solution? */ * Is there more better solution?
*/
void *addr; /* address of lockdep_map, used as ID */ void *addr; /* address of lockdep_map, used as ID */
char *name; /* for strcpy(), we cannot use const */ char *name; /* for strcpy(), we cannot use const */
char *file;
unsigned int line;
int state; int state;
u64 prev_event_time; /* timestamp of previous event */ u64 prev_event_time; /* timestamp of previous event */
...@@ -86,8 +86,11 @@ struct lock_key { ...@@ -86,8 +86,11 @@ struct lock_key {
}; };
static const char *sort_key = "acquired"; static const char *sort_key = "acquired";
static int (*compare)(struct lock_stat *, struct lock_stat *); static int (*compare)(struct lock_stat *, struct lock_stat *);
static struct rb_root result; /* place to store sorted data */
#define DEF_KEY_LOCK(name, fn_suffix) \ #define DEF_KEY_LOCK(name, fn_suffix) \
{ #name, lock_stat_key_ ## fn_suffix } { #name, lock_stat_key_ ## fn_suffix }
struct lock_key keys[] = { struct lock_key keys[] = {
...@@ -116,11 +119,8 @@ static void select_key(void) ...@@ -116,11 +119,8 @@ static void select_key(void)
die("Unknown compare key:%s\n", sort_key); die("Unknown compare key:%s\n", sort_key);
} }
static struct rb_root result; /* place to store sorted data */
static void insert_to_result(struct lock_stat *st, static void insert_to_result(struct lock_stat *st,
int (*bigger)(struct lock_stat *, int (*bigger)(struct lock_stat *, struct lock_stat *))
struct lock_stat *))
{ {
struct rb_node **rb = &result.rb_node; struct rb_node **rb = &result.rb_node;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
...@@ -155,8 +155,7 @@ static struct lock_stat *pop_from_result(void) ...@@ -155,8 +155,7 @@ static struct lock_stat *pop_from_result(void)
return container_of(node, struct lock_stat, rb); return container_of(node, struct lock_stat, rb);
} }
static struct lock_stat *lock_stat_findnew(void *addr, const char *name, static struct lock_stat *lock_stat_findnew(void *addr, const char *name)
const char *file, unsigned int line)
{ {
struct list_head *entry = lockhashentry(addr); struct list_head *entry = lockhashentry(addr);
struct lock_stat *ret, *new; struct lock_stat *ret, *new;
...@@ -175,11 +174,6 @@ static struct lock_stat *lock_stat_findnew(void *addr, const char *name, ...@@ -175,11 +174,6 @@ static struct lock_stat *lock_stat_findnew(void *addr, const char *name,
if (!new->name) if (!new->name)
goto alloc_failed; goto alloc_failed;
strcpy(new->name, name); strcpy(new->name, name);
new->file = zalloc(sizeof(char) * strlen(file) + 1);
if (!new->file)
goto alloc_failed;
strcpy(new->file, file);
new->line = line;
/* LOCK_STATE_UNLOCKED == 0 isn't guaranteed forever */ /* LOCK_STATE_UNLOCKED == 0 isn't guaranteed forever */
new->state = LOCK_STATE_UNLOCKED; new->state = LOCK_STATE_UNLOCKED;
...@@ -204,29 +198,21 @@ struct raw_event_sample { ...@@ -204,29 +198,21 @@ struct raw_event_sample {
struct trace_acquire_event { struct trace_acquire_event {
void *addr; void *addr;
const char *name; const char *name;
const char *file;
unsigned int line;
}; };
struct trace_acquired_event { struct trace_acquired_event {
void *addr; void *addr;
const char *name; const char *name;
const char *file;
unsigned int line;
}; };
struct trace_contended_event { struct trace_contended_event {
void *addr; void *addr;
const char *name; const char *name;
const char *file;
unsigned int line;
}; };
struct trace_release_event { struct trace_release_event {
void *addr; void *addr;
const char *name; const char *name;
const char *file;
unsigned int line;
}; };
struct trace_lock_handler { struct trace_lock_handler {
...@@ -255,7 +241,8 @@ struct trace_lock_handler { ...@@ -255,7 +241,8 @@ struct trace_lock_handler {
struct thread *thread); struct thread *thread);
}; };
static void prof_lock_acquire_event(struct trace_acquire_event *acquire_event, static void
report_lock_acquire_event(struct trace_acquire_event *acquire_event,
struct event *__event __used, struct event *__event __used,
int cpu __used, int cpu __used,
u64 timestamp, u64 timestamp,
...@@ -263,8 +250,7 @@ static void prof_lock_acquire_event(struct trace_acquire_event *acquire_event, ...@@ -263,8 +250,7 @@ static void prof_lock_acquire_event(struct trace_acquire_event *acquire_event,
{ {
struct lock_stat *st; struct lock_stat *st;
st = lock_stat_findnew(acquire_event->addr, acquire_event->name, st = lock_stat_findnew(acquire_event->addr, acquire_event->name);
acquire_event->file, acquire_event->line);
switch (st->state) { switch (st->state) {
case LOCK_STATE_UNLOCKED: case LOCK_STATE_UNLOCKED:
...@@ -279,7 +265,8 @@ static void prof_lock_acquire_event(struct trace_acquire_event *acquire_event, ...@@ -279,7 +265,8 @@ static void prof_lock_acquire_event(struct trace_acquire_event *acquire_event,
st->prev_event_time = timestamp; st->prev_event_time = timestamp;
} }
static void prof_lock_acquired_event(struct trace_acquired_event *acquired_event, static void
report_lock_acquired_event(struct trace_acquired_event *acquired_event,
struct event *__event __used, struct event *__event __used,
int cpu __used, int cpu __used,
u64 timestamp, u64 timestamp,
...@@ -287,8 +274,7 @@ static void prof_lock_acquired_event(struct trace_acquired_event *acquired_event ...@@ -287,8 +274,7 @@ static void prof_lock_acquired_event(struct trace_acquired_event *acquired_event
{ {
struct lock_stat *st; struct lock_stat *st;
st = lock_stat_findnew(acquired_event->addr, acquired_event->name, st = lock_stat_findnew(acquired_event->addr, acquired_event->name);
acquired_event->file, acquired_event->line);
switch (st->state) { switch (st->state) {
case LOCK_STATE_UNLOCKED: case LOCK_STATE_UNLOCKED:
...@@ -305,7 +291,8 @@ static void prof_lock_acquired_event(struct trace_acquired_event *acquired_event ...@@ -305,7 +291,8 @@ static void prof_lock_acquired_event(struct trace_acquired_event *acquired_event
st->prev_event_time = timestamp; st->prev_event_time = timestamp;
} }
static void prof_lock_contended_event(struct trace_contended_event *contended_event, static void
report_lock_contended_event(struct trace_contended_event *contended_event,
struct event *__event __used, struct event *__event __used,
int cpu __used, int cpu __used,
u64 timestamp, u64 timestamp,
...@@ -313,8 +300,7 @@ static void prof_lock_contended_event(struct trace_contended_event *contended_ev ...@@ -313,8 +300,7 @@ static void prof_lock_contended_event(struct trace_contended_event *contended_ev
{ {
struct lock_stat *st; struct lock_stat *st;
st = lock_stat_findnew(contended_event->addr, contended_event->name, st = lock_stat_findnew(contended_event->addr, contended_event->name);
contended_event->file, contended_event->line);
switch (st->state) { switch (st->state) {
case LOCK_STATE_UNLOCKED: case LOCK_STATE_UNLOCKED:
...@@ -330,7 +316,8 @@ static void prof_lock_contended_event(struct trace_contended_event *contended_ev ...@@ -330,7 +316,8 @@ static void prof_lock_contended_event(struct trace_contended_event *contended_ev
st->prev_event_time = timestamp; st->prev_event_time = timestamp;
} }
static void prof_lock_release_event(struct trace_release_event *release_event, static void
report_lock_release_event(struct trace_release_event *release_event,
struct event *__event __used, struct event *__event __used,
int cpu __used, int cpu __used,
u64 timestamp, u64 timestamp,
...@@ -339,8 +326,7 @@ static void prof_lock_release_event(struct trace_release_event *release_event, ...@@ -339,8 +326,7 @@ static void prof_lock_release_event(struct trace_release_event *release_event,
struct lock_stat *st; struct lock_stat *st;
u64 hold_time; u64 hold_time;
st = lock_stat_findnew(release_event->addr, release_event->name, st = lock_stat_findnew(release_event->addr, release_event->name);
release_event->file, release_event->line);
switch (st->state) { switch (st->state) {
case LOCK_STATE_UNLOCKED: case LOCK_STATE_UNLOCKED:
...@@ -373,11 +359,11 @@ static void prof_lock_release_event(struct trace_release_event *release_event, ...@@ -373,11 +359,11 @@ static void prof_lock_release_event(struct trace_release_event *release_event,
/* lock oriented handlers */ /* lock oriented handlers */
/* TODO: handlers for CPU oriented, thread oriented */ /* TODO: handlers for CPU oriented, thread oriented */
static struct trace_lock_handler prof_lock_ops = { static struct trace_lock_handler report_lock_ops = {
.acquire_event = prof_lock_acquire_event, .acquire_event = report_lock_acquire_event,
.acquired_event = prof_lock_acquired_event, .acquired_event = report_lock_acquired_event,
.contended_event = prof_lock_contended_event, .contended_event = report_lock_contended_event,
.release_event = prof_lock_release_event, .release_event = report_lock_release_event,
}; };
static struct trace_lock_handler *trace_handler; static struct trace_lock_handler *trace_handler;
...@@ -395,14 +381,9 @@ process_lock_acquire_event(void *data, ...@@ -395,14 +381,9 @@ process_lock_acquire_event(void *data,
tmp = raw_field_value(event, "lockdep_addr", data); tmp = raw_field_value(event, "lockdep_addr", data);
memcpy(&acquire_event.addr, &tmp, sizeof(void *)); memcpy(&acquire_event.addr, &tmp, sizeof(void *));
acquire_event.name = (char *)raw_field_ptr(event, "name", data); acquire_event.name = (char *)raw_field_ptr(event, "name", data);
acquire_event.file = (char *)raw_field_ptr(event, "file", data);
acquire_event.line =
(unsigned int)raw_field_value(event, "line", data);
if (trace_handler->acquire_event) { if (trace_handler->acquire_event)
trace_handler->acquire_event(&acquire_event, trace_handler->acquire_event(&acquire_event, event, cpu, timestamp, thread);
event, cpu, timestamp, thread);
}
} }
static void static void
...@@ -418,14 +399,9 @@ process_lock_acquired_event(void *data, ...@@ -418,14 +399,9 @@ process_lock_acquired_event(void *data,
tmp = raw_field_value(event, "lockdep_addr", data); tmp = raw_field_value(event, "lockdep_addr", data);
memcpy(&acquired_event.addr, &tmp, sizeof(void *)); memcpy(&acquired_event.addr, &tmp, sizeof(void *));
acquired_event.name = (char *)raw_field_ptr(event, "name", data); acquired_event.name = (char *)raw_field_ptr(event, "name", data);
acquired_event.file = (char *)raw_field_ptr(event, "file", data);
acquired_event.line =
(unsigned int)raw_field_value(event, "line", data);
if (trace_handler->acquire_event) { if (trace_handler->acquire_event)
trace_handler->acquired_event(&acquired_event, trace_handler->acquired_event(&acquired_event, event, cpu, timestamp, thread);
event, cpu, timestamp, thread);
}
} }
static void static void
...@@ -441,14 +417,9 @@ process_lock_contended_event(void *data, ...@@ -441,14 +417,9 @@ process_lock_contended_event(void *data,
tmp = raw_field_value(event, "lockdep_addr", data); tmp = raw_field_value(event, "lockdep_addr", data);
memcpy(&contended_event.addr, &tmp, sizeof(void *)); memcpy(&contended_event.addr, &tmp, sizeof(void *));
contended_event.name = (char *)raw_field_ptr(event, "name", data); contended_event.name = (char *)raw_field_ptr(event, "name", data);
contended_event.file = (char *)raw_field_ptr(event, "file", data);
contended_event.line =
(unsigned int)raw_field_value(event, "line", data);
if (trace_handler->acquire_event) { if (trace_handler->acquire_event)
trace_handler->contended_event(&contended_event, trace_handler->contended_event(&contended_event, event, cpu, timestamp, thread);
event, cpu, timestamp, thread);
}
} }
static void static void
...@@ -464,14 +435,9 @@ process_lock_release_event(void *data, ...@@ -464,14 +435,9 @@ process_lock_release_event(void *data,
tmp = raw_field_value(event, "lockdep_addr", data); tmp = raw_field_value(event, "lockdep_addr", data);
memcpy(&release_event.addr, &tmp, sizeof(void *)); memcpy(&release_event.addr, &tmp, sizeof(void *));
release_event.name = (char *)raw_field_ptr(event, "name", data); release_event.name = (char *)raw_field_ptr(event, "name", data);
release_event.file = (char *)raw_field_ptr(event, "file", data);
release_event.line =
(unsigned int)raw_field_value(event, "line", data);
if (trace_handler->acquire_event) { if (trace_handler->acquire_event)
trace_handler->release_event(&release_event, trace_handler->release_event(&release_event, event, cpu, timestamp, thread);
event, cpu, timestamp, thread);
}
} }
static void static void
...@@ -503,14 +469,6 @@ static int process_sample_event(event_t *event, struct perf_session *session) ...@@ -503,14 +469,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)
event__parse_sample(event, session->sample_type, &data); event__parse_sample(event, session->sample_type, &data);
thread = perf_session__findnew(session, data.pid); thread = perf_session__findnew(session, data.pid);
/*
* FIXME: this causes warn on 32bit environment
* because of (void *)data.ip (type of data.ip is u64)
*/
/* dump_printf("(IP, %d): %d/%d: %p period: %llu\n", */
/* event->header.misc, */
/* data.pid, data.tid, (void *)data.ip, data.period); */
if (thread == NULL) { if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n", pr_debug("problem processing %d event, skipping it.\n",
event->header.type); event->header.type);
...@@ -580,8 +538,7 @@ static void dump_map(void) ...@@ -580,8 +538,7 @@ static void dump_map(void)
for (i = 0; i < LOCKHASH_SIZE; i++) { for (i = 0; i < LOCKHASH_SIZE; i++) {
list_for_each_entry(st, &lockhash_table[i], hash_entry) { list_for_each_entry(st, &lockhash_table[i], hash_entry) {
printf("%p: %s (src: %s, line: %u)\n", printf("%p: %s\n", st->addr, st->name);
st->addr, st->name, st->file, st->line);
} }
} }
} }
...@@ -614,7 +571,7 @@ static void sort_result(void) ...@@ -614,7 +571,7 @@ static void sort_result(void)
} }
} }
static void __cmd_prof(void) static void __cmd_report(void)
{ {
setup_pager(); setup_pager();
select_key(); select_key();
...@@ -623,12 +580,12 @@ static void __cmd_prof(void) ...@@ -623,12 +580,12 @@ static void __cmd_prof(void)
print_result(); print_result();
} }
static const char * const prof_usage[] = { static const char * const report_usage[] = {
"perf sched prof [<options>]", "perf lock report [<options>]",
NULL NULL
}; };
static const struct option prof_options[] = { static const struct option report_options[] = {
OPT_STRING('k', "key", &sort_key, "acquired", OPT_STRING('k', "key", &sort_key, "acquired",
"key for sorting"), "key for sorting"),
/* TODO: type */ /* TODO: type */
...@@ -636,17 +593,14 @@ static const struct option prof_options[] = { ...@@ -636,17 +593,14 @@ static const struct option prof_options[] = {
}; };
static const char * const lock_usage[] = { static const char * const lock_usage[] = {
"perf lock [<options>] {record|trace|prof}", "perf lock [<options>] {record|trace|report}",
NULL NULL
}; };
static const struct option lock_options[] = { static const struct option lock_options[] = {
OPT_STRING('i', "input", &input_name, "file", OPT_STRING('i', "input", &input_name, "file", "input file name"),
"input file name"), OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('v', "verbose", &verbose, OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
"be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_END() OPT_END()
}; };
...@@ -698,21 +652,21 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used) ...@@ -698,21 +652,21 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used)
if (!strncmp(argv[0], "rec", 3)) { if (!strncmp(argv[0], "rec", 3)) {
return __cmd_record(argc, argv); return __cmd_record(argc, argv);
} else if (!strncmp(argv[0], "prof", 4)) { } else if (!strncmp(argv[0], "report", 6)) {
trace_handler = &prof_lock_ops; trace_handler = &report_lock_ops;
if (argc) { if (argc) {
argc = parse_options(argc, argv, argc = parse_options(argc, argv,
prof_options, prof_usage, 0); report_options, report_usage, 0);
if (argc) if (argc)
usage_with_options(prof_usage, prof_options); usage_with_options(report_usage, report_options);
} }
__cmd_prof(); __cmd_report();
} else if (!strcmp(argv[0], "trace")) { } else if (!strcmp(argv[0], "trace")) {
/* Aliased to 'perf trace' */ /* Aliased to 'perf trace' */
return cmd_trace(argc, argv, prefix); return cmd_trace(argc, argv, prefix);
} else if (!strcmp(argv[0], "map")) { } else if (!strcmp(argv[0], "map")) {
/* recycling prof_lock_ops */ /* recycling report_lock_ops */
trace_handler = &prof_lock_ops; trace_handler = &report_lock_ops;
setup_pager(); setup_pager();
read_events(); read_events();
dump_map(); dump_map();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment