Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf lock: Add -E/--entries option

Like in 'perf top', the -E option can limit number of entries to print.

It can be useful when users want to see top N contended locks only.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220924004221.841024-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
6282a1f4 84838712

+25 -5
+10
tools/perf/Documentation/perf-lock.txt
··· 94 94 EventManager_De 1845 1 636 95 95 futex-default-S 1609 0 0 96 96 97 + -E:: 98 + --entries=<value>:: 99 + Display this many entries. 100 + 101 + 97 102 INFO OPTIONS 98 103 ------------ 99 104 ··· 109 104 -m:: 110 105 --map:: 111 106 dump map of lock instances (address:name table) 107 + 112 108 113 109 CONTENTION OPTIONS 114 110 -------------- ··· 159 153 160 154 --stack-skip 161 155 Number of stack depth to skip when finding a lock caller (default: 3). 156 + 157 + -E:: 158 + --entries=<value>:: 159 + Display this many entries. 162 160 163 161 164 162 SEE ALSO
+15 -5
tools/perf/builtin-lock.c
··· 58 58 static unsigned long bpf_map_entries = 10240; 59 59 static int max_stack_depth = CONTENTION_STACK_DEPTH; 60 60 static int stack_skip = CONTENTION_STACK_SKIP; 61 + static int print_nr_entries = INT_MAX / 2; 61 62 62 63 static enum { 63 64 LOCK_AGGR_ADDR, ··· 1267 1266 struct lock_stat *st; 1268 1267 struct lock_key *key; 1269 1268 char cut_name[20]; 1270 - int bad, total; 1269 + int bad, total, printed; 1271 1270 1272 1271 pr_info("%20s ", "Name"); 1273 1272 list_for_each_entry(key, &lock_keys, list) 1274 1273 pr_info("%*s ", key->len, key->header); 1275 1274 pr_info("\n\n"); 1276 1275 1277 - bad = total = 0; 1276 + bad = total = printed = 0; 1278 1277 while ((st = pop_from_result())) { 1279 1278 total++; 1280 1279 if (st->broken) ··· 1312 1311 pr_info(" "); 1313 1312 } 1314 1313 pr_info("\n"); 1314 + 1315 + if (++printed >= print_nr_entries) 1316 + break; 1315 1317 } 1316 1318 1317 1319 print_bad_events(bad, total); ··· 1480 1476 { 1481 1477 struct lock_stat *st; 1482 1478 struct lock_key *key; 1483 - int bad, total; 1479 + int bad, total, printed; 1484 1480 1485 1481 list_for_each_entry(key, &lock_keys, list) 1486 1482 pr_info("%*s ", key->len, key->header); ··· 1490 1486 else 1491 1487 pr_info(" %10s %s\n\n", "type", "caller"); 1492 1488 1493 - bad = total = 0; 1489 + bad = total = printed = 0; 1494 1490 if (use_bpf) 1495 1491 bad = bad_hist[BROKEN_CONTENDED]; 1496 1492 ··· 1511 1507 /* st->addr contains tid of thread */ 1512 1508 t = perf_session__findnew(session, pid); 1513 1509 pr_info(" %10d %s\n", pid, thread__comm_str(t)); 1514 - continue; 1510 + goto next; 1515 1511 } 1516 1512 1517 1513 pr_info(" %10s %s\n", get_type_str(st), st->name); ··· 1531 1527 pr_info("\t\t\t%#lx %s\n", (unsigned long)ip, buf); 1532 1528 } 1533 1529 } 1530 + 1531 + next: 1532 + if (++printed >= print_nr_entries) 1533 + break; 1534 1534 } 1535 1535 1536 1536 print_bad_events(bad, total); ··· 1886 1878 "combine locks in the same class"), 1887 1879 OPT_BOOLEAN('t', "threads", &show_thread_stats, 1888 1880 "show per-thread lock stats"), 1881 + OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"), 1889 1882 OPT_PARENT(lock_options) 1890 1883 }; 1891 1884 ··· 1914 1905 OPT_INTEGER(0, "stack-skip", &stack_skip, 1915 1906 "Set the number of stack depth to skip when finding a lock caller, " 1916 1907 "Default: " __stringify(CONTENTION_STACK_SKIP)), 1908 + OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"), 1917 1909 OPT_PARENT(lock_options) 1918 1910 }; 1919 1911