diff --git a/tests/cpu/index.md b/tests/cpu/index.md index d7a1699..5f8d988 100644 --- a/tests/cpu/index.md +++ b/tests/cpu/index.md @@ -1,4 +1,5 @@ - [likely 和 unlikely 汇编结果对比](tests/cpu/test01) - [物理机 cpu 系统利用率的计算过程](tests/cpu/test06) - [容器 cpu 系统利用率的计算过程](tests/cpu/test07) -- [直接使用perf_event_open获取硬件计数](tests/cpu/test08) \ No newline at end of file +- [直接使用perf_event_open获取硬件计数](tests/cpu/test08) +- [火焰图专用测试代码](tests/cpu/test09) \ No newline at end of file diff --git a/tests/cpu/test08/main.c b/tests/cpu/test08/main.c index 8e57e94..b604831 100644 --- a/tests/cpu/test08/main.c +++ b/tests/cpu/test08/main.c @@ -6,9 +6,9 @@ #include // 封装perf_event_open系统调用 -int perf_event_open(struct perf_event_attr *attr,pid_t pid,int ,int group_fd,unsigned long flags) +int perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags) { - return syscall(__NR_perf_event_open,attr,pid,cpu,group_fd,flags); + return syscall(__NR_perf_event_open, attr,pid, cpu, group_fd, flags); } int main() diff --git a/tests/cpu/test09/main.c b/tests/cpu/test09/main.c new file mode 100644 index 0000000..23b9c57 --- /dev/null +++ b/tests/cpu/test09/main.c @@ -0,0 +1,43 @@ +#include +#include +#include + +void caculate(){ + for (i = 0; i < 10000000; i++) { + } +} + +void funcE(){ + caculate(); +} + +void funcD(){ + funcE(); +} + +void funcA(){ + funcD(); +} + +void funcB(){ + caculate(); +} + +void funcC(){ + caculate(); +} + +int main() { + int i; + for (i = 0; i < 100; i++) { + if (i < 10) { + funcA(); + } else if (i < 16) { + funcB(); + } else { + funcC(); + } + } + + return 0; +}