Skip to content

Commit 79079f2

Browse files
namhyungacmel
authored andcommitted
perf lock: Add -k and -F options to 'contention' subcommand
Like perf lock report, add -k/--key and -F/--field options to control output formatting and sorting. Note that it has slightly different default options as some fields are not available and to optimize the screen space. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20220725183124.368304-5-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 528b9ca commit 79079f2

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

tools/perf/Documentation/perf-lock.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ INFO OPTIONS
105105
--map::
106106
dump map of lock instances (address:name table)
107107

108+
CONTENTION OPTIONS
109+
--------------
110+
111+
-k::
112+
--key=<value>::
113+
Sorting key. Possible values: contended, wait_total (default),
114+
wait_max, wait_min, avg_wait.
115+
116+
-F::
117+
--field=<value>::
118+
Output fields. By default it shows all but the wait_min fields
119+
and users can customize that using this. Possible values:
120+
contended, wait_total, wait_max, wait_min, avg_wait.
121+
122+
108123
SEE ALSO
109124
--------
110125
linkperf:perf[1]

tools/perf/builtin-lock.c

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static const char *output_fields;
362362

363363
#define DEF_KEY_LOCK(name, header, fn_suffix, len) \
364364
{ #name, header, len, lock_stat_key_ ## fn_suffix, lock_stat_key_print_ ## fn_suffix, {} }
365-
struct lock_key keys[] = {
365+
static struct lock_key report_keys[] = {
366366
DEF_KEY_LOCK(acquired, "acquired", nr_acquired, 10),
367367
DEF_KEY_LOCK(contended, "contended", nr_contended, 10),
368368
DEF_KEY_LOCK(avg_wait, "avg wait", avg_wait_time, 12),
@@ -374,9 +374,24 @@ struct lock_key keys[] = {
374374
{ }
375375
};
376376

377-
static int select_key(void)
377+
static struct lock_key contention_keys[] = {
378+
DEF_KEY_LOCK(contended, "contended", nr_contended, 10),
379+
DEF_KEY_LOCK(wait_total, "total wait", wait_time_total, 12),
380+
DEF_KEY_LOCK(wait_max, "max wait", wait_time_max, 12),
381+
DEF_KEY_LOCK(wait_min, "min wait", wait_time_min, 12),
382+
DEF_KEY_LOCK(avg_wait, "avg wait", avg_wait_time, 12),
383+
384+
/* extra comparisons much complicated should be here */
385+
{ }
386+
};
387+
388+
static int select_key(bool contention)
378389
{
379390
int i;
391+
struct lock_key *keys = report_keys;
392+
393+
if (contention)
394+
keys = contention_keys;
380395

381396
for (i = 0; keys[i].name; i++) {
382397
if (!strcmp(keys[i].name, sort_key)) {
@@ -394,17 +409,21 @@ static int select_key(void)
394409
return -1;
395410
}
396411

397-
static int add_output_field(struct list_head *head, char *name)
412+
static int add_output_field(bool contention, char *name)
398413
{
399414
int i;
415+
struct lock_key *keys = report_keys;
416+
417+
if (contention)
418+
keys = contention_keys;
400419

401420
for (i = 0; keys[i].name; i++) {
402421
if (strcmp(keys[i].name, name))
403422
continue;
404423

405424
/* prevent double link */
406425
if (list_empty(&keys[i].list))
407-
list_add_tail(&keys[i].list, head);
426+
list_add_tail(&keys[i].list, &lock_keys);
408427

409428
return 0;
410429
}
@@ -413,10 +432,14 @@ static int add_output_field(struct list_head *head, char *name)
413432
return -1;
414433
}
415434

416-
static int setup_output_field(const char *str)
435+
static int setup_output_field(bool contention, const char *str)
417436
{
418437
char *tok, *tmp, *orig;
419438
int i, ret = 0;
439+
struct lock_key *keys = report_keys;
440+
441+
if (contention)
442+
keys = contention_keys;
420443

421444
/* no output field given: use all of them */
422445
if (str == NULL) {
@@ -433,7 +456,7 @@ static int setup_output_field(const char *str)
433456
return -ENOMEM;
434457

435458
while ((tok = strsep(&tmp, ",")) != NULL){
436-
ret = add_output_field(&lock_keys, tok);
459+
ret = add_output_field(contention, tok);
437460
if (ret < 0)
438461
break;
439462
}
@@ -1609,10 +1632,10 @@ static int __cmd_report(bool display_info)
16091632
goto out_delete;
16101633
}
16111634

1612-
if (setup_output_field(output_fields))
1635+
if (setup_output_field(false, output_fields))
16131636
goto out_delete;
16141637

1615-
if (select_key())
1638+
if (select_key(false))
16161639
goto out_delete;
16171640

16181641
if (show_thread_stats)
@@ -1674,11 +1697,10 @@ static int __cmd_contention(void)
16741697
goto out_delete;
16751698
}
16761699

1677-
if (setup_output_field("contended,wait_total,wait_max,avg_wait"))
1700+
if (setup_output_field(true, output_fields))
16781701
goto out_delete;
16791702

1680-
sort_key = "wait_total";
1681-
if (select_key())
1703+
if (select_key(true))
16821704
goto out_delete;
16831705

16841706
aggr_mode = LOCK_AGGR_CALLER;
@@ -1817,6 +1839,10 @@ int cmd_lock(int argc, const char **argv)
18171839
};
18181840

18191841
const struct option contention_options[] = {
1842+
OPT_STRING('k', "key", &sort_key, "wait_total",
1843+
"key for sorting (contended / wait_total / wait_max / wait_min / avg_wait)"),
1844+
OPT_STRING('F', "field", &output_fields, "contended,wait_total,wait_max,avg_wait",
1845+
"output fields (contended / wait_total / wait_max / wait_min / avg_wait)"),
18201846
OPT_PARENT(lock_options)
18211847
};
18221848

@@ -1876,6 +1902,9 @@ int cmd_lock(int argc, const char **argv)
18761902
rc = __cmd_report(true);
18771903
} else if (strlen(argv[0]) > 2 && strstarts("contention", argv[0])) {
18781904
trace_handler = &contention_lock_ops;
1905+
sort_key = "wait_total";
1906+
output_fields = "contended,wait_total,wait_max,avg_wait";
1907+
18791908
if (argc) {
18801909
argc = parse_options(argc, argv, contention_options,
18811910
contention_usage, 0);

0 commit comments

Comments
 (0)