|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| samples/ | H | - | - | 691,912 | 691,875 |
| README.md | H A D | 26-Sep-2022 | 2 KiB | 46 | 34 |
| example1.png | HD | 04-Sep-2022 | 94.5 KiB | | |
| example2.png | HD | 26-Sep-2022 | 217.2 KiB | | |
| profiler-kprobe.cpp | H A D | 18-Sep-2022 | 15.5 KiB | 435 | 383 |
| profiler.cpp | H A D | 10-Oct-2022 | 17 KiB | 476 | 421 |
| report.chromium.html | H A D | 26-Sep-2022 | 7.7 MiB | 333,538 | 333,537 |
| report.chromium.kernel.html | H A D | 26-Sep-2022 | 258.3 KiB | 11,524 | 11,523 |
| report.css | H A D | 04-Sep-2022 | 2.2 KiB | 126 | 104 |
| report.firefox.html | H A D | 26-Sep-2022 | 537.4 KiB | 22,096 | 22,095 |
| report.firefox.kernel.html | H A D | 26-Sep-2022 | 241.4 KiB | 10,780 | 10,779 |
| report.js | H A D | 04-Sep-2022 | 802 | 38 | 31 |
README.md
1# A simple profiler
2Fit for lightwight usage, minimum dependency
3
4## Build
5```
6g++ -o profiler profiler.cpp
7```
8The code needs c++11 features, if an old g++ compiler is used, `-std=c++11` is needed.
9You can also use static c/c++ libs via `-static-libstdc++ -static-libgcc`, or even further to build a static executable `-static`
10
11
12## How it works
13Profiler open perf-event and collect sampled (pid,callchain) pair, whether userspace call-chain is collected depends on kernel version, a new kernel which can unwind user space stack is recommended, (I only tested the profiler on limited number of kernel version, and they all can unwind user stack, the lowest version of kernel I have tested is 3.10.0 from centos/redhat distributions.)
14For each (pid, callchain) pair, if this pid has not been symbol-collected, profiler would parse elf information based on `/proc/[pid]/maps` and `/proc/[pid]/map_files/*`; (If the program has its symbol stripped, e.g. via `ld -s`, user space call chain will be dropped.) Symbols are stored in an ordered structure, C++ map, after symbols collected, each callchain address is binary searched for its function name, and then full chain is inserted into a tree.
15
16
17## Run
18The profiler would open perf event with the cgroup which controls the specified pid
19```
20./profiler <pid>
21```
22To profile kernel call chains, run with a nagative pid value
23```
24./profiler -<pid>
25```
26
27To create a perf-event cgroup
28
29cgroup v1
30```
31mkdir /sys/fs/cgroup/perf_event/<somename>
32echo $$ > /sys/fs/cgroup/perf_event/<somename>/cgroup.procs
33# run the target progrom
34# run profiler with any pid within the cgroup
35```
36For cgroup v2, just use /sys/fs/cgroup/<somename>
37
38
39## Example
40When profiler terminated, a report is generated, following is an example showing the performance impact from seccomp when running a high-IO program within a docker container.
41![example](./example1.png "report")
42
43Profiling kernel only, following is what firefox's profiling snap compared with chromium's
44![example](./example2.png "report")
45
46