我使用 linux perf 来分析我的程序,但我无法理解结果。
10.5% 2 乐趣 .....................
|
|- 80% - ABC
| call_ABC
-- 20% - 防御
调用_DEF
上面的例子意味着 'fun' 有两个样本并且贡献了 10.5% 的开销,
其中80%来自ABC,20%来自DEF。我对吗?
现在我们只有两个样本,那么'perf'如何计算ABC和DEF的分数?
为什么不是 50%?剂量'perf'使用附加信息?
我必须分析我的多线程 C++ 应用程序并找到它的瓶颈。问题是:我需要查看挂钟配置文件。我用过oprofile和perf。没有人可以向我提供这样的信息。
我使用过perf record -g -e sched:sched_stat_sleep <cmd>但因perf recordSIGFPE 异常而失败。这让我很生气。
Valgrind不适合我,因为我使用fanotify_mark了此工具中未实现的 syscall。
我不确定谷歌是否perftools可以进行挂钟分析 - 我在他们的文档中没有看到任何信息。
任何人都可以建议吗?谢谢你。
我正在尝试使用 linux perf 工具在特定功能期间监视性能统计信息。
我正在按照https://perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes给出的说明进行操作
我试图获得一个简单的 C 程序的指令数。(如下所示)
1) 我的简单 C 代码
#include<stdio.h>
int sum=0;
int i=0;
void func(void)
{
for(i=0;i<100;i++)
{
sum=sum+i;
}
}
int main(void)
{
func();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
2) 编译和添加探针
root@sunimal-laptop:/home/sunimal/temp# gcc -o ex source.c
root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex entry=func
Added new event:
probe_ex:entry (on 0x4ed)
You can now use it in all perf tools, such as:
perf record -e probe_ex:entry -aR sleep 1
root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex exit=func%return
Added new event: …Run Code Online (Sandbox Code Playgroud) 我想测量我的代码的缓存未命中率。我们可以使用 perf list 来显示支持的事件。我的台式机有一个 Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz 处理器,性能列表包含缓存引用和缓存未命中,如下所示:
cpu-cycles OR cycles [Hardware event]
stalled-cycles-frontend OR idle-cycles-frontend [Hardware event]
stalled-cycles-backend OR idle-cycles-backend [Hardware event]
instructions [Hardware event]
cache-references [Hardware event]
cache-misses [Hardware event]
Run Code Online (Sandbox Code Playgroud)
我认为缓存未命中根据英特尔架构软件开发人员手册映射到硬件事件 LLC 未命中(我通过比较perf stat -e r412e和perf stat -e cache-misses 来确认这一点,它们给出了几乎相同的结果)。但是缓存引用是如何计算的呢?我没有找到使用现有硬件事件获取总缓存引用的事件或方法。所以我想知道这个缓存引用在我的电脑上是否准确?
我使用“ perf stat”命令对某些事件进行统计:
[root@root test]# perf stat -a -e "r81d0","r82d0" -v ./a
r81d0: 71800964 1269047979 1269006431
r82d0: 26655201 1284214869 1284214869
Performance counter stats for './a':
71,800,964 r81d0 [100.00%]
26,655,201 r82d0
0.036892349 seconds time elapsed
Run Code Online (Sandbox Code Playgroud)
(1) 我知道71800964是“ r81d0”的计数,但是1269047979and是什么意思1269006431?
(2) “ [100.00%]”是什么意思?
我曾尝试“ perf stat --help”,但无法获得这些值的解释。
大家都知道,perf是为了得到一个程序的CPU性能计数器的工具,如cache-miss,cache-reference,instruction executed等。
问题:
如何在c或c++.
例如,我的程序首先进行一些初始化,然后进行工作,然后完成,我只想获得工作的性能计数器,例如 function do_something_1。
int main(int argc, char ** argv) {
do_initialize();
for (int i = 0;i < 100 ;i ++) {
/* begin profile code */
do_something_1();
/* end profile code */
do_something_2();
}
do_finalize();
}
Run Code Online (Sandbox Code Playgroud) 我运行以下调用 perf_event_open 系统调用的程序:Linux sama-desktop 3.18.0-20-rpi2 #21-Ubuntu SMP PREEMPT Sun Apr 5 01:56:02 UTC 2015 armv7l armv7l armv7l GNU/Linux
该程序:
#define _GNU_SOURCE 1
#include <asm/unistd.h>
#include <fcntl.h>
#include <linux/perf_event.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long perf_event_open(struct perf_event_attr* event_attr, pid_t pid, int cpu, int group_fd, unsigned long flags)
{
return syscall(__NR_perf_event_open, event_attr, pid, cpu, group_fd, flags);
}
static void perf_event_handler(int signum, siginfo_t* info, void* ucontext) {
if(info->si_code != POLL_HUP) {
// Only POLL_HUP should happen.
exit(EXIT_FAILURE);
}
ioctl(info->si_fd, PERF_EVENT_IOC_REFRESH, …Run Code Online (Sandbox Code Playgroud) 我知道“perf”工具需要安装对应于特定 linux 内核版本。而且我知道所有 docker 映像都使用相同的 linux 内核版本运行,无论 linux 发行版是什么。
我在 docker 中使用 ubuntu 16.04 并且已经安装了 linux-tools-common,启动性能告诉我我仍然缺少一些软件包:'
# perf
/usr/bin/perf: line 32: lsb_release: command not found
WARNING: perf not found for kernel 4.9.12
You may need to install the following packages for this specific kernel:
linux-tools-4.9.12-moby
linux-cloud-tools-4.9.12-moby
You may also want to install one of the following packages to keep up to date:
linux-tools-moby
linux-cloud-tools-moby
Run Code Online (Sandbox Code Playgroud)
然后我尝试安装我错过的东西:
root@xxxxxx:/# apt-get install linux-tools-4.9.12-moby linux-cloud-tools-4.9.12-moby
Reading package lists... Done
Building dependency tree
Reading state information... …Run Code Online (Sandbox Code Playgroud) 我使用以下开关编译了我的 C++ 代码:
g++ -O0 -g -rdynamic -DNDEBUG -DARMA_NO_DEBUG -std=c++11 -pthread
Run Code Online (Sandbox Code Playgroud)
链接器开关是:
-lboost_system -lboost_thread -lboost_chrono -larmadillo -pthread
Run Code Online (Sandbox Code Playgroud)
但是我在我的应用程序中没有使用线程。我也避免使用任何delay函数。
然后我运行代码并使用perf工具对其进行测试。
sudo perf record ./bin/my_application
sudo perf report -f
Run Code Online (Sandbox Code Playgroud)
结果对我来说很奇怪:
Overhead Command Shared Object Symbol
50.92% myApplication [kernel.kallsyms] [k] native_sched_clock
24.73% myApplication [kernel.kallsyms] [k] pick_next_entity
17.46% myApplication [kernel.kallsyms] [k] prepend_name
2.57% myApplication myApplication [.] arma::arrayops::copy_small<double>
1.11% myApplication myApplication [.] arma::Mat<double>::Mat
1.11% myApplication myApplication [.] myClass::myMethod
1.11% myApplication libblas.so.3 [.] dgemv_
0.97% myApplication myApplication [.] arma::Mat<double>::init_cold
Run Code Online (Sandbox Code Playgroud)
为什么 kernel.kallsyms函数主宰了执行时间? …
perf ×10
linux ×6
c++ ×2
linux-kernel ×2
performance ×2
profiling ×2
apt-get ×1
arm ×1
benchmarking ×1
c ×1
caching ×1
docker ×1
installation ×1
profile ×1
rate ×1
sample ×1
system-calls ×1