Skip to content

Commit 4bd9cab

Browse files
namhyungacmel
authored andcommitted
perf lock: Add -F/--field option to control output
The -F/--field option is to customize the list of fields to output: $ perf lock report -F contended,wait_max -k avg_wait Name contended max wait (ns) avg wait (ns) slock-AF_INET6 1 23543 23543 &lruvec->lru_lock 5 18317 11254 slock-AF_INET6 1 10379 10379 rcu_node_1 1 2104 2104 &dentry->d_lockr... 1 1844 1844 &dentry->d_lockr... 1 1672 1672 &newf->file_lock 15 2279 1025 &dentry->d_lockr... 1 792 792 Signed-off-by: Namhyung Kim <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 64999e4 commit 4bd9cab

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

tools/perf/Documentation/perf-lock.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ REPORT OPTIONS
5454
Sorting key. Possible values: acquired (default), contended,
5555
avg_wait, wait_total, wait_max, wait_min.
5656

57+
-F::
58+
--field=<value>::
59+
Output fields. By default it shows all the fields but users can
60+
customize that using this. Possible values: acquired, contended,
61+
avg_wait, wait_total, wait_max, wait_min.
62+
5763
-c::
5864
--combine-locks::
5965
Merge lock instances in the same class (based on name).

tools/perf/builtin-lock.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ static struct rb_root sorted; /* place to store intermediate data */
282282
static struct rb_root result; /* place to store sorted data */
283283

284284
static LIST_HEAD(lock_keys);
285+
static const char *output_fields;
285286

286287
#define DEF_KEY_LOCK(name, header, fn_suffix, len) \
287288
{ #name, header, len, lock_stat_key_ ## fn_suffix, lock_stat_key_print_ ## fn_suffix, {} }
@@ -304,23 +305,65 @@ static int select_key(void)
304305
for (i = 0; keys[i].name; i++) {
305306
if (!strcmp(keys[i].name, sort_key)) {
306307
compare = keys[i].key;
308+
309+
/* selected key should be in the output fields */
310+
if (list_empty(&keys[i].list))
311+
list_add_tail(&keys[i].list, &lock_keys);
312+
307313
return 0;
308314
}
309315
}
310316

311317
pr_err("Unknown compare key: %s\n", sort_key);
312-
313318
return -1;
314319
}
315320

316-
static int setup_output_field(void)
321+
static int add_output_field(struct list_head *head, char *name)
317322
{
318323
int i;
319324

325+
for (i = 0; keys[i].name; i++) {
326+
if (strcmp(keys[i].name, name))
327+
continue;
328+
329+
/* prevent double link */
330+
if (list_empty(&keys[i].list))
331+
list_add_tail(&keys[i].list, head);
332+
333+
return 0;
334+
}
335+
336+
pr_err("Unknown output field: %s\n", name);
337+
return -1;
338+
}
339+
340+
static int setup_output_field(const char *str)
341+
{
342+
char *tok, *tmp, *orig;
343+
int i, ret = 0;
344+
345+
/* no output field given: use all of them */
346+
if (str == NULL) {
347+
for (i = 0; keys[i].name; i++)
348+
list_add_tail(&keys[i].list, &lock_keys);
349+
return 0;
350+
}
351+
320352
for (i = 0; keys[i].name; i++)
321-
list_add_tail(&keys[i].list, &lock_keys);
353+
INIT_LIST_HEAD(&keys[i].list);
322354

323-
return 0;
355+
orig = tmp = strdup(str);
356+
if (orig == NULL)
357+
return -ENOMEM;
358+
359+
while ((tok = strsep(&tmp, ",")) != NULL){
360+
ret = add_output_field(&lock_keys, tok);
361+
if (ret < 0)
362+
break;
363+
}
364+
free(orig);
365+
366+
return ret;
324367
}
325368

326369
static void combine_lock_stats(struct lock_stat *st)
@@ -1002,7 +1045,7 @@ static int __cmd_report(bool display_info)
10021045
goto out_delete;
10031046
}
10041047

1005-
if (setup_output_field())
1048+
if (setup_output_field(output_fields))
10061049
goto out_delete;
10071050

10081051
if (select_key())
@@ -1090,6 +1133,8 @@ int cmd_lock(int argc, const char **argv)
10901133
const struct option report_options[] = {
10911134
OPT_STRING('k', "key", &sort_key, "acquired",
10921135
"key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
1136+
OPT_STRING('F', "field", &output_fields, NULL,
1137+
"output fields (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
10931138
/* TODO: type */
10941139
OPT_BOOLEAN('c', "combine-locks", &combine_locks,
10951140
"combine locks in the same class"),

0 commit comments

Comments
 (0)