How can I make the underlying file access actions of git log visible

153 Views Asked by At

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.

2

There are 2 best solutions below

0
On

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.

3
On

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