From e5901148a3d876872b98dd255f19bd638ff33a89 Mon Sep 17 00:00:00 2001 From: yanfeizhang <54074852@qq.com> Date: Fri, 12 May 2023 08:37:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E7=81=AB=E7=84=B0?= =?UTF-8?q?=E5=9B=BE=E4=B8=93=E7=94=A8=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/cpu/index.md | 3 ++- tests/cpu/test08/main.c | 4 ++-- tests/cpu/test09/main.c | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/cpu/test09/main.c 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; +}