简体   繁体   English

Linux上C ++应用程序的磁盘IO分析器

[英]Disk IO profiler for a C++ application on Linux

A program is massively reading from the disk but I don't know which file it is reading nor where in the code it is reading. 程序正在从磁盘上进行大量读取,但是我不知道它正在读取哪个文件,也不知道它在代码中的什么位置。

Is there any kind of tools on linux to monitor this ? Linux上是否有任何工具可以监视此情况?

Related question (windows) : Disk IO profiler for existing applications 相关问题(Windows): 现有应用程序的磁盘IO分析器

So, you can use: /proc/PID/fd or lsof -p PID 因此,您可以使用: /proc/PID/fdlsof -p PID

to know which file your process use. 知道您的进程使用哪个文件。

for example, with lsof -p 27666 (assume 27666 is the PID of a.out program) you can see this: 例如,使用lsof -p 27666 (假设27666是a.out程序的PID),您可以看到以下内容:

./a.out 22531 me    9w   REG   8,5   131072   528280 /home/me/tmp/test.db
./a.out 22531 me    9r   REG   8,5   131072   528280 /home/me/tmp/test2.db

If the system is really busy with IO, just look at top and you'll see the IO-bound process usually stuck in a D-state. 如果系统真的很忙于IO,则只需查看top ,您就会看到IO绑定进程通常停留在D状态。

strace -c myprog is my best friend for a first attempt at all generic 'what is my application doing/where is it spending most time' questions. strace -c myprog是我最好的朋友,它是所有通用“我的应用程序在做什么/花时间最多的地方”问题的第一次尝试。 Strace can also attach to running processes, so you can observe the program as it's running. Strace还可以附加到正在运行的进程,因此您可以在程序运行时对其进行观察。
Another good strace trick is to output it (with strace -o myprogrun.log ) to a log file , then view it with a modern vim as it does a very nice job syntax highlighting the log. 另一个很好的strace技巧是将它(使用strace -o myprogrun.log )输出到日志文件,然后使用现代的vim查看它,因为它在突出显示日志方面做得很好。 It's a lot easier to find things this way, as the default strace output is not very human-readable. 通过这种方式查找事物要容易得多,因为默认的strace输出不是人类可读的。

Important thing to remember is to log to another partition/set of disks than where the IO problem is! 要记住的重要事项是,要登录到另一个分区/磁盘集,而不是IO问题所在! Do not induce extra IO problems as strace can generate a lot of output. 不要引起额外的IO问题,因为strace会产生大量输出。 I like to use a TmpFS or ZRAM RAM-disks for such occasions. 在这种情况下,我喜欢使用TmpFS或ZRAM RAM磁盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM