Add record-events-per-thread.md

This commit is contained in:
Nan Xiao 2019-11-21 17:20:42 +08:00
parent 8fd80863c1
commit 5291012ef9
2 changed files with 59 additions and 1 deletions

View file

@ -5,6 +5,7 @@
* [How to specify monitoring events](posts/how-to-specify-monitoring-events.md)
* [What is skid](posts/what-is-skid.md)
* [Count events](posts/count-events.md)
* [Record event counts per thread](posts/record-event-counts-per-thread.md)
* [Profile memory access](posts/profile-memory-access.md)
* [Check cache false sharing](posts/check-cache-false-sharing.md)
* [Profile system in real time](posts/profile-system-in-real-time.md)
@ -12,4 +13,4 @@
* [Measure scheduler latency](posts/measure-scheduler-latency.md)
* [Use ftrace](posts/use-ftrace.md)
* [Show performance difference](posts/show-performance-difference.md)
* [The end](posts/the-end.md)
* [The end](posts/the-end.md)

View file

@ -0,0 +1,57 @@
# Record event counts per thread
`perf record` can be used to record event counts for every thread when using `-s` option. Check following multi-thread program:
```
$ cat sum.c
#include <omp.h>
#define N 100000000
#define THRAED_NUM 8
int values[N];
int main(void)
{
int sum[THRAED_NUM];
#pragma omp parallel for
for (int i = 0; i < THRAED_NUM; i++)
{
int local_sum;
for (int j = 0; j < N; j++)
{
local_sum += values[j] >> i;
}
sum[i] = local_sum;
}
return 0;
}
```
Build and use `perf record` to note down event counts for every thread:
```
# gcc -fopenmp -g sum.c -o sum
# perf record -s ./sum
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.404 MB perf.data (8757 samples) ]
```
Use `perf report` to analyze it (`-T` option means displaying per-thread event counts):
```
# perf report -T
......
# PID TID cycles:uppp
9960 9963 751824252
9960 9961 750625307
9960 9965 749742594
9960 9967 749228142
9960 9968 0
9960 9970 9857914
9960 9974 9150516
9960 9977 8928628
......
```