1

I am trying to optimize a project and would like to analyze how efficient the project is by looking at I/O. The project only affects files and directories in a local directory which makes things a little simpler. Assuming that the fewer the number of I/O operations (let's go with this for the moment), the better, is there a way to monitor or simply get a count of all filesystem operations from when a process A starts to when process A ends? Are there tools that allow you to do this? I am on MacOS, but would be looking to get something to work on either *nix or MacOS.

How to do this right? How to analyze performance of application based off of local filesystem I/O?

This happens to be a node.js application (not a server though)

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

3

Yes, that tool exists. It is strace.

On OSX, the equivalent tool appears to be dtruss.

Each of strace and dtruss support the -c switch. On strace, this switch reports "time, calls, and errors for each system call and reports a summary on program exit." On dtruss, it "prints system call counts".

The -c switch might give you everything you are asking for, but study the man pages anyway; they might inspire you to look at other data, too.

Examples:

strace -o /tmp/strace.out -e trace=file,open,close,read,write /bin/echo hello
grep -c '^write' /tmp/strace.out
$ strace -c -e trace=file,open,close,read,write /bin/echo hello
hello
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 36.47    0.000031          10         3           open
 21.18    0.000018           6         3         3 access
 17.65    0.000015          15         1           write
 11.76    0.000010           2         5           close
  7.06    0.000006           6         1           execve
  5.88    0.000005           5         1           read
------ ----------- ----------- --------- --------- ----------------
100.00    0.000085                    14         3 total
Robᵩ
  • 163,533
  • 20
  • 239
  • 308
1

inotify / inotifywatch could also be used for this purpose.

this is a kernel level hook that can be used to initiate filesystem monitoring. it is specific to linux.

ref: https://linux.die.net/man/7/inotify

Matt Joyce
  • 2,010
  • 2
  • 20
  • 31