1

I would like to visual the file system actions that are caused by running something like git lg -n3. I'm on a Mac. So I thought, ok let's run dtruss git lg -n3.

Unfortunately this doesn't give me the expected output. I would expect to see file access to some files at .git/objects.

Is dtruss not what I'm looking for?

I should add that I also don't see the output of git log when I run it through dtruss. If I run dtruss git I see the output of the git command overview at least. Am I doing it wrong?

UPDATE

Ok, turns out it's a problem with how dtruss handles the multi word command git log. If I use dtruss /usr/local/git/libexec/git-core/git-log it works as expected.

I can go further and run dtruss /usr/local/git/libexec/git-core/git-log -n3 2>&1 | grep access and get pretty much what I was looking for. So the only remaining question really would be why I have to use the full path to git-log instead of just the git log command.

Christoph
  • 26,519
  • 28
  • 95
  • 133
  • I have `access(".git/objects/f8/f38eae3f999ad65a8818862da946708bf7f15f\0", 0x0, 0x100276865) = 0 0`. Seems works as you expect. – kan Aug 26 '14 at 22:41
  • mmh, I don't have those in the output of `dtruss git lg -n3` :-/ – Christoph Aug 26 '14 at 22:47
  • Riiiight... As I see it appears first time, and then doesn't. Looks like that files are cached, so it is not accessed second time. – kan Aug 26 '14 at 22:55
  • 1
    Pretty sure you want strace. That will tell you every system call it makes (check options for following forks). – jthill Aug 27 '14 at 03:27
  • @kan I just tried it out on a fresh git repository and even for the first call to `dtruss git lg -n3` I don't see those files getting accessed :-/ – Christoph Aug 27 '14 at 08:06
  • But I also don't see the output of `git log` when I run it through `dtruss` so I'm wondering if I'm doing it wrong. – Christoph Aug 27 '14 at 08:19
  • Ok, turns out it's a problem with how dtruss handles the multi word command `git log`. If I use `dtruss /usr/local/git/libexec/git-core/git-log` it works as expected. – Christoph Aug 27 '14 at 08:29
  • I'd guess that dtruss command line parsing is a bit weird and it thinks `log` and `-n3` is meant for it. The sane (GNU) way would be to support `--` separator as in `dtruss -- git log -n3`. I don't have Mac to test, though. Another possible fix would be to run `dtruss "git log -n3"`. – Mikko Rantalainen Aug 28 '14 at 13:22
  • unfortunately `dtruss "git log -n3` doesn't work. It doesn't seem to perform the `git log` at all then :( – Christoph Aug 28 '14 at 13:36

2 Answers2

2

On UNIXoid systems like Linux (embedded or desktop) I like to use inotify-tools for that purpose, e.g. inotifywait or inotifywatch, depending on my exact purpose.

Edit: I wonder why someone has downvoted my answer. Inotify-tools is a specialised set of tools for monitoring file system access, and this is what was asked. I would appreciate a remark with a request for clarification first, if my answer does not seem to be good or relevant enough. Thank you.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
2

You probably want to try strace. For example, this may be the result you're looking for:

strace -q -f -e trace='open,stat' git log -n3

or if you really want all file system access

strace -q -f -e trace=file git log -n3

should do it. Drop the -f part if you don't need to trace the stuff done by less and other possibly executed forked processes. As usual, man strace will be worth reading...

Mikko Rantalainen
  • 14,132
  • 10
  • 74
  • 112