feat:增加火焰图专用测试代码

This commit is contained in:
yanfeizhang
2023-05-12 08:37:40 +08:00
parent 815bcd0870
commit e5901148a3
3 changed files with 47 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
- [likely 和 unlikely 汇编结果对比](tests/cpu/test01)
- [物理机 cpu 系统利用率的计算过程](tests/cpu/test06)
- [容器 cpu 系统利用率的计算过程](tests/cpu/test07)
- [直接使用perf_event_open获取硬件计数](tests/cpu/test08)
- [直接使用perf_event_open获取硬件计数](tests/cpu/test08)
- [火焰图专用测试代码](tests/cpu/test09)

View File

@@ -6,9 +6,9 @@
#include <linux/perf_event.h>
// 封装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()

43
tests/cpu/test09/main.c Normal file
View File

@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
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;
}