- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个运行异常缓慢的应用程序。我有理由怀疑这可能是因为某些特定文件的读取和统计速度较慢。
我知道我可以使用 strace 获取计时信息,但我更愿意使用 perf,因为开销要低得多。
Brendan Gregg 有一些使用 perf 的有用示例:
http://www.brendangregg.com/perf.html
但他的第一个系统调用示例仅显示所有调用的总计时,我需要每个文件的计时。他的第二个系统调用示例不包括时间,只显示 fd 数字,而不是真实路径。
我如何将它们拼凑起来?我正在寻找类似于我从“strace -Tttt -e trace=file”中得到的东西。
如果我可以同时测量周期,那将是额外的好处。
最佳答案
strace -Tttt -e trace=file
的输出是 trace(跟踪工具),perf 通常用作分析工具(按名称汇总在函数中花费的时间 - 在 perf 记录中
默认按时间或硬件事件 + perf report
、perf top
模式)或作为统计工具(在 perf stat
模式下) - 在程序的整个运行时间内对一些事件进行计数)。
您应该尝试一些跟踪工具(trace-cmd
、sysdig
、lttng、...)或者您可以尝试在跟踪模式下使用perf
(perf record
使用跟踪点和 perf 脚本
随时间输出非聚合日志)
有系统调用的跟踪点(syscalls 614
): http://www.brendangregg.com/perf.html#Tracepoints http://www.brendangregg.com/perf.html#StaticKernelTracing
perf record -e 'syscalls:sys_*' ./program
perf script
格式输出示例:process_name, pid, [cpu_core], time_since_boot_seconds.microseconds:, tracepoint_name, tracepoint_arguments
ls 19178 [001] 16529.466566: syscalls:sys_enter_open: filename: 0x7f6ae4c38f82, flags: 0x00080000, mode: 0x
ls 19178 [001] 16529.466570: syscalls:sys_exit_open: 0x4
ls 19178 [001] 16529.466570: syscalls:sys_enter_newfstat: fd: 0x00000004, statbuf: 0x7ffe22df92f0
ls 19178 [001] 16529.466572: syscalls:sys_exit_newfstat: 0x0
ls 19178 [001] 16529.466573: syscalls:sys_enter_mmap: addr: 0x00000000, len: 0x00042e6f, prot: 0x00000001,
ls 19178 [001] 16529.466767: syscalls:sys_exit_mmap: 0x7f6ae4df8000
ls 19178 [001] 16529.466768: syscalls:sys_enter_close: fd: 0x00000004
ls 19178 [001] 16529.466769: syscalls:sys_exit_close: 0x0
您也可以尝试使用 perf record -g -e 'syscalls:sys_*'
来记录函数回溯(以获取应用程序的哪个函数进行了系统调用以及谁调用了该函数的信息;与调试信息配合使用效果更好)。
perf 作为跟踪工具可能无法解码系统调用(跟踪点)参数; trace-cmd 或 lttng 等跟踪工具可能会更好地解码它们(至少在打开的系统调用中解码文件名)。
关于linux - 如何测量与文件相关的系统调用在 perf 中花费了多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49741256/
我一直在读一本分配给类(class)的书,它提到数组访问需要 O(1) 时间。我意识到这非常快(也许尽可能快),但是如果您有一个循环必须多次引用它,那么分配一个临时变量以在数组中查找值有什么好处吗?或
我一直试图找出为什么这个查询花了这么长时间。以前,它的执行时间约为 150 毫秒到 200 毫秒,但现在需要 25 秒或更长时间。这是从昨晚到今天之间的事。唯一改变的就是将数据添加到表中。 根据下面的
我有一个 ng repeat 重复数据。 - data.image(src)部分为null,src=null的不再重复。 我用一个简单的 ng-if 解决了它。
我有一个包含大量测试的 Laravel 项目。我正在使用 pcov 来计算代码覆盖率,大约需要 4 分钟。但是 pcov 不支持分支覆盖,所以我决定使用 xdebug。 使用 xdebug 测试执行,
我已经被这个问题困扰了一段时间了,我被难住了。 Automapper 需要 4 秒来映射 19 个对象。在我的机器(24GB 内存,3.6Ghz i7)上,该操作应该花费毫秒或纳秒。 这是映射调用。
我有一个包含大量测试的 Laravel 项目。我正在使用 pcov 来计算代码覆盖率,大约需要 4 分钟。但是 pcov 不支持分支覆盖,所以我决定使用 xdebug。 使用 xdebug 测试执行,
我在机器 A 上有一个 java 进程通过 TCP 与机器 B 上的 Tomcat 通信。 TCP 连接(只是 syn-syn/ack 交换)始终需要 100 毫秒的数量级,而 ping 请求需要 1
我做了一项任务,从 sqlserver 获取超过 200 万条记录并将它们填充到 Asp.net GridView 中。 问题是,查询需要超过 2 分钟才能获得记录,而我的查询现在已经完全优化。 当我
我希望将 165 秒变成 2:40 而不是 0:2:45 函数需要能够适应秒值的大小。 我知道有无数种方法可以做到这一点,但我正在寻找一种干净的方法来做到这一点,除了 jQuery 之外没有任何外部库
我是一名优秀的程序员,十分优秀!