perf stat: Enable '--per-thread' on all threads
cover perf stat: Enable '--per-thread' on all threads
perf stat --per-thread is useful to break down data per thread. But it currently requires specifying --pid/--tid to limit it to a process.
For analysis it would be useful to do it globally for the whole system.
1. Currently, if we perform 'perf stat --per-thread' without pid/tid, perf returns error:
root@skl:/tmp# perf stat --per-thread
The --per-thread option is only available when monitoring via -p -t options.
-p, --pid <pid> stat events on existing process id
-t, --tid <tid> stat events on existing thread id2. With this patch series, it returns data per thread with shadow metrics. (run "vmstat 1" in following example)
root@skl:/tmp# perf stat --per-thread
^C
Performance counter stats for 'system wide': perf-24165 4.302433 cpu-clock (msec) # 0.001 CPUs utilized
vmstat-23127 1.562215 cpu-clock (msec) # 0.000 CPUs utilized
irqbalance-2780 0.827851 cpu-clock (msec) # 0.000 CPUs utilized
sshd-23111 0.278308 cpu-clock (msec) # 0.000 CPUs utilized
thermald-2841 0.230880 cpu-clock (msec) # 0.000 CPUs utilized
sshd-23058 0.207306 cpu-clock (msec) # 0.000 CPUs utilized
kworker/0:2-19991 0.133983 cpu-clock (msec) # 0.000 CPUs utilized
kworker/u16:1-18249 0.125636 cpu-clock (msec) # 0.000 CPUs utilized
rcu_sched-8 0.085533 cpu-clock (msec) # 0.000 CPUs utilized
kworker/u16:2-23146 0.077139 cpu-clock (msec) # 0.000 CPUs utilized
gmain-2700 0.041789 cpu-clock (msec) # 0.000 CPUs utilized
kworker/4:1-15354 0.028370 cpu-clock (msec) # 0.000 CPUs utilized
kworker/6:0-17528 0.023895 cpu-clock (msec) # 0.000 CPUs utilized
kworker/4:1H-1887 0.013209 cpu-clock (msec) # 0.000 CPUs utilized
kworker/5:2-31362 0.011627 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/0-11 0.010892 cpu-clock (msec) # 0.000 CPUs utilized
kworker/3:2-12870 0.010220 cpu-clock (msec) # 0.000 CPUs utilized
ksoftirqd/0-7 0.008869 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/1-14 0.008476 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/7-50 0.002944 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/3-26 0.002893 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/4-32 0.002759 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/2-20 0.002429 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/6-44 0.001491 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/5-38 0.001477 cpu-clock (msec) # 0.000 CPUs utilized
rcu_sched-8 10 context-switches # 0.117 M/sec
kworker/u16:1-18249 7 context-switches # 0.056 M/sec
sshd-23111 4 context-switches # 0.014 M/sec
vmstat-23127 4 context-switches # 0.003 M/sec
perf-24165 4 context-switches # 0.930 K/sec
kworker/0:2-19991 3 context-switches # 0.022 M/sec
kworker/u16:2-23146 3 context-switches # 0.039 M/sec
kworker/4:1-15354 2 context-switches # 0.070 M/sec
kworker/6:0-17528 2 context-switches # 0.084 M/sec
sshd-23058 2 context-switches # 0.010 M/sec
ksoftirqd/0-7 1 context-switches # 0.113 M/sec
watchdog/0-11 1 context-switches # 0.092 M/sec
watchdog/1-14 1 context-switches # 0.118 M/sec
watchdog/2-20 1 context-switches # 0.412 M/sec
watchdog/3-26 1 context-switches # 0.346 M/sec
watchdog/4-32 1 context-switches # 0.362 M/sec
watchdog/5-38 1 context-switches # 0.677 M/sec
watchdog/6-44 1 context-switches # 0.671 M/sec
watchdog/7-50 1 context-switches # 0.340 M/sec
kworker/4:1H-1887 1 context-switches # 0.076 M/sec
thermald-2841 1 context-switches # 0.004 M/sec
gmain-2700 1 context-switches # 0.024 M/sec
irqbalance-2780 1 context-switches # 0.001 M/sec
kworker/3:2-12870 1 context-switches # 0.098 M/sec
kworker/5:2-31362 1 context-switches # 0.086 M/sec
kworker/u16:1-18249 2 cpu-migrations # 0.016 M/sec
kworker/u16:2-23146 2 cpu-migrations # 0.026 M/sec
rcu_sched-8 1 cpu-migrations # 0.012 M/sec
sshd-23058 1 cpu-migrations # 0.005 M/sec
perf-24165 8,833,385 cycles # 2.053 GHz
vmstat-23127 1,702,699 cycles # 1.090 GHz
irqbalance-2780 739,847 cycles # 0.894 GHz
sshd-23111 269,506 cycles # 0.968 GHz
thermald-2841 204,556 cycles # 0.886 GHz
sshd-23058 158,780 cycles # 0.766 GHz
kworker/0:2-19991 112,981 cycles # 0.843 GHz
kworker/u16:1-18249 100,926 cycles # 0.803 GHz
rcu_sched-8 74,024 cycles # 0.865 GHz
kworker/u16:2-23146 55,984 cycles # 0.726 GHz
gmain-2700 34,278 cycles # 0.820 GHz
kworker/4:1-15354 20,665 cycles # 0.728 GHz
kworker/6:0-17528 16,445 cycles # 0.688 GHz
kworker/5:2-31362 9,492 cycles # 0.816 GHz
watchdog/3-26 8,695 cycles # 3.006 GHz
kworker/4:1H-1887 8,238 cycles # 0.624 GHz
watchdog/4-32 7,580 cycles # 2.747 GHz
kworker/3:2-12870 7,306 cycles # 0.715 GHz
watchdog/2-20 7,274 cycles # 2.995 GHz
watchdog/0-11 6,988 cycles # 0.642 GHz
ksoftirqd/0-7 6,376 cycles # 0.719 GHz
watchdog/1-14 5,340 cycles # 0.630 GHz
watchdog/5-38 4,061 cycles # 2.749 GHz
watchdog/6-44 3,976 cycles # 2.667 GHz
watchdog/7-50 3,418 cycles # 1.161 GHz
vmstat-23127 2,511,699 instructions # 1.48 insn per cycle
perf-24165 1,829,908 instructions # 0.21 insn per cycle
irqbalance-2780 1,190,204 instructions # 1.61 insn per cycle
thermald-2841 143,544 instructions # 0.70 insn per cycle
sshd-23111 128,138 instructions # 0.48 insn per cycle
sshd-23058 57,654 instructions # 0.36 insn per cycle
rcu_sched-8 44,063 instructions # 0.60 insn per cycle
kworker/u16:1-18249 42,551 instructions # 0.42 insn per cycle
kworker/0:2-19991 25,873 instructions # 0.23 insn per cycle
kworker/u16:2-23146 21,407 instructions # 0.38 insn per cycle
gmain-2700 13,691 instructions # 0.40 insn per cycle
kworker/4:1-15354 12,964 instructions # 0.63 insn per cycle
kworker/6:0-17528 10,034 instructions # 0.61 insn per cycle
kworker/5:2-31362 5,203 instructions # 0.55 insn per cycle
kworker/3:2-12870 4,866 instructions # 0.67 insn per cycle
kworker/4:1H-1887 3,586 instructions # 0.44 insn per cycle
ksoftirqd/0-7 3,463 instructions # 0.54 insn per cycle
watchdog/0-11 3,135 instructions # 0.45 insn per cycle
watchdog/1-14 3,135 instructions # 0.59 insn per cycle
watchdog/2-20 3,135 instructions # 0.43 insn per cycle
watchdog/3-26 3,135 instructions # 0.36 insn per cycle
watchdog/4-32 3,135 instructions # 0.41 insn per cycle
watchdog/5-38 3,135 instructions # 0.77 insn per cycle
watchdog/6-44 3,135 instructions # 0.79 insn per cycle
watchdog/7-50 3,135 instructions # 0.92 insn per cycle
vmstat-23127 539,181 branches # 345.139 M/sec
perf-24165 375,364 branches # 87.245 M/sec
irqbalance-2780 262,092 branches # 316.593 M/sec
thermald-2841 31,611 branches # 136.915 M/sec
sshd-23111 21,874 branches # 78.596 M/sec
sshd-23058 10,682 branches # 51.528 M/sec
rcu_sched-8 8,693 branches # 101.633 M/sec
kworker/u16:1-18249 7,891 branches # 62.808 M/sec
kworker/0:2-19991 5,761 branches # 42.998 M/sec
kworker/u16:2-23146 4,099 branches # 53.138 M/sec
kworker/4:1-15354 2,755 branches # 97.110 M/sec
gmain-2700 2,638 branches # 63.127 M/sec
kworker/6:0-17528 2,216 branches # 92.739 M/sec
kworker/5:2-31362 1,132 branches # 97.360 M/sec
kworker/3:2-12870 1,081 branches # 105.773 M/sec
kworker/4:1H-1887 725 branches # 54.887 M/sec
ksoftirqd/0-7 707 branches # 79.716 M/sec
watchdog/0-11 652 branches # 59.860 M/sec
watchdog/1-14 652 branches # 76.923 M/sec
watchdog/2-20 652 branches # 268.423 M/sec
watchdog/3-26 652 branches # 225.372 M/sec
watchdog/4-32 652 branches # 236.318 M/sec
watchdog/5-38 652 branches # 441.435 M/sec
watchdog/6-44 652 branches # 437.290 M/sec
watchdog/7-50 652 branches # 221.467 M/sec
vmstat-23127 8,960 branch-misses # 1.66% of all branches
irqbalance-2780 3,047 branch-misses # 1.16% of all branches
perf-24165 2,876 branch-misses # 0.77% of all branches
sshd-23111 1,843 branch-misses # 8.43% of all branches
thermald-2841 1,444 branch-misses # 4.57% of all branches
sshd-23058 1,379 branch-misses # 12.91% of all branches
kworker/u16:1-18249 982 branch-misses # 12.44% of all branches
rcu_sched-8 893 branch-misses # 10.27% of all branches
kworker/u16:2-23146 578 branch-misses # 14.10% of all branches
kworker/0:2-19991 376 branch-misses # 6.53% of all branches
gmain-2700 280 branch-misses # 10.61% of all branches
kworker/6:0-17528 196 branch-misses # 8.84% of all branches
kworker/4:1-15354 187 branch-misses # 6.79% of all branches
kworker/5:2-31362 123 branch-misses # 10.87% of all branches
watchdog/0-11 95 branch-misses # 14.57% of all branches
watchdog/4-32 89 branch-misses # 13.65% of all branches
kworker/3:2-12870 80 branch-misses # 7.40% of all branches
watchdog/3-26 61 branch-misses # 9.36% of all branches
kworker/4:1H-1887 60 branch-misses # 8.28% of all branches
watchdog/2-20 52 branch-misses # 7.98% of all branches
ksoftirqd/0-7 47 branch-misses # 6.65% of all branches
watchdog/1-14 46 branch-misses # 7.06% of all branches
watchdog/7-50 13 branch-misses # 1.99% of all branches
watchdog/5-38 8 branch-misses # 1.23% of all branches
watchdog/6-44 7 branch-misses # 1.07% of all branches3.695150786 seconds time elapsed
root@skl:/tmp# perf stat --per-thread -M IPC,CPI ^C
Performance counter stats for 'system wide':
vmstat-23127 2,000,783 inst_retired.any # 1.5 IPC
thermald-2841 1,472,670 inst_retired.any # 1.3 IPC
sshd-23111 977,374 inst_retired.any # 1.2 IPC
perf-24163 483,779 inst_retired.any # 0.2 IPC
gmain-2700 341,213 inst_retired.any # 0.9 IPC
sshd-23058 148,891 inst_retired.any # 0.8 IPC
rtkit-daemon-3288 71,210 inst_retired.any # 0.7 IPC
kworker/u16:1-18249 39,562 inst_retired.any # 0.3 IPC
rcu_sched-8 14,474 inst_retired.any # 0.8 IPC
kworker/0:2-19991 7,659 inst_retired.any # 0.2 IPC
kworker/4:1-15354 6,714 inst_retired.any # 0.8 IPC
rtkit-daemon-3289 4,839 inst_retired.any # 0.3 IPC
kworker/6:0-17528 3,321 inst_retired.any # 0.6 IPC
kworker/5:2-31362 3,215 inst_retired.any # 0.5 IPC
kworker/7:2-23145 3,173 inst_retired.any # 0.7 IPC
kworker/4:1H-1887 1,719 inst_retired.any # 0.3 IPC
watchdog/0-11 1,479 inst_retired.any # 0.3 IPC
watchdog/1-14 1,479 inst_retired.any # 0.3 IPC
watchdog/2-20 1,479 inst_retired.any # 0.4 IPC
watchdog/3-26 1,479 inst_retired.any # 0.4 IPC
watchdog/4-32 1,479 inst_retired.any # 0.3 IPC
watchdog/5-38 1,479 inst_retired.any # 0.3 IPC
watchdog/6-44 1,479 inst_retired.any # 0.7 IPC
watchdog/7-50 1,479 inst_retired.any # 0.7 IPC
kworker/u16:2-23146 1,408 inst_retired.any # 0.5 IPC
perf-24163 2,249,872 cpu_clk_unhalted.thread
vmstat-23127 1,352,455 cpu_clk_unhalted.thread
thermald-2841 1,161,140 cpu_clk_unhalted.thread
sshd-23111 807,827 cpu_clk_unhalted.thread
gmain-2700 375,535 cpu_clk_unhalted.thread
sshd-23058 194,071 cpu_clk_unhalted.thread
kworker/u16:1-18249 114,306 cpu_clk_unhalted.thread
rtkit-daemon-3288 103,547 cpu_clk_unhalted.thread
kworker/0:2-19991 46,550 cpu_clk_unhalted.thread
rcu_sched-8 18,855 cpu_clk_unhalted.thread
rtkit-daemon-3289 17,549 cpu_clk_unhalted.thread
kworker/4:1-15354 8,812 cpu_clk_unhalted.thread
kworker/5:2-31362 6,812 cpu_clk_unhalted.thread
kworker/4:1H-1887 5,270 cpu_clk_unhalted.thread
kworker/6:0-17528 5,111 cpu_clk_unhalted.thread
kworker/7:2-23145 4,667 cpu_clk_unhalted.thread
watchdog/0-11 4,663 cpu_clk_unhalted.thread
watchdog/1-14 4,663 cpu_clk_unhalted.thread
watchdog/4-32 4,626 cpu_clk_unhalted.thread
watchdog/5-38 4,403 cpu_clk_unhalted.thread
watchdog/3-26 3,936 cpu_clk_unhalted.thread
watchdog/2-20 3,850 cpu_clk_unhalted.thread
kworker/u16:2-23146 2,654 cpu_clk_unhalted.thread
watchdog/6-44 2,017 cpu_clk_unhalted.thread
watchdog/7-50 2,017 cpu_clk_unhalted.thread
vmstat-23127 2,000,783 inst_retired.any # 0.7 CPI
thermald-2841 1,472,670 inst_retired.any # 0.8 CPI
sshd-23111 977,374 inst_retired.any # 0.8 CPI
perf-24163 495,037 inst_retired.any # 4.7 CPI
gmain-2700 341,213 inst_retired.any # 1.1 CPI
sshd-23058 148,891 inst_retired.any # 1.3 CPI
rtkit-daemon-3288 71,210 inst_retired.any # 1.5 CPI
kworker/u16:1-18249 39,562 inst_retired.any # 2.9 CPI
rcu_sched-8 14,474 inst_retired.any # 1.3 CPI
kworker/0:2-19991 7,659 inst_retired.any # 6.1 CPI
kworker/4:1-15354 6,714 inst_retired.any # 1.3 CPI
rtkit-daemon-3289 4,839 inst_retired.any # 3.6 CPI
kworker/6:0-17528 3,321 inst_retired.any # 1.5 CPI
kworker/5:2-31362 3,215 inst_retired.any # 2.1 CPI
kworker/7:2-23145 3,173 inst_retired.any # 1.5 CPI
kworker/4:1H-1887 1,719 inst_retired.any # 3.1 CPI
watchdog/0-11 1,479 inst_retired.any # 3.2 CPI
watchdog/1-14 1,479 inst_retired.any # 3.2 CPI
watchdog/2-20 1,479 inst_retired.any # 2.6 CPI
watchdog/3-26 1,479 inst_retired.any # 2.7 CPI
watchdog/4-32 1,479 inst_retired.any # 3.1 CPI
watchdog/5-38 1,479 inst_retired.any # 3.0 CPI
watchdog/6-44 1,479 inst_retired.any # 1.4 CPI
watchdog/7-50 1,479 inst_retired.any # 1.4 CPI
kworker/u16:2-23146 1,408 inst_retired.any # 1.9 CPI
perf-24163 2,302,323 cycles
vmstat-23127 1,352,455 cycles
thermald-2841 1,161,140 cycles
sshd-23111 807,827 cycles
gmain-2700 375,535 cycles
sshd-23058 194,071 cycles
kworker/u16:1-18249 114,306 cycles
rtkit-daemon-3288 103,547 cycles
kworker/0:2-19991 46,550 cycles
rcu_sched-8 18,855 cycles
rtkit-daemon-3289 17,549 cycles
kworker/4:1-15354 8,812 cycles
kworker/5:2-31362 6,812 cycles
kworker/4:1H-1887 5,270 cycles
kworker/6:0-17528 5,111 cycles
kworker/7:2-23145 4,667 cycles
watchdog/0-11 4,663 cycles
watchdog/1-14 4,663 cycles
watchdog/4-32 4,626 cycles
watchdog/5-38 4,403 cycles
watchdog/3-26 3,936 cycles
watchdog/2-20 3,850 cycles
kworker/u16:2-23146 2,654 cycles
watchdog/6-44 2,017 cycles
watchdog/7-50 2,017 cycles
2.175726600 seconds time elapsed
Jin Yao (9):
perf util: Create rblist__reset() function
perf util: Define a structure for runtime shadow metrics stats perf util: Reconstruct rblist for supporting per-thread shadow stats perf util: Update and print per-thread shadow stats
perf util: Remove a set of shadow stats static variables perf stat: Allocate shadow stats buffer for threads
perf util: Reuse thread_map__new_by_uid to enumerate threads from
/proc
perf stat: Remove --per-thread pid/tid limitation
perf stat: Resort '--per-thread' result
tools/perf/builtin-stat.c | 161 +++++++++++++--- tools/perf/tests/thread-map.c | 2 +- tools/perf/util/evlist.c | 3 +- tools/perf/util/rblist.c | 24 ++- tools/perf/util/rblist.h | 1 + tools/perf/util/stat-shadow.c | 433 ++++++++++++++++++++++++++---------------- tools/perf/util/stat.c | 15 +- tools/perf/util/stat.h | 63 +++++- tools/perf/util/target.h | 7 + tools/perf/util/thread_map.c | 19 +- tools/perf/util/thread_map.h | 3 +- 11 files changed, 519 insertions(+), 212 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/9 perf util: Create rblist__reset() function
Currently we have a rblist__delete() which is used to delete a rblist. While rblist__delete() will free the pointer of rblist at the end.
It's inconvenience for user to delete a rblist which is not allocated by something like malloc(). For example, the rblist is defined in a data structure.
This patch creates a new function rblist__reset() which function is similar as rblist__delete() but it will not free the rblist.
--- tools/perf/util/rblist.c | 24 +++++++++++++++++------- tools/perf/util/rblist.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-)
tools/perf/util/rblist.c +17 -7
@@ -101,20 +101,30 @@ void rblist__init(struct rblist *rblist)return ; } +static void remove_nodes (struct rblist *rblist) +{ +struct rb_node *pos, *next =rb_first (&rblist->entries); + +while (next) { + pos = next; + next =rb_next (pos); +rblist__remove_node (rblist, pos); + } +} +void rblist__delete (struct rblist *rblist) {if (rblist !=NULL ) { -struct rb_node *pos, *next =rb_first (&rblist->entries); - -while (next) { - pos = next; - next =rb_next (pos); -rblist__remove_node (rblist, pos); - } +remove_nodes (rblist);free (rblist); } } +void rblist__reset (struct rblist *rblist) +{ +remove_nodes (rblist); +} +struct rb_node *rblist__entry (const struct rblist *rblist,unsigned int idx) {struct rb_node *node;
tools/perf/util/rblist.h +1 -0
@@ -35,6 +35,7 @@ void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node);struct rb_node *rblist__find (struct rblist *rblist,const void *entry);struct rb_node *rblist__findnew (struct rblist *rblist,const void *entry);struct rb_node *rblist__entry (const struct rblist *rblist,unsigned int idx); +void rblist__reset (struct rblist *rblist);static inline bool rblist__empty (const struct rblist *rblist) {
Signature · 1 line
2.7.4
PATCH 3/9 perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoIn current stat-shadow.c, the rblist deleting is ignored.
The patch reconstructs the codes of rblist init/free, and adds the implementation to node_delete method of rblist.
This patch also does:
1. Add the ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats.
2. Create a static runtime_stat variable 'rt_stat' which will log the shadow metrics by default.
--- tools/perf/util/stat-shadow.c | 62 ++++++++++++++++++++++++++++++++++++++++--- tools/perf/util/stat.h | 2 ++ 2 files changed, 60 insertions(+), 4 deletions(-)
tools/perf/util/stat-shadow.c +58 -4
@@ -40,12 +40,16 @@ static struct stats runtime_aperf_stats[NUM_CTX][MAX_NR_CPUS];static struct rblist runtime_saved_values;static bool have_frontend_stalled; +static struct runtime_stat rt_stat;struct stats walltime_nsecs_stats;struct saved_value {struct rb_node rb_node;struct perf_evsel *evsel; +enum stat_type type; +int ctx;int cpu; +struct runtime_stat *stat;struct stats stats; };
@@ -58,6 +62,23 @@ static int saved_value_cmp(struct rb_node *rb_node, const void *entry)if (a->cpu != b->cpu)return a->cpu - b->cpu; + +if (a->type != b->type) +return a->type - b->type; + +if (a->ctx != b->ctx) +return a->ctx - b->ctx; + +if (a->evsel ==NULL && b->evsel ==NULL ) { +if (a->stat == b->stat) +return 0 ; + +if ((char *)a->stat < (char *)b->stat) +return -1 ; + +return 1 ; + } +if (a->evsel == b->evsel)return 0 ;if ((char *)a->evsel < (char *)b->evsel)
@@ -76,6 +97,17 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused,return &nd->rb_node; } +static void saved_value_delete (struct rblist *rblist__maybe_unused , +struct rb_node *rb_node) +{ +struct saved_value *v =container_of (rb_node, + struct saved_value, + rb_node); + +if (v) +free (v); +} +static struct saved_value *saved_value_lookup (struct perf_evsel *evsel,int cpu,bool create)
@@ -97,13 +129,35 @@ static struct saved_value *saved_value_lookup(struct perf_evsel *evsel,return NULL ; } +static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete; +} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat )); +init_saved_rblist (&stat->value_list); +} + +void perf_stat__free_runtime_stat (struct runtime_stat *stat) +{ +free_saved_rblist (&stat->value_list); +} +void perf_stat__init_shadow_stats (void ) { have_frontend_stalled =pmu_have_event ("cpu" ,"stalled-cycles-frontend" ); -rblist__init (&runtime_saved_values); - runtime_saved_values.node_cmp = saved_value_cmp; - runtime_saved_values.node_new = saved_value_new; -/* No delete for now */ +memset (&walltime_nsecs_stats,0 ,sizeof (walltime_nsecs_stats)); +perf_stat__init_runtime_stat (&rt_stat); }static int evsel_context (struct perf_evsel *evsel)
tools/perf/util/stat.h +2 -0
@@ -126,6 +126,8 @@ typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, const char *fmt, double val);typedef void (*new_line_t )(void *ctx); +void perf_stat__init_runtime_stat (struct runtime_stat *stat); +void perf_stat__free_runtime_stat (struct runtime_stat *stat);void perf_stat__init_shadow_stats (void );void perf_stat__reset_shadow_stats (void ); void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
Signature · 1 line
2.7.4
PATCH 4/9 perf util: Update and print per-thread shadow stats
In reply to Jin YaoThe functions perf_stat__update_shadow_stats() and perf_stat__print_shadow_statss() are called to update and print the shadow stats on a set of static variables.
But the static variables are the limitations to support per-thread shadow stats.
This patch lets the perf_stat__update_shadow_stats() support to update the shadow stats on a input parameter 'stat' and uses update_runtime_stat() to update the stats. It will not directly update the static variables as before.
And this patch also lets the perf_stat__print_shadow_stats() support to print the shadow stats from a input parameter 'stat'.
It will not directly get value from static variable. Instead, it now uses runtime_stat_avg() and runtime_stat_n() to get and compute the values.
--- tools/perf/builtin-stat.c | 25 ++-- tools/perf/util/stat-shadow.c | 296 +++++++++++++++++++++++++++--------------- tools/perf/util/stat.c | 15 ++- tools/perf/util/stat.h | 5 +- 4 files changed, 222 insertions(+), 119 deletions(-)
tools/perf/builtin-stat.c +16 -9
@@ -1151,7 +1151,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }static void printout (int id,int nr,struct perf_evsel *counter,double uval, -char *prefix,u64 run,u64 ena,double noise) +char *prefix,u64 run,u64 ena,double noise, +struct runtime_stat *stat) {struct perf_stat_output_ctx out;struct outstate os = {
@@ -1244,7 +1245,8 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,perf_stat__print_shadow_stats (counter, uval,first_shadow_cpu (counter, id), - &out, &metric_events); + &out, &metric_events, + stat);if (!csv_output && !metric_only) {print_noise (counter, noise);print_running (run, ena);
@@ -1268,7 +1270,7 @@ static void aggr_update_shadow(void) val +=perf_counts (counter->counts, cpu,0 )->val; }perf_stat__update_shadow_stats (counter, val, -first_shadow_cpu (counter, id)); +first_shadow_cpu (counter, id),NULL ); } } }
@@ -1388,7 +1390,8 @@ static void print_aggr(char *prefix)fprintf (output,"%s" , prefix); uval = val * counter->scale; -printout (id, nr, counter, uval, prefix, run, ena,1.0 ); +printout (id, nr, counter, uval, prefix, run, ena,1.0 , +NULL );if (!metric_only)fputc ('\n' , output); }
@@ -1418,7 +1421,8 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)fprintf (output,"%s" , prefix); uval = val * counter->scale; -printout (thread,0 , counter, uval, prefix, run, ena,1.0 ); +printout (thread,0 , counter, uval, prefix, run, ena,1.0 , + &stat_config.stats[thread]);fputc ('\n' , output); } }
@@ -1455,7 +1459,8 @@ static void print_counter_aggr(struct perf_evsel *counter, char *prefix)fprintf (output,"%s" , prefix); uval = cd.avg * counter->scale; -printout (-1 ,0 , counter, uval, prefix, cd.avg_running, cd.avg_enabled, cd.avg); +printout (-1 ,0 , counter, uval, prefix, cd.avg_running, cd.avg_enabled, + cd.avg,NULL );if (!metric_only)fprintf (output,"\n" ); }
@@ -1494,7 +1499,7 @@ static void print_counter(struct perf_evsel *counter, char *prefix)fprintf (output,"%s" , prefix); uval = val * counter->scale; -printout (cpu,0 , counter, uval, prefix, run, ena,1.0 ); +printout (cpu,0 , counter, uval, prefix, run, ena,1.0 ,NULL );fputc ('\n' , output); }
@@ -1526,7 +1531,8 @@ static void print_no_aggr_metric(char *prefix) run =perf_counts (counter->counts, cpu,0 )->run; uval = val * counter->scale; -printout (cpu,0 , counter, uval, prefix, run, ena,1.0 ); +printout (cpu,0 , counter, uval, prefix, run, ena,1.0 , +NULL ); }fputc ('\n' , stat_config.output); }
@@ -1582,7 +1588,8 @@ static void print_metric_headers(const char *prefix, bool no_indent)perf_stat__print_shadow_stats (counter,0 ,0 , &out, - &metric_events); + &metric_events, +NULL ); }fputc ('\n' , stat_config.output); }
tools/perf/util/stat-shadow.c +192 -104
646 lines not on this page · raw message
tools/perf/util/stat.c +11 -4
@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD ) -perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]); +else +perf_stat__update_shadow_stats (evsel, + count->val,0 ,NULL ); + }break ;case AGGR_GLOBAL : aggr->val += count->val;
@@ -362,7 +369,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,/* * Save the full runtime - to allow normalization during printout: */ -perf_stat__update_shadow_stats (counter, *count,0 ); +perf_stat__update_shadow_stats (counter, *count,0 ,NULL );return 0 ; }
tools/perf/util/stat.h +3 -2
@@ -131,7 +131,7 @@ void perf_stat__free_runtime_stat(struct runtime_stat *stat);void perf_stat__init_shadow_stats (void );void perf_stat__reset_shadow_stats (void );void perf_stat__update_shadow_stats (struct perf_evsel *counter,u64 count, -int cpu); +int cpu,struct runtime_stat *stat);struct perf_stat_output_ctx {void *ctx;print_metric_t print_metric;
@@ -142,7 +142,8 @@ struct perf_stat_output_ctx {void perf_stat__print_shadow_stats (struct perf_evsel *evsel,double avg,int cpu,struct perf_stat_output_ctx *out, -struct rblist *metric_events); +struct rblist *metric_events, +struct runtime_stat *stat);void perf_stat__collect_metric_expr (struct perf_evlist *);int perf_evlist__alloc_stats (struct perf_evlist *evlist,bool alloc_raw);
Signature · 1 line
2.7.4
PATCH 6/9 perf stat: Allocate shadow stats buffer for threads
In reply to Jin YaoAfter perf_evlist__create_maps() being executed, we can get all threads from /proc. And via thread_map__nr(), we can also get the number of threads.
With the number of threads, the patch allocates a buffer which will record the shadow stats for these threads.
The buffer pointer is saved in stat_config.
--- tools/perf/builtin-stat.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +45 -1
@@ -214,8 +214,13 @@ static inline void diff_timespec(struct timespec *r, struct timespec *a,static void perf_stat__reset_stats (void ) { +int i; +perf_evlist__reset_stats (evsel_list);perf_stat__reset_shadow_stats (); + +for (i =0 ; i < stat_config.stat_num; i++) +perf_stat__reset_shadow_per_stat (&stat_config.stats[i]); }static int create_perf_stat_counter (struct perf_evsel *evsel)
@@ -2548,6 +2553,35 @@ int process_cpu_map_event(struct perf_tool *tool,return set_maps (st); } +static int runtime_stat_alloc (struct perf_stat_config *config,int nthreads) +{ +int i; + + config->stats =calloc (nthreads,sizeof (struct runtime_stat )); +if (!config->stats) +return -1 ; + + config->stat_num = nthreads; + +for (i =0 ; i < nthreads; i++) +perf_stat__init_runtime_stat (&config->stats[i]); + +return 0 ; +} + +static void runtime_stat_free (struct perf_stat_config *config) +{ +int i; + +if (!config->stats) +return ; + +for (i =0 ; i < config->stat_num; i++) +perf_stat__free_runtime_stat (&config->stats[i]); + +free (config->stats); +} +static const char *const stat_report_usage[] = {"perf stat report [<options>]" ,NULL ,
@@ -2803,8 +2837,15 @@ int cmd_stat(int argc, const char **argv)* Initialize thread_map with comm names, * so we could print it out on output. */ -if (stat_config.aggr_mode ==AGGR_THREAD ) +if (stat_config.aggr_mode ==AGGR_THREAD ) {thread_map__read_comms (evsel_list->threads); +if (target.system_wide) { +if (runtime_stat_alloc (&stat_config, +thread_map__nr (evsel_list->threads))) { + goto out; + } + } + }if (interval && interval <100 ) {if (interval <10 ) {
@@ -2894,5 +2935,8 @@ int cmd_stat(int argc, const char **argv)sysfs__write_int (FREEZE_ON_SMI_PATH ,0 );perf_evlist__delete (evsel_list); + +runtime_stat_free (&stat_config); +return status; }
Signature · 1 line
2.7.4
PATCH 8/9 perf stat: Remove --per-thread pid/tid limitation
In reply to Jin YaoCurrently, if we execute 'perf stat --per-thread' without specifying pid/tid, perf will return error.
root@skl:/tmp# perf stat --per-thread
The --per-thread option is only available when monitoring via -p -t options.
-p, --pid <pid> stat events on existing process id
-t, --tid <tid> stat events on existing thread idThis patch removes this limitation. If no pid/tid specified, it returns all threads (get threads from /proc).
--- tools/perf/builtin-stat.c | 23 +++++++++++++++-------- tools/perf/util/target.h | 7 +++++++ 2 files changed, 22 insertions(+), 8 deletions(-)
tools/perf/builtin-stat.c +15 -8
@@ -277,7 +277,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->enable_on_exec =1 ; } -if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target))return perf_evsel__open_per_cpu (evsel,perf_evsel__cpus (evsel));return perf_evsel__open_per_thread (evsel, evsel_list->threads);
@@ -340,7 +340,7 @@ static int read_counter(struct perf_evsel *counter)int nthreads =thread_map__nr (evsel_list->threads);int ncpus, cpu, thread; -if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target)) ncpus =perf_evsel__nr_cpus (counter);else ncpus =1 ;
@@ -2791,12 +2791,16 @@ int cmd_stat(int argc, const char **argv) run_count =1 ; } -if ((stat_config.aggr_mode ==AGGR_THREAD ) && !target__has_task (&target)) { -fprintf (stderr,"The --per-thread option is only available " -"when monitoring via -p -t options.\n" ); -parse_options_usage (NULL , stat_options,"p" ,1 ); -parse_options_usage (NULL , stat_options,"t" ,1 ); - goto out; +if ((stat_config.aggr_mode ==AGGR_THREAD ) && + !target__has_task (&target)) { +if (!target.system_wide || target.cpu_list) { +fprintf (stderr,"The --per-thread option is only " +"available when monitoring via -p -t " +"options.\n" ); +parse_options_usage (NULL , stat_options,"p" ,1 ); +parse_options_usage (NULL , stat_options,"t" ,1 ); + goto out; + } }/*
@@ -2820,6 +2824,9 @@ int cmd_stat(int argc, const char **argv)target__validate (&target); +if ((stat_config.aggr_mode ==AGGR_THREAD ) && (target.system_wide)) + target.per_thread = true; +if (perf_evlist__create_maps (evsel_list, &target) <0 ) {if (target__has_task (&target)) {pr_err ("Problems finding threads of monitor\n" );
tools/perf/util/target.h +7 -0
@@ -64,6 +64,11 @@ static inline bool target__none(struct target *target)return !target__has_task (target) && !target__has_cpu (target); } +static inline bool target__has_per_thread (struct target *target) +{ +return target->system_wide && target->per_thread; +} +static inline bool target__uses_dummy_map (struct target *target) {bool use_dummy = false;
@@ -73,6 +78,8 @@ static inline bool target__uses_dummy_map(struct target *target)else if (target__has_task (target) || (!target__has_cpu (target) && !target->uses_mmap)) use_dummy = true; +else if (target__has_per_thread (target)) + use_dummy = true;return use_dummy; }
Signature · 1 line
2.7.4
PATCH 7/9 perf util: Reuse thread_map__new_by_uid to enumerate threads from /proc
In reply to Jin YaoPerf already has a function thread_map__new_by_uid() which can enumerate all threads from /proc by uid.
This patch creates a static function enumerate_threads() which reuses the common code in thread_map__new_by_uid() to enumerate threads from /proc.
The enumerate_threads() is shared by thread_map__new_by_uid() and a new function thread_map__new_threads().
The new function thread_map__new_threads() is called to enumerate all threads from /proc.
--- tools/perf/tests/thread-map.c | 2 +- tools/perf/util/evlist.c | 3 ++- tools/perf/util/thread_map.c | 19 ++++++++++++++++--- tools/perf/util/thread_map.h | 3 ++- 4 files changed, 21 insertions(+), 6 deletions(-)
tools/perf/tests/thread-map.c +1 -1
@@ -105,7 +105,7 @@ int test__thread_map_remove(struct test *test __maybe_unused, int subtest __maybTEST_ASSERT_VAL ("failed to allocate map string" ,asprintf (&str,"%d,%d" ,getpid (),getppid ()) >=0 ); - threads =thread_map__new_str (str,NULL ,0 ); + threads =thread_map__new_str (str,NULL ,0 , false);TEST_ASSERT_VAL ("failed to allocate thread_map" , threads);
tools/perf/util/evlist.c +2 -1
@@ -1102,7 +1102,8 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct cpu_map *cpus;struct thread_map *threads; - threads =thread_map__new_str (target->pid, target->tid, target->uid); + threads =thread_map__new_str (target->pid, target->tid, target->uid, + target->per_thread);if (!threads)return -1 ;
tools/perf/util/thread_map.c +16 -3
@@ -92,7 +92,7 @@ struct thread_map *thread_map__new_by_tid(pid_t tid)return threads; } -struct thread_map *thread_map__new_by_uid (uid_t uid) +static struct thread_map *enumerate_threads (uid_t uid) {DIR *proc;int max_threads =32 , items, i;
@@ -124,7 +124,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)if (stat (path, &st) !=0 )continue ; -if (st.st_uid != uid) +if ((uid !=UINT_MAX ) && (st.st_uid != uid))continue ;snprintf (path,sizeof (path),"/proc/%d/task" , pid);
@@ -178,6 +178,16 @@ struct thread_map *thread_map__new_by_uid(uid_t uid) goto out_closedir; } +struct thread_map *thread_map__new_by_uid (uid_t uid) +{ +return enumerate_threads (uid); +} + +struct thread_map *thread_map__new_threads (void ) +{ +return enumerate_threads (UINT_MAX ); +} +struct thread_map *thread_map__new (pid_t pid,pid_t tid,uid_t uid) {if (pid !=-1 )
@@ -313,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) }struct thread_map *thread_map__new_str (const char *pid,const char *tid, -uid_t uid) +uid_t uid,bool per_thread) {if (pid)return thread_map__new_by_pid_str (pid);
@@ -321,6 +331,9 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid,if (!tid && uid !=UINT_MAX )return thread_map__new_by_uid (uid); +if (per_thread) +return thread_map__new_threads (); +return thread_map__new_by_tid_str (tid); }
tools/perf/util/thread_map.h +2 -1
@@ -23,6 +23,7 @@ struct thread_map *thread_map__new_dummy(void);struct thread_map *thread_map__new_by_pid (pid_t pid);struct thread_map *thread_map__new_by_tid (pid_t tid);struct thread_map *thread_map__new_by_uid (uid_t uid); +struct thread_map *thread_map__new_threads (void );struct thread_map *thread_map__new (pid_t pid,pid_t tid,uid_t uid);struct thread_map *thread_map__new_event (struct thread_map_event *event);
@@ -30,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map);void thread_map__put (struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid, -const char *tid,uid_t uid); +const char *tid,uid_t uid,bool per_thread);struct thread_map *thread_map__new_by_tid_str (const char *tid_str);
Signature · 1 line
2.7.4
PATCH 9/9 perf stat: Resort '--per-thread' result
In reply to Jin YaoThere are many threads reported if we enable '--per-thread' globally.
1. Most of the threads are not counted or counting value 0. This patch removes these threads.
2. We also resort the threads in display according to the counting value. It's useful for user to see the hottest threads easily.
For example, the new results would be:
root@skl:/tmp# perf stat --per-thread ^C Performance counter stats for 'system wide':
perf-24165 4.302433 cpu-clock (msec) # 0.001 CPUs utilized
vmstat-23127 1.562215 cpu-clock (msec) # 0.000 CPUs utilized
irqbalance-2780 0.827851 cpu-clock (msec) # 0.000 CPUs utilized
sshd-23111 0.278308 cpu-clock (msec) # 0.000 CPUs utilized
thermald-2841 0.230880 cpu-clock (msec) # 0.000 CPUs utilized
sshd-23058 0.207306 cpu-clock (msec) # 0.000 CPUs utilized
kworker/0:2-19991 0.133983 cpu-clock (msec) # 0.000 CPUs utilized
kworker/u16:1-18249 0.125636 cpu-clock (msec) # 0.000 CPUs utilized
rcu_sched-8 0.085533 cpu-clock (msec) # 0.000 CPUs utilized
kworker/u16:2-23146 0.077139 cpu-clock (msec) # 0.000 CPUs utilized
gmain-2700 0.041789 cpu-clock (msec) # 0.000 CPUs utilized
kworker/4:1-15354 0.028370 cpu-clock (msec) # 0.000 CPUs utilized
kworker/6:0-17528 0.023895 cpu-clock (msec) # 0.000 CPUs utilized
kworker/4:1H-1887 0.013209 cpu-clock (msec) # 0.000 CPUs utilized
kworker/5:2-31362 0.011627 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/0-11 0.010892 cpu-clock (msec) # 0.000 CPUs utilized
kworker/3:2-12870 0.010220 cpu-clock (msec) # 0.000 CPUs utilized
ksoftirqd/0-7 0.008869 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/1-14 0.008476 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/7-50 0.002944 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/3-26 0.002893 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/4-32 0.002759 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/2-20 0.002429 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/6-44 0.001491 cpu-clock (msec) # 0.000 CPUs utilized
watchdog/5-38 0.001477 cpu-clock (msec) # 0.000 CPUs utilized
rcu_sched-8 10 context-switches # 0.117 M/sec
kworker/u16:1-18249 7 context-switches # 0.056 M/sec
sshd-23111 4 context-switches # 0.014 M/sec
vmstat-23127 4 context-switches # 0.003 M/sec
perf-24165 4 context-switches # 0.930 K/sec
kworker/0:2-19991 3 context-switches # 0.022 M/sec
kworker/u16:2-23146 3 context-switches # 0.039 M/sec
kworker/4:1-15354 2 context-switches # 0.070 M/sec
kworker/6:0-17528 2 context-switches # 0.084 M/sec
sshd-23058 2 context-switches # 0.010 M/sec
ksoftirqd/0-7 1 context-switches # 0.113 M/sec
watchdog/0-11 1 context-switches # 0.092 M/sec
watchdog/1-14 1 context-switches # 0.118 M/sec
watchdog/2-20 1 context-switches # 0.412 M/sec
watchdog/3-26 1 context-switches # 0.346 M/sec
watchdog/4-32 1 context-switches # 0.362 M/sec
watchdog/5-38 1 context-switches # 0.677 M/sec
watchdog/6-44 1 context-switches # 0.671 M/sec
watchdog/7-50 1 context-switches # 0.340 M/sec
kworker/4:1H-1887 1 context-switches # 0.076 M/sec
thermald-2841 1 context-switches # 0.004 M/sec
gmain-2700 1 context-switches # 0.024 M/sec
irqbalance-2780 1 context-switches # 0.001 M/sec
kworker/3:2-12870 1 context-switches # 0.098 M/sec
kworker/5:2-31362 1 context-switches # 0.086 M/sec
kworker/u16:1-18249 2 cpu-migrations # 0.016 M/sec
kworker/u16:2-23146 2 cpu-migrations # 0.026 M/sec
rcu_sched-8 1 cpu-migrations # 0.012 M/sec
sshd-23058 1 cpu-migrations # 0.005 M/sec
perf-24165 8,833,385 cycles # 2.053 GHz
vmstat-23127 1,702,699 cycles # 1.090 GHz
irqbalance-2780 739,847 cycles # 0.894 GHz
sshd-23111 269,506 cycles # 0.968 GHz
thermald-2841 204,556 cycles # 0.886 GHz
sshd-23058 158,780 cycles # 0.766 GHz
kworker/0:2-19991 112,981 cycles # 0.843 GHz
kworker/u16:1-18249 100,926 cycles # 0.803 GHz
rcu_sched-8 74,024 cycles # 0.865 GHz
kworker/u16:2-23146 55,984 cycles # 0.726 GHz
gmain-2700 34,278 cycles # 0.820 GHz
kworker/4:1-15354 20,665 cycles # 0.728 GHz
kworker/6:0-17528 16,445 cycles # 0.688 GHz
kworker/5:2-31362 9,492 cycles # 0.816 GHz
watchdog/3-26 8,695 cycles # 3.006 GHz
kworker/4:1H-1887 8,238 cycles # 0.624 GHz
watchdog/4-32 7,580 cycles # 2.747 GHz
kworker/3:2-12870 7,306 cycles # 0.715 GHz
watchdog/2-20 7,274 cycles # 2.995 GHz
watchdog/0-11 6,988 cycles # 0.642 GHz
ksoftirqd/0-7 6,376 cycles # 0.719 GHz
watchdog/1-14 5,340 cycles # 0.630 GHz
watchdog/5-38 4,061 cycles # 2.749 GHz
watchdog/6-44 3,976 cycles # 2.667 GHz
watchdog/7-50 3,418 cycles # 1.161 GHz
vmstat-23127 2,511,699 instructions # 1.48 insn per cycle
perf-24165 1,829,908 instructions # 0.21 insn per cycle
irqbalance-2780 1,190,204 instructions # 1.61 insn per cycle
thermald-2841 143,544 instructions # 0.70 insn per cycle
sshd-23111 128,138 instructions # 0.48 insn per cycle
sshd-23058 57,654 instructions # 0.36 insn per cycle
rcu_sched-8 44,063 instructions # 0.60 insn per cycle
kworker/u16:1-18249 42,551 instructions # 0.42 insn per cycle
kworker/0:2-19991 25,873 instructions # 0.23 insn per cycle
kworker/u16:2-23146 21,407 instructions # 0.38 insn per cycle
gmain-2700 13,691 instructions # 0.40 insn per cycle
kworker/4:1-15354 12,964 instructions # 0.63 insn per cycle
kworker/6:0-17528 10,034 instructions # 0.61 insn per cycle
kworker/5:2-31362 5,203 instructions # 0.55 insn per cycle
kworker/3:2-12870 4,866 instructions # 0.67 insn per cycle
kworker/4:1H-1887 3,586 instructions # 0.44 insn per cycle
ksoftirqd/0-7 3,463 instructions # 0.54 insn per cycle
watchdog/0-11 3,135 instructions # 0.45 insn per cycle
watchdog/1-14 3,135 instructions # 0.59 insn per cycle
watchdog/2-20 3,135 instructions # 0.43 insn per cycle
watchdog/3-26 3,135 instructions # 0.36 insn per cycle
watchdog/4-32 3,135 instructions # 0.41 insn per cycle
watchdog/5-38 3,135 instructions # 0.77 insn per cycle
watchdog/6-44 3,135 instructions # 0.79 insn per cycle
watchdog/7-50 3,135 instructions # 0.92 insn per cycle
vmstat-23127 539,181 branches # 345.139 M/sec
perf-24165 375,364 branches # 87.245 M/sec
irqbalance-2780 262,092 branches # 316.593 M/sec
thermald-2841 31,611 branches # 136.915 M/sec
sshd-23111 21,874 branches # 78.596 M/sec
sshd-23058 10,682 branches # 51.528 M/sec
rcu_sched-8 8,693 branches # 101.633 M/sec
kworker/u16:1-18249 7,891 branches # 62.808 M/sec
kworker/0:2-19991 5,761 branches # 42.998 M/sec
kworker/u16:2-23146 4,099 branches # 53.138 M/sec
kworker/4:1-15354 2,755 branches # 97.110 M/sec
gmain-2700 2,638 branches # 63.127 M/sec
kworker/6:0-17528 2,216 branches # 92.739 M/sec
kworker/5:2-31362 1,132 branches # 97.360 M/sec
kworker/3:2-12870 1,081 branches # 105.773 M/sec
kworker/4:1H-1887 725 branches # 54.887 M/sec
ksoftirqd/0-7 707 branches # 79.716 M/sec
watchdog/0-11 652 branches # 59.860 M/sec
watchdog/1-14 652 branches # 76.923 M/sec
watchdog/2-20 652 branches # 268.423 M/sec
watchdog/3-26 652 branches # 225.372 M/sec
watchdog/4-32 652 branches # 236.318 M/sec
watchdog/5-38 652 branches # 441.435 M/sec
watchdog/6-44 652 branches # 437.290 M/sec
watchdog/7-50 652 branches # 221.467 M/sec
vmstat-23127 8,960 branch-misses # 1.66% of all branches
irqbalance-2780 3,047 branch-misses # 1.16% of all branches
perf-24165 2,876 branch-misses # 0.77% of all branches
sshd-23111 1,843 branch-misses # 8.43% of all branches
thermald-2841 1,444 branch-misses # 4.57% of all branches
sshd-23058 1,379 branch-misses # 12.91% of all branches
kworker/u16:1-18249 982 branch-misses # 12.44% of all branches
rcu_sched-8 893 branch-misses # 10.27% of all branches
kworker/u16:2-23146 578 branch-misses # 14.10% of all branches
kworker/0:2-19991 376 branch-misses # 6.53% of all branches
gmain-2700 280 branch-misses # 10.61% of all branches
kworker/6:0-17528 196 branch-misses # 8.84% of all branches
kworker/4:1-15354 187 branch-misses # 6.79% of all branches
kworker/5:2-31362 123 branch-misses # 10.87% of all branches
watchdog/0-11 95 branch-misses # 14.57% of all branches
watchdog/4-32 89 branch-misses # 13.65% of all branches
kworker/3:2-12870 80 branch-misses # 7.40% of all branches
watchdog/3-26 61 branch-misses # 9.36% of all branches
kworker/4:1H-1887 60 branch-misses # 8.28% of all branches
watchdog/2-20 52 branch-misses # 7.98% of all branches
ksoftirqd/0-7 47 branch-misses # 6.65% of all branches
watchdog/1-14 46 branch-misses # 7.06% of all branches
watchdog/7-50 13 branch-misses # 1.99% of all branches
watchdog/5-38 8 branch-misses # 1.23% of all branches
watchdog/6-44 7 branch-misses # 1.07% of all branches3.695150786 seconds time elapsed
root@skl:/tmp# perf stat --per-thread -M IPC,CPI ^C
Performance counter stats for 'system wide':
vmstat-23127 2,000,783 inst_retired.any # 1.5 IPC
thermald-2841 1,472,670 inst_retired.any # 1.3 IPC
sshd-23111 977,374 inst_retired.any # 1.2 IPC
perf-24163 483,779 inst_retired.any # 0.2 IPC
gmain-2700 341,213 inst_retired.any # 0.9 IPC
sshd-23058 148,891 inst_retired.any # 0.8 IPC
rtkit-daemon-3288 71,210 inst_retired.any # 0.7 IPC
kworker/u16:1-18249 39,562 inst_retired.any # 0.3 IPC
rcu_sched-8 14,474 inst_retired.any # 0.8 IPC
kworker/0:2-19991 7,659 inst_retired.any # 0.2 IPC
kworker/4:1-15354 6,714 inst_retired.any # 0.8 IPC
rtkit-daemon-3289 4,839 inst_retired.any # 0.3 IPC
kworker/6:0-17528 3,321 inst_retired.any # 0.6 IPC
kworker/5:2-31362 3,215 inst_retired.any # 0.5 IPC
kworker/7:2-23145 3,173 inst_retired.any # 0.7 IPC
kworker/4:1H-1887 1,719 inst_retired.any # 0.3 IPC
watchdog/0-11 1,479 inst_retired.any # 0.3 IPC
watchdog/1-14 1,479 inst_retired.any # 0.3 IPC
watchdog/2-20 1,479 inst_retired.any # 0.4 IPC
watchdog/3-26 1,479 inst_retired.any # 0.4 IPC
watchdog/4-32 1,479 inst_retired.any # 0.3 IPC
watchdog/5-38 1,479 inst_retired.any # 0.3 IPC
watchdog/6-44 1,479 inst_retired.any # 0.7 IPC
watchdog/7-50 1,479 inst_retired.any # 0.7 IPC
kworker/u16:2-23146 1,408 inst_retired.any # 0.5 IPC
perf-24163 2,249,872 cpu_clk_unhalted.thread
vmstat-23127 1,352,455 cpu_clk_unhalted.thread
thermald-2841 1,161,140 cpu_clk_unhalted.thread
sshd-23111 807,827 cpu_clk_unhalted.thread
gmain-2700 375,535 cpu_clk_unhalted.thread
sshd-23058 194,071 cpu_clk_unhalted.thread
kworker/u16:1-18249 114,306 cpu_clk_unhalted.thread
rtkit-daemon-3288 103,547 cpu_clk_unhalted.thread
kworker/0:2-19991 46,550 cpu_clk_unhalted.thread
rcu_sched-8 18,855 cpu_clk_unhalted.thread
rtkit-daemon-3289 17,549 cpu_clk_unhalted.thread
kworker/4:1-15354 8,812 cpu_clk_unhalted.thread
kworker/5:2-31362 6,812 cpu_clk_unhalted.thread
kworker/4:1H-1887 5,270 cpu_clk_unhalted.thread
kworker/6:0-17528 5,111 cpu_clk_unhalted.thread
kworker/7:2-23145 4,667 cpu_clk_unhalted.thread
watchdog/0-11 4,663 cpu_clk_unhalted.thread
watchdog/1-14 4,663 cpu_clk_unhalted.thread
watchdog/4-32 4,626 cpu_clk_unhalted.thread
watchdog/5-38 4,403 cpu_clk_unhalted.thread
watchdog/3-26 3,936 cpu_clk_unhalted.thread
watchdog/2-20 3,850 cpu_clk_unhalted.thread
kworker/u16:2-23146 2,654 cpu_clk_unhalted.thread
watchdog/6-44 2,017 cpu_clk_unhalted.thread
watchdog/7-50 2,017 cpu_clk_unhalted.thread
vmstat-23127 2,000,783 inst_retired.any # 0.7 CPI
thermald-2841 1,472,670 inst_retired.any # 0.8 CPI
sshd-23111 977,374 inst_retired.any # 0.8 CPI
perf-24163 495,037 inst_retired.any # 4.7 CPI
gmain-2700 341,213 inst_retired.any # 1.1 CPI
sshd-23058 148,891 inst_retired.any # 1.3 CPI
rtkit-daemon-3288 71,210 inst_retired.any # 1.5 CPI
kworker/u16:1-18249 39,562 inst_retired.any # 2.9 CPI
rcu_sched-8 14,474 inst_retired.any # 1.3 CPI
kworker/0:2-19991 7,659 inst_retired.any # 6.1 CPI
kworker/4:1-15354 6,714 inst_retired.any # 1.3 CPI
rtkit-daemon-3289 4,839 inst_retired.any # 3.6 CPI
kworker/6:0-17528 3,321 inst_retired.any # 1.5 CPI
kworker/5:2-31362 3,215 inst_retired.any # 2.1 CPI
kworker/7:2-23145 3,173 inst_retired.any # 1.5 CPI
kworker/4:1H-1887 1,719 inst_retired.any # 3.1 CPI
watchdog/0-11 1,479 inst_retired.any # 3.2 CPI
watchdog/1-14 1,479 inst_retired.any # 3.2 CPI
watchdog/2-20 1,479 inst_retired.any # 2.6 CPI
watchdog/3-26 1,479 inst_retired.any # 2.7 CPI
watchdog/4-32 1,479 inst_retired.any # 3.1 CPI
watchdog/5-38 1,479 inst_retired.any # 3.0 CPI
watchdog/6-44 1,479 inst_retired.any # 1.4 CPI
watchdog/7-50 1,479 inst_retired.any # 1.4 CPI
kworker/u16:2-23146 1,408 inst_retired.any # 1.9 CPI
perf-24163 2,302,323 cycles
vmstat-23127 1,352,455 cycles
thermald-2841 1,161,140 cycles
sshd-23111 807,827 cycles
gmain-2700 375,535 cycles
sshd-23058 194,071 cycles
kworker/u16:1-18249 114,306 cycles
rtkit-daemon-3288 103,547 cycles
kworker/0:2-19991 46,550 cycles
rcu_sched-8 18,855 cycles
rtkit-daemon-3289 17,549 cycles
kworker/4:1-15354 8,812 cycles
kworker/5:2-31362 6,812 cycles
kworker/4:1H-1887 5,270 cycles
kworker/6:0-17528 5,111 cycles
kworker/7:2-23145 4,667 cycles
watchdog/0-11 4,663 cycles
watchdog/1-14 4,663 cycles
watchdog/4-32 4,626 cycles
watchdog/5-38 4,403 cycles
watchdog/3-26 3,936 cycles
watchdog/2-20 3,850 cycles
kworker/u16:2-23146 2,654 cycles
watchdog/6-44 2,017 cycles
watchdog/7-50 2,017 cycles2.175726600 seconds time elapsed
--- tools/perf/builtin-stat.c | 71 +++++++++++++++++++++++++++++++++++++++++------ tools/perf/util/stat.h | 9 ++++++ 2 files changed, 72 insertions(+), 8 deletions(-)
tools/perf/builtin-stat.c +63 -8
@@ -1405,13 +1405,24 @@ static void print_aggr(char *prefix) } } -static void print_aggr_thread (struct perf_evsel *counter,char *prefix) +static int cmp_val (const void *a,const void *b) { -FILE *output = stat_config.output; -int nthreads =thread_map__nr (counter->threads); -int ncpus =cpu_map__nr (counter->cpus); -int cpu, thread; +return ((struct perf_aggr_thread_value *)b)->val - + ((struct perf_aggr_thread_value *)a)->val; +} + +static struct perf_aggr_thread_value *sort_aggr_thread ( +struct perf_evsel *counter, +int nthreads,int ncpus, +int *ret) +{ +int cpu, thread, i =0 ;double uval; +struct perf_aggr_thread_value *buf; + + buf =calloc (nthreads,sizeof (struct perf_aggr_thread_value )); +if (!buf) +return NULL ;for (thread =0 ; thread < nthreads; thread++) {u64 ena =0 , run =0 , val =0 ;
@@ -1422,14 +1433,58 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix) run +=perf_counts (counter->counts, cpu, thread)->run; } + uval = val * counter->scale; + +/* +* Skip value 0 when enabling --per-thread globally, +* otherwise too many 0 output. +*/ +if (uval ==0.0 &&target__has_per_thread (&target)) +continue ; + + buf[i].counter = counter; + buf[i].id = thread; + buf[i].uval = uval; + buf[i].val = val; + buf[i].run = run; + buf[i].ena = ena; + i++; + } + +qsort (buf, i,sizeof (struct perf_aggr_thread_value ), cmp_val); + +if (ret) + *ret = i; + +return buf; +} + +static void print_aggr_thread (struct perf_evsel *counter,char *prefix) +{ +FILE *output = stat_config.output; +int nthreads =thread_map__nr (counter->threads); +int ncpus =cpu_map__nr (counter->cpus); +int thread, sorted_threads, id; +struct perf_aggr_thread_value *buf; + + buf =sort_aggr_thread (counter, nthreads, ncpus, &sorted_threads); +if (!buf) { +perror ("cannot sort aggr thread" ); +return ; + } + +for (thread =0 ; thread < sorted_threads; thread++) {if (prefix)fprintf (output,"%s" , prefix); - uval = val * counter->scale; -printout (thread,0 , counter, uval, prefix, run, ena,1.0 , - &stat_config.stats[thread]); + id = buf[thread].id; +printout (id,0 , buf[thread].counter, buf[thread].uval, + prefix, buf[thread].run, buf[thread].ena,1.0 , + &stat_config.stats[id]);fputc ('\n' , output); } + +free (buf); }struct caggr_data {
tools/perf/util/stat.h +9 -0
@@ -112,6 +112,15 @@ static inline void init_stats(struct stats *stats)struct perf_evsel ;struct perf_evlist ; +struct perf_aggr_thread_value { +struct perf_evsel *counter; +int id; +double uval; +u64 val; +u64 run; +u64 ena; +}; +bool __perf_evsel_stat__is (struct perf_evsel *evsel,enum perf_stat_evsel_id id);
Signature · 1 line
2.7.4
PATCH 5/9 perf util: Remove a set of shadow stats static variables
In reply to Jin YaoIn previous patches, we have reconstructed the code and let it not access the static variables directly.
This patch removes these static variables.
--- tools/perf/util/stat-shadow.c | 64 ++++++++++--------------------------------- tools/perf/util/stat.h | 1 + 2 files changed, 16 insertions(+), 49 deletions(-)
tools/perf/util/stat-shadow.c +15 -49
@@ -16,28 +16,6 @@* AGGR_NONE: Use matching CPU * AGGR_THREAD: Not supported? */ -static struct stats runtime_nsecs_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_front_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_back_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_branches_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_cacherefs_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_l1_dcache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_l1_icache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_ll_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_itlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_dtlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_cycles_in_tx_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_transaction_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_elision_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_total_slots[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_slots_issued[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_slots_retired[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_fetch_bubbles[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_recovery_bubbles[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_smi_num_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_aperf_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct rblist runtime_saved_values;static bool have_frontend_stalled;static struct runtime_stat rt_stat;
@@ -191,36 +169,13 @@ static int evsel_context(struct perf_evsel *evsel)return ctx; } -void perf_stat__reset_shadow_stats (void ) +static void reset_stat (struct runtime_stat *stat) { +struct rblist *rblist;struct rb_node *pos, *next; -memset (runtime_nsecs_stats,0 ,sizeof (runtime_nsecs_stats)); -memset (runtime_cycles_stats,0 ,sizeof (runtime_cycles_stats)); -memset (runtime_stalled_cycles_front_stats,0 ,sizeof (runtime_stalled_cycles_front_stats)); -memset (runtime_stalled_cycles_back_stats,0 ,sizeof (runtime_stalled_cycles_back_stats)); -memset (runtime_branches_stats,0 ,sizeof (runtime_branches_stats)); -memset (runtime_cacherefs_stats,0 ,sizeof (runtime_cacherefs_stats)); -memset (runtime_l1_dcache_stats,0 ,sizeof (runtime_l1_dcache_stats)); -memset (runtime_l1_icache_stats,0 ,sizeof (runtime_l1_icache_stats)); -memset (runtime_ll_cache_stats,0 ,sizeof (runtime_ll_cache_stats)); -memset (runtime_itlb_cache_stats,0 ,sizeof (runtime_itlb_cache_stats)); -memset (runtime_dtlb_cache_stats,0 ,sizeof (runtime_dtlb_cache_stats)); -memset (runtime_cycles_in_tx_stats,0 , -sizeof (runtime_cycles_in_tx_stats)); -memset (runtime_transaction_stats,0 , -sizeof (runtime_transaction_stats)); -memset (runtime_elision_stats,0 ,sizeof (runtime_elision_stats)); -memset (&walltime_nsecs_stats,0 ,sizeof (walltime_nsecs_stats)); -memset (runtime_topdown_total_slots,0 ,sizeof (runtime_topdown_total_slots)); -memset (runtime_topdown_slots_retired,0 ,sizeof (runtime_topdown_slots_retired)); -memset (runtime_topdown_slots_issued,0 ,sizeof (runtime_topdown_slots_issued)); -memset (runtime_topdown_fetch_bubbles,0 ,sizeof (runtime_topdown_fetch_bubbles)); -memset (runtime_topdown_recovery_bubbles,0 ,sizeof (runtime_topdown_recovery_bubbles)); -memset (runtime_smi_num_stats,0 ,sizeof (runtime_smi_num_stats)); -memset (runtime_aperf_stats,0 ,sizeof (runtime_aperf_stats)); - - next =rb_first (&runtime_saved_values.entries); + rblist = &stat->value_list; + next =rb_first (&rblist->entries);while (next) { pos = next; next =rb_next (pos);
@@ -230,6 +185,17 @@ void perf_stat__reset_shadow_stats(void) } } +void perf_stat__reset_shadow_stats (void ) +{ +reset_stat (&rt_stat); +memset (&walltime_nsecs_stats,0 ,sizeof (walltime_nsecs_stats)); +} + +void perf_stat__reset_shadow_per_stat (struct runtime_stat *stat) +{ +reset_stat (stat); +} +static void update_runtime_stat (struct runtime_stat *stat,enum stat_type type,int ctx,int cpu,u64 count)
tools/perf/util/stat.h +1 -0
@@ -130,6 +130,7 @@ void perf_stat__init_runtime_stat(struct runtime_stat *stat);void perf_stat__free_runtime_stat (struct runtime_stat *stat);void perf_stat__init_shadow_stats (void );void perf_stat__reset_shadow_stats (void ); +void perf_stat__reset_shadow_per_stat (struct runtime_stat *stat);void perf_stat__update_shadow_stats (struct perf_evsel *counter,u64 count,int cpu,struct runtime_stat *stat);struct perf_stat_output_ctx {
Signature · 1 line
2.7.4
PATCH 2/9 perf util: Define a structure for runtime shadow metrics stats
In reply to Jin YaoPerf has a set of static variables to record the runtime shadow metrics stats.
While if we want to record the runtime shadow stats for per-thread, it will be the limitation. This patch creates a structure and the next patches will use this structure to update the runtime shadow stats for per-thread.
--- tools/perf/util/stat-shadow.c | 11 ----------- tools/perf/util/stat.h | 46 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 12 deletions(-)
tools/perf/util/stat-shadow.c +0 -11
@@ -9,17 +9,6 @@#include "expr.h" #include "metricgroup.h" -enum { -CTX_BIT_USER =1 <<0 , -CTX_BIT_KERNEL =1 <<1 , -CTX_BIT_HV =1 <<2 , -CTX_BIT_HOST =1 <<3 , -CTX_BIT_IDLE =1 <<4 , -CTX_BIT_MAX =1 <<5 , -}; - -#define NUM_CTX CTX_BIT_MAX -/* * AGGR_GLOBAL: Use CPU 0 * AGGR_SOCKET: Use first CPU of socket
tools/perf/util/stat.h +45 -1
69 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 4 lines · Jin Yao
perf stat --per-thread is useful to break down data per thread. But it currently requires specifying --pid/--tid to limit it to a process.
For analysis it would be useful to do it globally for the whole system.
I can't compile this:
builtin-script.c: In function ‘perf_sample__fprint_metric’:
builtin-script.c:1549:2: error: too few arguments to function ‘perf_stat__update_shadow_stats’
perf_stat__update_shadow_stats(evsel,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from builtin-script.c:24:0:util/stat.h:134:6: note: declared here
void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
builtin-script.c:1555:4: error: too few arguments to function ‘perf_stat__print_shadow_stats’
perf_stat__print_shadow_stats(ev2,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from builtin-script.c:24:0:
util/stat.h:143:6: note: declared here
void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~mv: cannot stat './.builtin-script.o.tmp': No such file or directory
thanks,
jirka
Quoted 23 lines · Jiri Olsa
Quoted 4 lines · Jin Yao
perf stat --per-thread is useful to break down data per thread. But it currently requires specifying --pid/--tid to limit it to a process.
For analysis it would be useful to do it globally for the whole system.
I can't compile this:
builtin-script.c: In function ‘perf_sample__fprint_metric’:
builtin-script.c:1549:2: error: too few arguments to function ‘perf_stat__update_shadow_stats’
perf_stat__update_shadow_stats(evsel,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from builtin-script.c:24:0:util/stat.h:134:6: note: declared here
void perf_stat__update_shadow_stats(structperf_evsel*counter, u64 count,^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ builtin-script.c:1555:4: error: too few arguments to function ‘perf_stat__print_shadow_stats’ perf_stat__print_shadow_stats(ev2, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from builtin-script.c:24:0: util/stat.h:143:6: note: declared here void perf_stat__print_shadow_stats(struct perf_evsel *evsel, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 5 lines
mv: cannot stat './.builtin-script.o.tmp': No such file or directory
thanks,
jirka
Hi Jiri,
This patch set is based on the latest perf/core branch.
I pull the branch right now and try the build again, the building is OK.
Could you tell me which branch you are testing on?
Thanks
Jin Yao
Quoted 32 lines · Yao
Quoted 23 lines · Jiri Olsa
Quoted 4 lines · Jin Yao
perf stat --per-thread is useful to break down data per thread. But it currently requires specifying --pid/--tid to limit it to a process.
For analysis it would be useful to do it globally for the whole system.
I can't compile this:
builtin-script.c: In function ‘perf_sample__fprint_metric’:
builtin-script.c:1549:2: error: too few arguments to function ‘perf_stat__update_shadow_stats’
perf_stat__update_shadow_stats(evsel,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from builtin-script.c:24:0:util/stat.h:134:6: note: declared here
void perf_stat__update_shadow_stats(structperf_evsel*counter, u64 count,^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ builtin-script.c:1555:4: error: too few arguments to function ‘perf_stat__print_shadow_stats’ perf_stat__print_shadow_stats(ev2, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from builtin-script.c:24:0: util/stat.h:143:6: note: declared here void perf_stat__print_shadow_stats(struct perf_evsel *evsel, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~Quoted 5 lines
mv: cannot stat './.builtin-script.o.tmp': No such file or directory
thanks,
jirka
Quoted 7 lines
Hi Jiri,
This patch set is based on the latest perf/core branch.
I pull the branch right now and try the build again, the building is OK.
Could you tell me which branch you are testing on?
ugh.. I was over Andi's changes.. I'll recheck
sry for noise
jirka
Quoted 9 lines
Quoted 7 lines
Hi Jiri,
This patch set is based on the latest perf/core branch.
I pull the branch right now and try the build again, the building is OK.
Could you tell me which branch you are testing on?
ugh.. I was over Andi's changes.. I'll recheck
Yes the two patch kits conflicts. Whoever gets merged first, the other has to rebase.
-Andi
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 7 lines
tools/perf/util/stat-shadow.c +6
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete;
tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 147
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat ));
what's this memset for? that struct has only rb_list
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 143
Quoted 13 lines
tools/perf/util/stat-shadow.c +12
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete; +} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +}
I don't see a reason for this code to be in separate functions.. could go directly in:
perf_stat__init_runtime_stat perf_stat__free_runtime_stat
jirka
Quoted 12 lines
tools/perf/util/stat-shadow.c +12
-0+ +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat )); +init_saved_rblist (&stat->value_list); +} + +void perf_stat__free_runtime_stat (struct runtime_stat *stat) +{ +free_saved_rblist (&stat->value_list); +} +
SNIP
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoQuoted 5 lines · Jin Yao
In current
stat-shadow.c, the rblist deleting is ignored.The patch reconstructs the codes of rblist init/free, and adds the implementation to
node_deletemethod of rblist.
Quoted 8 lines
This patch also does:
1. Add the ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats.
2. Create a static
runtime_statvariable 'rt_stat' which will log the shadow metrics by default.
please make that separate patches then,
one patch - one logical change
thanks,
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 22 lines
tools/perf/util/stat-shadow.c +22
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete; +} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat )); +init_saved_rblist (&stat->value_list); +} + +void perf_stat__free_runtime_stat (struct runtime_stat *stat) +{ +free_saved_rblist (&stat->value_list);
tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 159
Quoted 10 lines
tools/perf/util/stat-shadow.c +3
-4+} +void perf_stat__init_shadow_stats (void ) { have_frontend_stalled =pmu_have_event ("cpu" ,"stalled-cycles-frontend" ); -rblist__init (&runtime_saved_values); - runtime_saved_values.node_cmp = saved_value_cmp; - runtime_saved_values.node_new = saved_value_new; -/* No delete for now */ +memset (&walltime_nsecs_stats,0 ,sizeof (walltime_nsecs_stats));
why do you zero walltime_nsecs_stats in here?
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoQuoted 42 lines · Jin Yao
In current
stat-shadow.c, the rblist deleting is ignored.The patch reconstructs the codes of rblist init/free, and adds the implementation to
node_deletemethod of rblist.This patch also does:
1. Add the ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats.
2. Create a static
runtime_statvariable 'rt_stat' which will log the shadow metrics by default.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/stat-shadow.c | 62 ++++++++++++++++++++++++++++++++++++++++--- tools/perf/util/stat.h | 2 ++ 2 files changed, 60 insertions(+), 4 deletions(-)tools/perf/util/stat-shadow.c +4
-0@@ -40,12 +40,16 @@ static struct stats runtime_aperf_stats[NUM_CTX][MAX_NR_CPUS];static struct rblist runtime_saved_values;static bool have_frontend_stalled; +static struct runtime_stat rt_stat;struct stats walltime_nsecs_stats;struct saved_value {struct rb_node rb_node;struct perf_evsel *evsel; +enum stat_type type; +int ctx;int cpu; +struct runtime_stat *stat;struct stats stats; };
tools/perf/util/stat-shadow.c static int saved_value_cmp(struct rb_node *rb_node, const void *entry) · line 71
Quoted 10 lines
tools/perf/util/stat-shadow.c +7
-0@@ -58,6 +62,23 @@ static int saved_value_cmp(struct rb_node *rb_node, const void *entry)if (a->cpu != b->cpu)return a->cpu - b->cpu; + +if (a->type != b->type) +return a->type - b->type; + +if (a->ctx != b->ctx) +return a->ctx - b->ctx; +
could you please comment in here on the cases where evsel is defined and when not
jirka
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+if (a->evsel ==NULL && b->evsel ==NULL ) { +if (a->stat == b->stat) +return 0 ; + +if ((char *)a->stat < (char *)b->stat) +return -1 ; + +return 1 ; + } +
SNIP
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
tools/perf/util/stat.h typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, · line 130
Quoted 11 lines
static int
evsel_context(struct perf_evsel *evsel)tools/perf/util/stat.h +2
-0@@ -126,6 +126,8 @@ typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, const char *fmt, double val);typedef void (*new_line_t )(void *ctx); +void perf_stat__init_runtime_stat (struct runtime_stat *stat); +void perf_stat__free_runtime_stat (struct runtime_stat *stat);
maybe that could be:
runtime_stat__init(struct runtime_stat *stat);
runtime_stat__free(struct runtime_stat *stat);
jirka
Re: [PATCH v1 5/9] perf util: Remove a set of shadow stats static variables
In reply to Jin YaoQuoted 32 lines · Jin Yao
In previous patches, we have reconstructed the code and let it not access the static variables directly.
This patch removes these static variables.
Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/stat-shadow.c | 64 ++++++++++--------------------------------- tools/perf/util/stat.h | 1 + 2 files changed, 16 insertions(+), 49 deletions(-)tools/perf/util/stat-shadow.c +0
-13@@ -16,28 +16,6 @@* AGGR_NONE: Use matching CPU * AGGR_THREAD: Not supported? */ -static struct stats runtime_nsecs_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_front_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_back_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_branches_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_cacherefs_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_l1_dcache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_l1_icache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_ll_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_itlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_dtlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_cycles_in_tx_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_transaction_stats[NUM_CTX ][MAX_NR_CPUS ];
tools/perf/util/stat-shadow.c line 19
Quoted 10 lines
tools/perf/util/stat-shadow.c +0
-9-static struct stats runtime_elision_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_total_slots[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_slots_issued[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_slots_retired[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_fetch_bubbles[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_topdown_recovery_bubbles[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_smi_num_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct stats runtime_aperf_stats[NUM_CTX ][MAX_NR_CPUS ]; -static struct rblist runtime_saved_values;static bool have_frontend_stalled;
all this is about switching from array to rb_list for the --per-thread case, which can be considered as a special use case.. how much do we suffer in performance with new code? how about the "perf stat -I 100", would it scale ok for extreme cases (many events in -e or -dddd..)
jirka
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 19 lines
tools/perf/util/stat-shadow.c +5
-1@@ -110,19 +110,32 @@ static void saved_value_delete(struct rblist *rblist __maybe_unused,static struct saved_value *saved_value_lookup (struct perf_evsel *evsel,int cpu, -bool create) +bool create, +enum stat_type type, +int ctx, +struct runtime_stat *stat) { +struct rblist *rblist;struct rb_node *nd;struct saved_value dm = { .cpu = cpu, .evsel = evsel,
tools/perf/util/stat-shadow.c static void saved_value_delete(struct rblist *rblist __maybe_unused, · line 131
Quoted 10 lines
tools/perf/util/stat-shadow.c +8
-1+ .type = type, + .ctx = ctx, + .stat = stat, }; - nd =rblist__find (&runtime_saved_values, &dm); + +if (stat) + rblist = &stat->value_list; +else + rblist = &rt_stat.value_list;
please pass the correct 'struct runtime_stat *stat',
I don't see a reason noot to pass &rt_stat directly below:
Quoted 10 lines
tools/perf/util/stat.c +0
-2@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD )
tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 289
Quoted 10 lines
tools/perf/util/stat.c +9
-1-perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]); +else +perf_stat__update_shadow_stats (evsel, + count->val,0 ,NULL );
here
tools/perf/util/stat.c int perf_stat_process_counter(struct perf_stat_config *config, · line 372
Quoted 10 lines
tools/perf/util/stat.c +2
-1+ }break ;case AGGR_GLOBAL : aggr->val += count->val;@@ -362,7 +369,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,/* * Save the full runtime - to allow normalization during printout: */ -perf_stat__update_shadow_stats (counter, *count,0 ); +perf_stat__update_shadow_stats (counter, *count,0 ,NULL );
and here
thanks,
jirka
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 8 lines
tools/perf/util/stat-shadow.c +0
-0if (num ==0 )tools/perf/util/stat.c +0
-0@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );
tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 286
Quoted 10 lines
tools/perf/util/stat.c +6
-3if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD ) -perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]);
please add this part together with config->stats allocation/usage and keep this change only about adding the struct runtime_stat *stat into the code path with no functional change
thanks,
jirka
Re: [PATCH v1 2/9] perf util: Define a structure for runtime shadow metrics stats
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:37PM +0800, Jin Yao wrote:
SNIP
Quoted 6 lines
tools/perf/util/stat.h +6
-0+STAT_SMI_NUM , +STAT_APERF , +STAT_MAX +}; + +struct runtime_stat {
tools/perf/util/stat.h enum aggr_mode { · line 95
Quoted 10 lines
tools/perf/util/stat.h +5
-0+struct rblist value_list; +}; +struct perf_stat_config {enum aggr_mode aggr_mode;bool scale;FILE *output;unsigned int interval; +struct runtime_stat *stats; +int stat_num;
s/stat_num/stats_num/ or s/stats/stat/
thanks,
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
SNIP
tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv) · line 2799
Quoted 12 lines
tools/perf/builtin-stat.c +6
-6-if ((stat_config.aggr_mode ==AGGR_THREAD ) && !target__has_task (&target)) { -fprintf (stderr,"The --per-thread option is only available " -"when monitoring via -p -t options.\n" ); -parse_options_usage (NULL , stat_options,"p" ,1 ); -parse_options_usage (NULL , stat_options,"t" ,1 ); - goto out; +if ((stat_config.aggr_mode ==AGGR_THREAD ) && + !target__has_task (&target)) { +if (!target.system_wide || target.cpu_list) { +fprintf (stderr,"The --per-thread option is only " +"available when monitoring via -p -t " +"options.\n" );
the message should be updated with '-a' option, that you just added, also why dont we support target.cpu_list, it should work no?
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jin YaoOn Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
SNIP
tools/perf/util/target.h static inline bool target__none(struct target *target) · line 70
Quoted 12 lines
tools/perf/util/target.h +4
-0@@ -64,6 +64,11 @@ static inline bool target__none(struct target *target)return !target__has_task (target) && !target__has_cpu (target); } +static inline bool target__has_per_thread (struct target *target) +{ +return target->system_wide && target->per_thread; +}
this is confusing.. has_per_thread depends on system_wide?
tools/perf/util/target.h static inline bool target__uses_dummy_map(struct target *target) · line 82
Quoted 10 lines
tools/perf/util/target.h +3
-0+static inline bool target__uses_dummy_map (struct target *target) {bool use_dummy = false;@@ -73,6 +78,8 @@ static inline bool target__uses_dummy_map(struct target *target)else if (target__has_task (target) || (!target__has_cpu (target) && !target->uses_mmap)) use_dummy = true; +else if (target__has_per_thread (target)) + use_dummy = true;
why do we need dummy_map for this? please comment
thanks,
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jin YaoQuoted 22 lines · Jin Yao
Currently, if we execute 'perf stat --per-thread' without specifying pid/tid, perf will return error.
root@skl:/tmp# perf stat --per-thread The --per-thread option is only available when monitoring via -p -t options. -p, --pid <pid> stat events on existing process id -t, --tid <tid> stat events on existing thread idThis patch removes this limitation. If no pid/tid specified, it returns all threads (get threads from /proc).
Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-stat.c | 23 +++++++++++++++-------- tools/perf/util/target.h | 7 +++++++ 2 files changed, 22 insertions(+), 8 deletions(-)tools/perf/builtin-stat.c +0
-0
tools/perf/builtin-stat.c static int create_perf_stat_counter(struct perf_evsel *evsel) · line 280
Quoted 5 lines
tools/perf/builtin-stat.c +1
-1@@ -277,7 +277,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->enable_on_exec =1 ; } -if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target))
please add comment on why this is needed..
tools/perf/builtin-stat.c static int read_counter(struct perf_evsel *counter) · line 343
Quoted 9 lines
tools/perf/builtin-stat.c +1
-1return perf_evsel__open_per_cpu (evsel,perf_evsel__cpus (evsel));return perf_evsel__open_per_thread (evsel, evsel_list->threads);@@ -340,7 +340,7 @@ static int read_counter(struct perf_evsel *counter)int nthreads =thread_map__nr (evsel_list->threads);int ncpus, cpu, thread; -if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target))
same here
thanks,
jirka
Re: [PATCH v1 5/9] perf util: Remove a set of shadow stats static variables
In reply to Jiri OlsaQuoted 4 lines
all this is about switching from array to
rb_listfor the --per-thread case, which can be considered as a special use case.. how much do we suffer in performance with new code? how about the "perf stat -I 100", would it scale ok for extreme cases (many events in -e or -dddd..)
rbtrees scale by log N, with N being the entries in the tree.
Even in extreme cases, let's say 10000 events and 1000 cpus it would need only 8 memory accesses and comparisons for each look up. Even if we assume cache misses for all of the memory lookups, at ~200ns per cache miss it's still only 1us per event, which is negligible.
In practice not all memory accesses will be misses because the upper levels of the tree are almost certainly cached from earlier accesses.
-Andi
Re: [PATCH v1 5/9] perf util: Remove a set of shadow stats static variables
Quoted 13 lines · Andi Kleen
Quoted 4 lines
all this is about switching from array to
rb_listfor the --per-thread case, which can be considered as a special use case.. how much do we suffer in performance with new code? how about the "perf stat -I 100", would it scale ok for extreme cases (many events in -e or -dddd..)rbtrees scale by log N, with N being the entries in the tree.
Even in extreme cases, let's say 10000 events and 1000 cpus it would need only 8 memory accesses and comparisons for each look up. Even if we assume cache misses for all of the memory lookups, at ~200ns per cache miss it's still only 1us per event, which is negligible.
Quoted 3 lines
In practice not all memory accesses will be misses because the upper levels of the tree are almost certainly cached from earlier accesses.
sounds good, thanks
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 24 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 7 lines
tools/perf/util/stat-shadow.c +6
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete;tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 147
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat ));what's this memset for? that struct has only
rb_list
Quoted 2 lines
jirka
Currently this struct has only rblist. I use memset to zero this struct is for future potential new added fields to this struct.
If it's not good, I will remove this memset.
Thanks
Jin Yao
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 23 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 143
Quoted 13 lines
tools/perf/util/stat-shadow.c +12
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete; +} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +}I don't see a reason for this code to be in separate functions.. could go directly in:
perf_stat__init_runtime_statperf_stat__free_runtime_stat
Quoted 2 lines
jirka
Agree, that's better.
I will put this code in perf_stat__init_runtime_stat and perf_stat__free_runtime_stat.
Thanks
Jin Yao
Quoted 15 lines
Quoted 12 lines
tools/perf/util/stat-shadow.c +12
-0+ +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat )); +init_saved_rblist (&stat->value_list); +} + +void perf_stat__free_runtime_stat (struct runtime_stat *stat) +{ +free_saved_rblist (&stat->value_list); +} +SNIP
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 12 lines · Jiri Olsa
Quoted 11 lines · Jin Yao
In current
stat-shadow.c, the rblist deleting is ignored.The patch reconstructs the codes of rblist init/free, and adds the implementation to
node_deletemethod of rblist.This patch also does:
1. Add the ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats.
Quoted 9 lines
Quoted 2 lines
2. Create a static
runtime_statvariable 'rt_stat' which will log the shadow metrics by default.please make that separate patches then,
one patch - one logical changethanks,
jirka
OK, I will separate the patches.
Thanks
Jin Yao
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 39 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 22 lines
tools/perf/util/stat-shadow.c +22
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete; +} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat )); +init_saved_rblist (&stat->value_list); +} + +void perf_stat__free_runtime_stat (struct runtime_stat *stat) +{ +free_saved_rblist (&stat->value_list);tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 159
Quoted 10 lines
tools/perf/util/stat-shadow.c +3
-4+} +void perf_stat__init_shadow_stats (void ) { have_frontend_stalled =pmu_have_event ("cpu" ,"stalled-cycles-frontend" ); -rblist__init (&runtime_saved_values); - runtime_saved_values.node_cmp = saved_value_cmp; - runtime_saved_values.node_new = saved_value_new; -/* No delete for now */ +memset (&walltime_nsecs_stats,0 ,sizeof (walltime_nsecs_stats));why do you zero
walltime_nsecs_statsin here?
Quoted 2 lines
jirka
walltime_nsecs_stats is initialized in process_interval().
init_stats(&walltime_nsecs_stats);
Yes, the zero of walltime_nsecs_stats in perf_stat__init_shadow_stats looks a bit redundant. I will remove it.
Thanks
Jin Yao
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 57 lines · Jiri Olsa
Quoted 42 lines · Jin Yao
In current
stat-shadow.c, the rblist deleting is ignored.The patch reconstructs the codes of rblist init/free, and adds the implementation to
node_deletemethod of rblist.This patch also does:
1. Add the ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats.
2. Create a static
runtime_statvariable 'rt_stat' which will log the shadow metrics by default.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/stat-shadow.c | 62 ++++++++++++++++++++++++++++++++++++++++--- tools/perf/util/stat.h | 2 ++ 2 files changed, 60 insertions(+), 4 deletions(-)tools/perf/util/stat-shadow.c +4
-0@@ -40,12 +40,16 @@ static struct stats runtime_aperf_stats[NUM_CTX][MAX_NR_CPUS];static struct rblist runtime_saved_values;static bool have_frontend_stalled; +static struct runtime_stat rt_stat;struct stats walltime_nsecs_stats;struct saved_value {struct rb_node rb_node;struct perf_evsel *evsel; +enum stat_type type; +int ctx;int cpu; +struct runtime_stat *stat;struct stats stats; };tools/perf/util/stat-shadow.c static int saved_value_cmp(struct rb_node *rb_node, const void *entry) · line 71
Quoted 10 lines
tools/perf/util/stat-shadow.c +7
-0@@ -58,6 +62,23 @@ static int saved_value_cmp(struct rb_node *rb_node, const void *entry)if (a->cpu != b->cpu)return a->cpu - b->cpu; + +if (a->type != b->type) +return a->type - b->type; + +if (a->ctx != b->ctx) +return a->ctx - b->ctx; +could you please comment in here on the cases where evsel is defined and when not
Quoted 2 lines
jirka
Thanks for reminding.
I will add comments to describe the cases where and when the evsel is set or not.
Thanks
Jin Yao
Quoted 13 lines
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+if (a->evsel ==NULL && b->evsel ==NULL ) { +if (a->stat == b->stat) +return 0 ; + +if ((char *)a->stat < (char *)b->stat) +return -1 ; + +return 1 ; + } +SNIP
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 13 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 9 lines
static int
evsel_context(struct perf_evsel *evsel)tools/perf/util/stat.h +0
-0@@ -126,6 +126,8 @@ typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, const char *fmt, double val);typedef void (*new_line_t )(void *ctx);
Quoted 9 lines
tools/perf/util/stat.h typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, · line 130
Quoted 2 lines
tools/perf/util/stat.h +2
-0+void perf_stat__init_runtime_stat (struct runtime_stat *stat); +void perf_stat__free_runtime_stat (struct runtime_stat *stat);maybe that could be:
runtime_stat__init(struct runtime_stat *stat); runtime_stat__free(struct runtime_stat *stat);jirka
Sure, I will update according to your suggestion.
Thanks
Jin Yao
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jiri OlsaQuoted 75 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 19 lines
tools/perf/util/stat-shadow.c +5
-1@@ -110,19 +110,32 @@ static void saved_value_delete(struct rblist *rblist __maybe_unused,static struct saved_value *saved_value_lookup (struct perf_evsel *evsel,int cpu, -bool create) +bool create, +enum stat_type type, +int ctx, +struct runtime_stat *stat) { +struct rblist *rblist;struct rb_node *nd;struct saved_value dm = { .cpu = cpu, .evsel = evsel,tools/perf/util/stat-shadow.c static void saved_value_delete(struct rblist *rblist __maybe_unused, · line 131
Quoted 10 lines
tools/perf/util/stat-shadow.c +8
-1+ .type = type, + .ctx = ctx, + .stat = stat, }; - nd =rblist__find (&runtime_saved_values, &dm); + +if (stat) + rblist = &stat->value_list; +else + rblist = &rt_stat.value_list;please pass the correct 'struct
runtime_stat*stat',I don't see a reason noot to pass
&rt_statdirectly below:Quoted 10 lines
tools/perf/util/stat.c +0
-2@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD )tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 289
Quoted 10 lines
tools/perf/util/stat.c +9
-1-perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]); +else +perf_stat__update_shadow_stats (evsel, + count->val,0 ,NULL );here
tools/perf/util/stat.c int perf_stat_process_counter(struct perf_stat_config *config, · line 372
Quoted 10 lines
tools/perf/util/stat.c +2
-1+ }break ;case AGGR_GLOBAL : aggr->val += count->val;@@ -362,7 +369,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,/* * Save the full runtime - to allow normalization during printout: */ -perf_stat__update_shadow_stats (counter, *count,0 ); +perf_stat__update_shadow_stats (counter, *count,0 ,NULL );and here
Quoted 3 lines
thanks,
jirka
Fine, I will pass &rt_stat to perf_stat__update_shadow_stats to replace the NULL.
The change maybe needs to let the rt_stat be a global variable.
Thanks
Jin Yao
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jiri OlsaQuoted 27 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 8 lines
if (num == 0)
tools/perf/util/stat.c +0
-0@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 286
Quoted 10 lines
tools/perf/util/stat.c +6
-3if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD ) -perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]);please add this part together with
config->statsallocation/usage and keep this change only about adding the structruntime_stat*stat into the code path with no functional change
Quoted 3 lines
thanks,
jirka
The interface of perf_stat__update_shadow_stats() is changed (added with a new parameter 'struct runtime_stat *stat').
If I move above part to another patch (e.g. move to v1-0006-perf-stat-Allocate-shadow-stats-buffer-for-thread.patch), the compilation would be failed if only applying with this patch. It's not good for git bisect.
Thanks
Jin Yao
Re: [PATCH v1 2/9] perf util: Define a structure for runtime shadow metrics stats
In reply to Jiri OlsaQuoted 23 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:37PM +0800, Jin Yao wrote:
SNIP
Quoted 6 lines
tools/perf/util/stat.h +6
-0+STAT_SMI_NUM , +STAT_APERF , +STAT_MAX +}; + +struct runtime_stat {tools/perf/util/stat.h enum aggr_mode { · line 95
Quoted 10 lines
tools/perf/util/stat.h +5
-0+struct rblist value_list; +}; +struct perf_stat_config {enum aggr_mode aggr_mode;bool scale;FILE *output;unsigned int interval; +struct runtime_stat *stats; +int stat_num;s/stat_num/stats_num/ or s/stats/stat/
Quoted 3 lines
thanks,
jirka
Fine, I will update according to your suggestion.
Thanks
Jin Yao
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jiri OlsaQuoted 4 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
SNIP
Quoted 14 lines
tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv) · line 2799
Quoted 12 lines
tools/perf/builtin-stat.c +6
-6-if ((stat_config.aggr_mode ==AGGR_THREAD ) && !target__has_task (&target)) { -fprintf (stderr,"The --per-thread option is only available " -"when monitoring via -p -t options.\n" ); -parse_options_usage (NULL , stat_options,"p" ,1 ); -parse_options_usage (NULL , stat_options,"t" ,1 ); - goto out; +if ((stat_config.aggr_mode ==AGGR_THREAD ) && + !target__has_task (&target)) { +if (!target.system_wide || target.cpu_list) { +fprintf (stderr,"The --per-thread option is only " +"available when monitoring via -p -t " +"options.\n" );the message should be updated with '-a' option, that you just added,
OK. Could I update the message like this?
"The --per-thread option is only "
"available when monitoring via -p -t -a" "options or only --per-thread without any other option"
Quoted 2 lines
also why dont we support target.cpu_list, it should work no?
Currently it doesn't support cpu_list.
I just think this patch series is too big and I wish to add supporting for cpu_list, cgroup or others in follow up patches.
Is that OK?
Thanks
Jin Yao
Quoted 2 lines
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jiri OlsaQuoted 12 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
SNIP
Quoted 8 lines
tools/perf/util/target.h +0
-0@@ -64,6 +64,11 @@ static inline bool target__none(struct target *target)return !target__has_task (target) && !target__has_cpu (target); }
Quoted 7 lines
tools/perf/util/target.h static inline bool target__none(struct target *target) · line 70
Quoted 4 lines
tools/perf/util/target.h +4
-0+static inline bool target__has_per_thread (struct target *target) +{ +return target->system_wide && target->per_thread; +}this is confusing..
has_per_threaddepends onsystem_wide?
This patch series only supports to get per-thread data for the whole system.
So I add checking of system_wide here.
Quoted 4 lines
Quoted 4 lines
tools/perf/util/target.h +1
-0+static inline bool target__uses_dummy_map (struct target *target) {bool use_dummy = false;
Quoted 9 lines
tools/perf/util/target.h static inline bool target__uses_dummy_map(struct target *target) · line 82
Quoted 6 lines
tools/perf/util/target.h +2
-0@@ -73,6 +78,8 @@ static inline bool target__uses_dummy_map(struct target *target)else if (target__has_task (target) || (!target__has_cpu (target) && !target->uses_mmap)) use_dummy = true; +else if (target__has_per_thread (target)) + use_dummy = true;why do we need
dummy_mapfor this? please comment
We need dummy_map here. That's similar to the processing of '--per-thread -p -t'.
We need a dummy map to help us to aggregate counts per-thread.
Thanks
Jin Yao
Quoted 3 lines
thanks,
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jiri OlsaQuoted 38 lines · Jiri Olsa
Quoted 22 lines · Jin Yao
Currently, if we execute 'perf stat --per-thread' without specifying pid/tid, perf will return error.
root@skl:/tmp# perf stat --per-thread The --per-thread option is only available when monitoring via -p -t options. -p, --pid <pid> stat events on existing process id -t, --tid <tid> stat events on existing thread idThis patch removes this limitation. If no pid/tid specified, it returns all threads (get threads from /proc).
Signed-off-by Jin Yao <[email protected]>--- tools/perf/builtin-stat.c | 23 +++++++++++++++-------- tools/perf/util/target.h | 7 +++++++ 2 files changed, 22 insertions(+), 8 deletions(-)tools/perf/builtin-stat.c +0
-0tools/perf/builtin-stat.c static int create_perf_stat_counter(struct perf_evsel *evsel) · line 280
Quoted 5 lines
tools/perf/builtin-stat.c +1
-1@@ -277,7 +277,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->enable_on_exec =1 ; } -if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target))please add comment on why this is needed..
Quoted 7 lines
tools/perf/builtin-stat.c +0
-0return perf_evsel__open_per_cpu (evsel,perf_evsel__cpus (evsel));return perf_evsel__open_per_thread (evsel, evsel_list->threads);@@ -340,7 +340,7 @@ static int read_counter(struct perf_evsel *counter)int nthreads =thread_map__nr (evsel_list->threads);int ncpus, cpu, thread;
Quoted 5 lines
tools/perf/builtin-stat.c static int read_counter(struct perf_evsel *counter) · line 343
Quoted 2 lines
tools/perf/builtin-stat.c +1
-1-if (target__has_cpu (&target)) +if (target__has_cpu (&target) && !target__has_per_thread (&target))same here
That's because this patch series doesn't support cpu_list yet. So if it's a cpu_list case, then skip.
I plan to add cpu_list supporting as follow-up patch to avoid adding too much in this patch series.
Thanks
Jin Yao
Quoted 3 lines
thanks,
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin YaoQuoted 4 lines · Jin Yao
tools/perf/util/stat-shadow.c +0
-0@@ -76,6 +97,17 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused,return &nd->rb_node; }
tools/perf/util/stat-shadow.c static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused, · line 109
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+static void saved_value_delete (struct rblist *rblist__maybe_unused , +struct rb_node *rb_node) +{ +struct saved_value *v =container_of (rb_node, + struct saved_value, + rb_node); + +if (v) +free (v); +}
Do we really need if(v) ?
Thanks,
Ravi
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
Quoted 20 lines · Ravi Bangoria
Quoted 5 lines · Jin Yao
tools/perf/util/stat-shadow.c +0
-0@@ -76,6 +97,17 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused, return &nd->rb_node; }tools/perf/util/stat-shadow.c static struct rb_node *saved_value_new(struct · line 110
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+static void saved_value_delete (struct rblist *rblist__maybe_unused , + struct rb_node *rb_node) +{ + struct saved_value *v = container_of(rb_node, + struct saved_value, + rb_node); + + if (v) + free(v); +}Do we really need if(v) ?
Quoted 3 lines
Thanks,
Ravi
Hi Ravi,
Looks it doesn't need if(v).
I put if(v) here is from my coding habits (checking pointer before free).
It's OK for me if you think the code should be removed.
Thanks
Jin Yao
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin, YaoQuoted 26 lines · Yao
Quoted 23 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:38PM +0800, Jin Yao wrote:
SNIP
Quoted 6 lines
tools/perf/util/stat-shadow.c +6
-0+static void init_saved_rblist (struct rblist *rblist) +{ +rblist__init (rblist); + rblist->node_cmp = saved_value_cmp; + rblist->node_new = saved_value_new; + rblist->node_delete = saved_value_delete;tools/perf/util/stat-shadow.c static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, · line 147
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+} + +static void free_saved_rblist (struct rblist *rblist) +{ +rblist__reset (rblist); +} + +void perf_stat__init_runtime_stat (struct runtime_stat *stat) +{ +memset (stat,0 ,sizeof (struct runtime_stat ));what's this memset for? that struct has only
rb_list
Quoted 7 lines
Quoted 2 lines
jirka
Currently this struct has only rblist. I use memset to zero this struct is for future potential new added fields to this struct.
If it's not good, I will remove this memset.
ok, np
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jin, YaoQuoted 27 lines · Yao
Quoted 20 lines · Ravi Bangoria
Quoted 5 lines · Jin Yao
tools/perf/util/stat-shadow.c +0
-0@@ -76,6 +97,17 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused, return &nd->rb_node; }tools/perf/util/stat-shadow.c static struct rb_node *saved_value_new(struct · line 110
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+static void saved_value_delete (struct rblist *rblist__maybe_unused , + struct rb_node *rb_node) +{ + struct saved_value *v = container_of(rb_node, + struct saved_value, + rb_node); + + if (v) + free(v); +}Do we really need if(v) ?
Quoted 3 lines
Thanks,
Ravi
Quoted 7 lines
Hi Ravi,
Looks it doesn't need if(v).
I put if(v) here is from my coding habits (checking pointer before free).
It's OK for me if you think the code should be removed.
you could add BUG_ON(!rb_node);
jirka
Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation
In reply to Jin, YaoQuoted 31 lines · Yao
Quoted 4 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
SNIP
Quoted 14 lines
tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv) · line 2799
Quoted 12 lines
tools/perf/builtin-stat.c +6
-6-if ((stat_config.aggr_mode ==AGGR_THREAD ) && !target__has_task (&target)) { -fprintf (stderr,"The --per-thread option is only available " -"when monitoring via -p -t options.\n" ); -parse_options_usage (NULL , stat_options,"p" ,1 ); -parse_options_usage (NULL , stat_options,"t" ,1 ); - goto out; +if ((stat_config.aggr_mode ==AGGR_THREAD ) && + !target__has_task (&target)) { +if (!target.system_wide || target.cpu_list) { +fprintf (stderr,"The --per-thread option is only " +"available when monitoring via -p -t " +"options.\n" );the message should be updated with '-a' option, that you just added,
OK. Could I update the message like this?
"The --per-thread option is only "
"available when monitoring via -p -t -a" "options or only --per-thread without any other option"Quoted 2 lines
also why dont we support target.cpu_list, it should work no?
Quoted 6 lines
Currently it doesn't support
cpu_list.I just think this patch series is too big and I wish to add supporting for
cpu_list, cgroup or others in follow up patches.Is that OK?
ok, thanks
jirka
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jin, YaoQuoted 34 lines · Yao
Quoted 27 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 8 lines
if (num == 0)
tools/perf/util/stat.c +0
-0@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 286
Quoted 10 lines
tools/perf/util/stat.c +6
-3if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD ) -perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]);please add this part together with
config->statsallocation/usage and keep this change only about adding the structruntime_stat*stat into the code path with no functional changeQuoted 3 lines
thanks,
jirka
Quoted 7 lines
The interface of
perf_stat__update_shadow_stats()is changed (added with a new parameter 'structruntime_stat*stat').If I move above part to another patch (e.g. move to v1-0006-perf-stat-Allocate-shadow-stats-buffer-for-thread.patch), the compilation would be failed if only applying with this patch. It's not good for git bisect.
but you could make the patch just to add the 'struct runtime_stat *stat' as an argument through the code path.. as a base for the stats, no?
jirka
Re: [PATCH v1 3/9] perf util: Reconstruct rblist for supporting per-thread shadow stats
In reply to Jiri OlsaQuoted 32 lines · Jiri Olsa
Quoted 31 lines · Yao
Quoted 20 lines · Ravi Bangoria
Quoted 5 lines · Jin Yao
tools/perf/util/stat-shadow.c +0
-0@@ -76,6 +97,17 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused, return &nd->rb_node; }tools/perf/util/stat-shadow.c static struct rb_node *saved_value_new(struct · line 110
Quoted 10 lines
tools/perf/util/stat-shadow.c +10
-0+static void saved_value_delete (struct rblist *rblist__maybe_unused , + struct rb_node *rb_node) +{ + struct saved_value *v = container_of(rb_node, + struct saved_value, + rb_node); + + if (v) + free(v); +}Do we really need if(v) ?
Quoted 3 lines
Thanks,
RaviHi Ravi,
Looks it doesn't need if(v).
Quoted 8 lines
Quoted 3 lines
I put if(v) here is from my coding habits (checking pointer before free).
It's OK for me if you think the code should be removed.
you could add
BUG_ON(!rb_node);jirka
Good idea! I will add BUG_ON checking there.
Thanks
Jin Yao
Re: [PATCH v1 4/9] perf util: Update and print per-thread shadow stats
In reply to Jiri OlsaQuoted 43 lines · Jiri Olsa
Quoted 34 lines · Yao
Quoted 27 lines · Jiri Olsa
On Mon, Nov 20, 2017 at 10:43:39PM +0800, Jin Yao wrote:
SNIP
Quoted 8 lines
if (num == 0)tools/perf/util/stat.c +0
-0@@ -278,9 +278,16 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselperf_evsel__compute_deltas (evsel, cpu, thread, count);perf_counts_values__scale (count, config->scale,NULL );tools/perf/util/stat.c process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · line 286
Quoted 10 lines
tools/perf/util/stat.c +6
-3if (config->aggr_mode ==AGGR_NONE ) -perf_stat__update_shadow_stats (evsel, count->val, cpu); -if (config->aggr_mode ==AGGR_THREAD ) -perf_stat__update_shadow_stats (evsel, count->val,0 ); +perf_stat__update_shadow_stats (evsel, count->val, cpu, +NULL ); +if (config->aggr_mode ==AGGR_THREAD ) { +if (config->stats) +perf_stat__update_shadow_stats (evsel, + count->val,0 , &config->stats[thread]);please add this part together with
config->statsallocation/usage and keep this change only about adding the structruntime_stat*stat into the code path with no functional changeQuoted 3 lines
thanks,
jirkaQuoted 7 lines
The interface of
perf_stat__update_shadow_stats()is changed (added with a new parameter 'structruntime_stat*stat').If I move above part to another patch (e.g. move to v1-0006-perf-stat-Allocate-shadow-stats-buffer-for-thread.patch), the compilation would be failed if only applying with this patch. It's not good for git bisect.
Quoted 5 lines
but you could make the patch just to add the 'struct
runtime_stat*stat' as an argument through the code path.. as a base for the stats, no?jirka
Yeah, that might be OK. Let me have a try.
Thanks
Jin Yao