我在某处读到可以将perf.data(从Linux perf record分析工具输出)转换为kcachegrind可以解析/绘制的格式,但是我没有找到能够执行此转换的应用程序,并且kcachegrind也没有打开perf.data.
这是可能的:使用kcachegrind查看perf输出?我可以使用哪种工具?
编辑:我用我的基准测试的详细信息更新了我的问题
出于基准测试目的,我试图在运行在两个Intel Xeon 56xx("Westmere")处理器之上的Linux 3.13系统中设置1GB页面.为此我修改了我的启动参数以添加对1GB页面的支持(10页).这些引导参数仅包含1GB页面而不包含2MB页面.跑步hugeadm --pool-list 导致:
Size Minimum Current Maximum Default
1073741824 10 10 10 *
Run Code Online (Sandbox Code Playgroud)
我的内核启动参数被考虑在内.在我的基准测试中,我正在分配1GiB的内存,我想用1GiB大页面支持:
#define PROTECTION (PROT_READ | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB)
uint64_t size = 1UL*1024*1024*1024;
memory = mmap(0, size, PROTECTION, FLAGS, 0, 0);
if (memory == MAP_FAILED) {
perror("mmap");
exit(1);
}
sleep(200)
Run Code Online (Sandbox Code Playgroud)
看着/proc/meminfo替补席正在睡觉的时候(sleep上面打电话),我们可以看到已经分配了一个巨大的页面:
AnonHugePages: 4096 kB
HugePages_Total: 10
HugePages_Free: 9
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 1048576 kB
Run Code Online (Sandbox Code Playgroud)
注意:我/sys在运行工作台之前禁用了THP(通过文件系统),所以我猜测AnonHugePages报告的字段/proc/meminfo代表THP在停止之前分配的大页面. …
我在x86_64系统上遇到了从Linux内核3.11到3.12的奇怪性能回归.在Fedora 20,3.12上运行Mark Stock's Radiance基准测试的速度明显变慢.没有其他任何改变 - 相同的二进制,相同的glibc - 我只是启动一个不同的内核版本,性能改变.定时程序rpict是100%CPU绑定的用户级代码.
在我将此报告为错误之前,我想找到导致此行为的原因.我对Linux内核了解不多,从3.11到3.12的更改日志并没有给我任何线索.
我在两个系统上观察到了这一点,Intel Haswell(i7-4771)和AMD Richland(A8-6600K).在Haswell系统上,用户时间从895秒变为3.11到962变为3.12.在里奇兰,从1764年到1844年.这些时间可以在几秒钟内重复.
我用perf进行了一些分析,发现IPC与减速的比例下降了.在Haswell系统中,这似乎是由更多错过的分支引起的,但为什么预测率会下降?Radiance确实使用随机数生成器 - 可能"更好"的随机性导致错过的分支?但除了OMAP4支持外,RNG在3.12中似乎没有变化.
在AMD系统上,perf只指向更多空闲的后端周期,但原因尚不清楚.
Haswell系统:
3.11.10 895s user, 3.74% branch-misses, 1.65 insns per cycle
3.12.6 962s user, 4.22% branch-misses, 1.52 insns per cycle
Run Code Online (Sandbox Code Playgroud)
里奇兰系统:
3.11.10 1764s user, 8.23% branch-misses, 0.75 insns per cycle
3.12.6 1844s user, 8.26% branch-misses, 0.72 insns per cycle
Run Code Online (Sandbox Code Playgroud)
我还查看了两个内核的dmesg输出中的差异,但没有看到任何可能导致CPU绑定程序如此减速的事情.
我尝试将cpufreq 调控器从默认的ondemand切换到peformance但是没有任何效果.
可执行文件是使用gcc 4.7.3编译的,但不使用AVX指令.libm似乎仍然使用一些AVX(例如__ieee754_pow_fma4),但这些功能仅占总执行时间的0.3%.
附加信息:
我正在寻找一种方法来找出我的程序花费时间的地方.我阅读了perf教程并试图描述那里描述的睡眠时间.我写了最简单的程序来分析:
#include <unistd.h>
int main() {
sleep(10);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我用perf执行它:
$ sudo perf record -e sched:sched_stat_sleep -e sched:sched_switch -e sched:sched_process_exit -g -o ~/perf.data.raw ./a.out
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB /home/pablo/perf.data.raw (~578 samples) ]
$ sudo perf inject -v -s -i ~/perf.data.raw -o ~/perf.data
build id event received for [kernel.kallsyms]: d62870685909222126e7070d2bafdf029f7ed3b6
failed to write feature 2
$ sudo perf report --stdio --show-total-period -i ~/perf.data …Run Code Online (Sandbox Code Playgroud) 如何为perf调用图启用C++ demangling?当我进入注释模式时,似乎是解码符号,而不是在主调用图中.
示例代码(使用Google Benchmark):
#include <benchmark/benchmark.h>
#include <vector>
static __attribute__ ((noinline)) int my_really_big_function()
{
for(size_t i = 0; i < 1000; ++i)
{
benchmark::DoNotOptimize(i % 5);
}
return 0;
}
static __attribute__ ((noinline)) void caller1()
{
for(size_t i = 0; i < 1000; ++i)
{
benchmark::DoNotOptimize(my_really_big_function());
benchmark::DoNotOptimize(i % 5);
}
}
static __attribute__ ((noinline)) void myfun(benchmark::State& state)
{
while(state.KeepRunning())
{
caller1();
}
}
BENCHMARK(myfun);
BENCHMARK_MAIN();
Run Code Online (Sandbox Code Playgroud)
构建命令:
clang++ main.cpp -o main -fno-omit-frame-pointer -O0 -lpthread -lbenchmark
Run Code Online (Sandbox Code Playgroud)
perf命令:
perf record -g …Run Code Online (Sandbox Code Playgroud) 如何按输出中的self列排序perf report?
$ perf --version
perf version 4.0.8-300.fc22.x86_64
$ uname -a
Linux marko-desktop 4.0.8-300.fc22.x86_64 #1 SMP Fri Jul 10 21:04:56 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
数据是用
$ perf record -g -p $(pidof node)
Run Code Online (Sandbox Code Playgroud)
当我想在 WSL 下运行 perf 时,我遇到了以下问题:
警告:找不到内核 4.4.0-18362 的性能
您可能需要为此特定内核安装以下软件包:
linux-tools-4.4.0-18362-Microsoft
linux-cloud-tools-4.4.0-18362-Microsoft
您可能还需要安装以下软件包之一以保持最新状态:
linux-tools-微软
linux-cloud-tools-微软
但我找不到名为linux-tools-4.4.0-18362-Microsoftor 的包linux-cloud-tools-4.4.0-18362-Microsoft。我猜包名是自动生成的。
我还尝试在 docker 容器中使用 perf。但是,docker 容器使用与主机相同的内核。
有没有什么方法可以在 WSL 下运行 perf?
我听说在 WSL2 中可以使用 perf。但是在我升级到 WSL2 后,它显示了类似的错误消息:
警告:找不到内核 4.19.84-microsoft 的性能
您可能需要为此特定内核安装以下软件包:
Run Code Online (Sandbox Code Playgroud)linux-tools-4.19.84-microsoft-standard linux-cloud-tools-4.19.84-microsoft-standard您可能还需要安装以下软件包之一以保持最新状态:
Run Code Online (Sandbox Code Playgroud)linux-tools-standard linux-cloud-tools-standard
我目前在运行linux perf时遇到问题,主要是因为/proc/sys/kernel/kptr_restrict当前设置为1.
但是,如果我尝试/proc/sys/kernel/kptr_restrict通过如下回显0来...
echo 0 > /proc/sys/kernel/kptr_restrict
Run Code Online (Sandbox Code Playgroud)
我得到一个权限被拒绝错误.我认为我也不能改变它的权限.
有没有办法直接设置这个?我是超级用户.我不认为如果没有这个设置,perf将会起到可接受的作用.
虽然我可以直观地得到大部分结果,但我很难完全理解perf report命令的输出,特别是对于调用图有什么关系,所以我写了一个愚蠢的测试,一劳永逸地解决了我的这个问题.
我编写了以下内容:
gcc -Wall -pedantic -lm perf-test.c -o perf-test
Run Code Online (Sandbox Code Playgroud)
没有积极的优化来避免内联等.
#include <math.h>
#define N 10000000UL
#define USELESSNESS(n) \
do { \
unsigned long i; \
double x = 42; \
for (i = 0; i < (n); i++) x = sin(x); \
} while (0)
void baz()
{
USELESSNESS(N);
}
void bar()
{
USELESSNESS(2 * N);
baz();
}
void foo()
{
USELESSNESS(3 * N);
bar();
baz();
}
int main()
{
foo();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
perf …Run Code Online (Sandbox Code Playgroud) 请考虑以下简单代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <err.h>
int cpu_ms() {
return (int)(clock() * 1000 / CLOCKS_PER_SEC);
}
int main(int argc, char** argv) {
if (argc < 2) errx(EXIT_FAILURE, "provide the array size in KB on the command line");
size_t size = atol(argv[1]) * 1024;
unsigned char *p = malloc(size);
if (!p) errx(EXIT_FAILURE, "malloc of %zu bytes failed", size);
int fill = argv[2] ? argv[2][0] : 'x';
memset(p, fill, size);
int startms = cpu_ms();
printf("allocated %zu bytes …Run Code Online (Sandbox Code Playgroud) perf ×10
linux ×8
c ×3
linux-kernel ×3
performance ×3
profiling ×2
c++ ×1
cpu-cache ×1
intel-pmu ×1
radiance ×1
ubuntu ×1
valgrind ×1
windows-subsystem-for-linux ×1
x86 ×1