mirror of
https://github.com/yanfeizhang/coder-kung-fu.git
synced 2026-05-05 12:53:40 +08:00
feat:增加火焰图专用测试代码
This commit is contained in:
@@ -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)
|
||||
@@ -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
43
tests/cpu/test09/main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user