Barth
Barth

Reputation: 15715

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 ?

Related question (windows) : Disk IO profiler for existing applications

Upvotes: 2

Views: 1831

Answers (2)

Marcin
Marcin

Reputation: 3524

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.

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 can also attach to running processes, so you can observe the program as it's running.
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. It's a lot easier to find things this way, as the default strace output is not very human-readable.

Important thing to remember is to log to another partition/set of disks than where the IO problem is! Do not induce extra IO problems as strace can generate a lot of output. I like to use a TmpFS or ZRAM RAM-disks for such occasions.

Upvotes: 4

A.H
A.H

Reputation: 1025

So, you can use: /proc/PID/fd or lsof -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:

./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

Upvotes: 7

Related Questions