kfmfe04
kfmfe04

Reputation: 15327

How to measure time spent on disk I/O during a compile/link cycle?

On a Linux system, is there a way to measure the amount of time spent on disk I/O during a g++ compile/link cycle?

I am interested in measuring this metric before spending money on a SSD to improve build times.

Upvotes: 2

Views: 570

Answers (2)

MasterID
MasterID

Reputation: 1510

You can use ccache.

It is a cache for C/C++, Objective-C and Objective-C++.

It will improve a lot the compilation of already compiled sources. It means the most of time of compiler is spent executing code than waiting for IO(at least for C++).

If you need to clean your source frequently, it is a must have.

Compiling my project without ccache: 7 minutes and 46 seconds

with it: 24 seconds

Upvotes: 1

wallyk
wallyk

Reputation: 57784

To amplify @MarkGarcia's comment: It would be difficult to isolate wait time during i/o. Linux does read ahead buffering from disk and does other optimizations which will frustrate getting a solid timing.

The effort to get an accurate i/o time is likely to affect the measurement anyway. Maybe you could alter gcc to add instrumentation code, or put gcc inside an emulation box which times the i/o, or something else probably also quite heavy duty.

But what you really want to know is how is the overall compilation time affected by waiting for disk.

Simple method 1: Run the compilation twice in a row and measure execution time—perhaps with the times command. The first time will read the files from disk. The second time will most probably use memory-cached copies of the files, unless a file is very large or the system is otherwise busy handling other memory intensive tasks (which would cause the file cache to clear soon).

Not as simple method 2: Load all the needed files onto the ram disk—your build tree plus everything from /usr/include and the needed bits from /usr/lib— and alter the build to use those files instead. This will be irritating to get right.

Upvotes: 0

Related Questions