NIX_SHOW_STATS_PATH is overwritten even if a statistics file already exists at the given path. This can be problematic when profiling certain nix tools such as nixops that invoke multiple instances of nix in quick succession. You're only able to have a stats file for the latest invocation of nix in these scenarios, and all previous invocations have their stats file overwritten.
Steps To Reproduce
Profile a nixops deployment with NIX_SHOW_STATS=1 & NIX_SHOW_STATS_PATH=stats.json
Observe the file is overwritten multiple times:
$ inotifywait -m ./stats.json
Setting up watches.
Watches established.
./ OPEN
./ ACCESS
./ CLOSE_NOWRITE,CLOSE
./ OPEN
./ ACCESS
./ CLOSE_NOWRITE,CLOSE
./ MODIFY
./ OPEN
./ MODIFY
./ CLOSE_WRITE,CLOSE
./ OPEN
./ ACCESS
./ CLOSE_NOWRITE,CLOSE
./ MODIFY
./ OPEN
./ MODIFY
./ CLOSE_WRITE,CLOSE
./ OPEN
./ ACCESS
./ CLOSE_NOWRITE,CLOSE
...
**Expected behavior**
`nix` should perhaps append a random discriminator to the file name to prevent collision similar to many profiling tools that randomize dump file names.
**`nix-env --version` output** `nix-env (Nix) 2.5.0pre20211206_d1aaa7e`
Describe the bug
NIX_SHOW_STATS_PATH
is overwritten even if a statistics file already exists at the given path. This can be problematic when profiling certainnix
tools such asnixops
that invoke multiple instances ofnix
in quick succession. You're only able to have a stats file for the latest invocation ofnix
in these scenarios, and all previous invocations have their stats file overwritten.Steps To Reproduce
nixops
deployment withNIX_SHOW_STATS=1
&NIX_SHOW_STATS_PATH=stats.json
...