perf使用示例1

简介: perf使用示例1 perf - Performance analysis tools for Linux Performance counters for Linux are a new kernel-based subsystem that provide a framework for all things performance analysis.

perf使用示例1

perf - Performance analysis tools for Linux

Performance counters for Linux are a new kernel-based subsystem that provide a framework for all things performance analysis. It covers hardware level (CPU/PMU, Performance Monitoring Unit) features and software features (software counters, tracepoints) as well.

perf --help

perf help COMMANDperf COMMAND -h

1.命令简要说明

perf list 命令可以列出所有能够触发 perf 采样点的事件

perf stat [-e <EVENT> | --event=EVENT] [-a] <command> or perf stat [-e <EVENT> | --event=EVENT] [-a] — <command> [<options>] 以概括精简的方式提供被调试程序运行的整体情况和汇总数据

perf top [-e <EVENT> | --event=EVENT] [<options>] 用于实时显示当前系统的性能统计信息

perf record [-e <EVENT> | --event=EVENT] [-l] [-a] <command>

perf -g report 显示调用关系

2.示例1

1)perf stat 命令用于统计进程总体的信息task-clock:CPU 利用率,该值高,说明程序的多数时间花费在 CPU 计算上而非 IO

2)perf top 命令可查看系统的实时信息,例如系统中最耗时的内核函数或某个用户进程

3)perf record 记录单个函数级别的统计信息,并使用 perf report 来显示统计结果,以此可以找到热点

perf record -e cpu-clock -g 给出函数的调用关系,以便于找到次级热点

[dskong@tecsun perfs]$ cat test.c

//test.c

void longa()

{

int i,j;

for(i = 0; i < 1000000; i++)

j=i; //am I silly or crazy? I feel boring and desperate.

}

void foo2()

{

int i;

for(i=0 ; i < 10; i++)

longa();

}

void foo1()

{

int i;

for(i = 0; i< 100; i++)

longa();

}

int main(void)

{

foo1();

foo2();

}

[dskong@tecsun perfs]$ gcc -g test.c

[dskong@tecsun perfs]$ perf stat ./a.out

[dskong@tecsun perfs]$ perf record ./a.out

[dskong@tecsun perfs]$ perf report

[dskong@tecsun perfs]$ perf annotate

原文

http://whatot.github.io/pub/linux_program/perf%E7%AE%80%E4%BB%8B/

http://blog.chinaunix.net/uid-8350672-id-2984617.html

http://www.dskong.com/archives/223

http://www.pixelbeat.org/programming/profiling/

目录
相关文章
|
SQL 缓存 Java
ASH Report 解析
ASH Report 解析
228 0
|
11月前
|
数据可视化 Linux 调度
译 | Linux perf_events Off-CPU Time Flame Graph
译 | Linux perf_events Off-CPU Time Flame Graph
84 0
|
网络安全
Jmeter系列(44)- 详解 Elapsed time、Latency、Connect Time的含义
Jmeter系列(44)- 详解 Elapsed time、Latency、Connect Time的含义
313 0
jMeter CSV Data set config 的 sharing mode 和 Thread group loop 配合使用
jMeter CSV Data set config 的 sharing mode 和 Thread group loop 配合使用
146 0
jMeter CSV Data set config 的 sharing mode 和 Thread group loop 配合使用
|
存储 测试技术 Apache
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
177 0
jMeter 里 CSV Data Set Config Sharing Mode 的含义详解
|
SQL 监控 关系型数据库
参数performance_schema设置最佳实践
最早开源MySQL从5.5开始支持performance_schema(下文简称PFS),又在后续版本不断持续完善、优化,PFS已经成为了性能诊断优化的利器,使SQL问题、锁等待事件等比较清晰地展现出来,但打开PFS也会带来相应的性能成本,本篇就来看下PFS相比其他工具及不打开PFS的性能差异。
参数performance_schema设置最佳实践
|
监控 API 测试技术
PERF EVENT API篇
简介 perf_event 是内核对用户态提供软硬件性能数据的一个统一的接口,用户通过 perf_event 的句柄操作能获取到各式各样的性能数据,本文将介绍如何通过用户态实现对内核 perf_event 功能的使用 API 介绍 int perf_event_open(struct perf_e.
4716 0