Bug 19601 – Running -profile=gc when no gc is logged leaves old misleading file contents

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-21T11:58:04Z
Last change time
2024-12-13T19:02:07Z
Assigned to
No Owner
Creator
John Burton
Moved to GitHub: dmd#19530 →

Comments

Comment #0 by john.burton — 2019-01-21T11:58:04Z
Rather minor issue but might be easy to fix if it's agreed it's a bug and worth the effort. Using the following option on dmd :- -profile=gc When the resulting executable file is run it logs GC operations to the file profilegc.log However if no GC operations occurs during the run, then any previous contents of that file is left unchanged which is misleading as the file does not accurately reflect the result of the profiling (which should be an empty file) This caused me a small amount of confusion when I was trying to eliminate the gc operations from some inner loop code and was trying to understand the results once I'd managed to eliminate all the GC operations. I would expect that it you've requested a gc profile and there is nothing for the log that an empty file is produces or some indication that there is no GC (or even the file is removed).
Comment #1 by john.burton — 2019-01-22T13:53:23Z
It looks like the reason is this line :- https://github.com/dlang/druntime/blob/424640864c2aa001731467e96f637bd3e704e481/src/rt/profilegc.d#L137 where it only creates the file if there is anything to write to it. It's not as simple as just removing the test though to "fix" as we presumably only want to do this if the user has requested the profile was made.
Comment #2 by tiberiulepadatu14 — 2019-03-08T11:04:48Z
(In reply to John Burton from comment #1) > It looks like the reason is this line :- > https://github.com/dlang/druntime/blob/ > 424640864c2aa001731467e96f637bd3e704e481/src/rt/profilegc.d#L137 > > where it only creates the file if there is anything to write to it. > It's not as simple as just removing the test though to "fix" as we > presumably only want to do this if the user has requested the profile was > made. So we should test if the user has requested that the profile is made and then, if there is nothing to write in the file just create the file?
Comment #3 by hsteoh — 2022-01-18T01:27:44Z
Ran into this today. Taken together with the other -profile=gc issues, this makes -profile=gc extremely misleading. It fails to detect GC allocations via druntime APIs, *and* fails to update profilegc.txt when no allocations happened on that run, leaving stale data in the file (or fails to create the file at all, making users wonder whether -profile=gc even had any effect). At the very least it should create an empty file per run.
Comment #4 by hsteoh — 2022-01-18T15:37:05Z
Relevant code: druntime/src/rt/profilegc.d The simplest fix I can think of is for the compiler to emit a call to some druntime function that sets a flag indicating we need to create this file (so that this doesn't trigger when *not* compiling with -profile=gc), then change the if-condition in profilegc.~this to check this flag instead of counts.length.
Comment #5 by robert.schadek — 2024-12-13T19:02:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19530 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB