Link to home
Start Free TrialLog in
Avatar of zizi21
zizi21

asked on

count physical input / output operations

hi,

i am programming in C to run the program on linux. I am trying to find the number of physical input / output operations made to disk to get the data ?

Is there any function in linux or C or a profiler that helps to do this..thanks .
Avatar of Hugh McCurdy
Hugh McCurdy
Flag of United States of America image

I doubt that information is available to even the Linux kernel.  The kernel might be able to count the requests it made.  But due to caching by disk drives, the kernel doesn't know (nor does it care) which operations actually involve a physical read or physical write and how many there were per each request.
Avatar of zizi21
zizi21

ASKER

But, would there a function to count disk cache misses. This is because if there is a disk cache miss, you need to go to disk and get it ?
Caveat: I could be wrong and you should wait for other opinions.

Disk cache misses are handled invisibly by the disk drive's firmware.  Drives used to be accessed by Cylinder/Head/Sector.  During that time, I think such metrics were possible.  But that was long ago.

I would wait around to see if someone else comes by with a solution.  Just because I think the theory won't allow it doesn't mean I'm right.
Avatar of zizi21

ASKER

Thanks for replying. It is appreciated.
No problem.  

It might help to know why you want to count disk activity.  

Otherwise, I'd let this rest for a while and give others a chance to show up.  It's Friday night in the U.S. and people might be doing other things.  (Other than watching baseball and working on the computer at the same time.)  Good luck in your quest.
Avatar of zizi21

ASKER

Hi !

I am testing the efficiency of the my programs. I am unable to rely much on the timings because there is are chances that the disk caches might cache the data. Another way is to find the number of seeks made to the hard disk. So, if the program makes too many seeks, you can say it is in inefficient.

Thanks again for your time.
In that case, you could put logging in the program.  Of course, that will slow the program but perhaps not much.  Depends on how many read/write instructions you have.

How are you doing the disk I/O?  read/write/seek?  fread/fwrite/fseek?  Something else?

You could count them.  Perhaps wrapper functions like my_read, my_write, etc.  They could count the times used.  In this case, I think using global variables are OK.

Just an idea.
Avatar of zizi21

ASKER

Thanks again for replying.

Besides using fseek , fread and fwrite, I am using mmap. The main problem that I am facing is that with mmap, the implementation details are being hidden from the programmer. So, I was hoping there might be some tool that will count that .

I just came across this tool called ":/sys/block/sda/sda7/stat and it seems to be giving some info. Not sure how reliable is this info...number of reads, writes..
ASKER CERTIFIED SOLUTION
Avatar of Hugh McCurdy
Hugh McCurdy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zizi21

ASKER

Thank you very much. I would look at it now.
Avatar of zizi21

ASKER

Thanks a lot.
Glad it helped.