Add access to GC runtime profile stats#2155
Conversation
|
This will need a changelog entry - see the |
|
Thanks for your pull request and interest in making D better, @marcioapm! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + druntime#2155" |
|
@marcioapm FYI as this is a new symbol it requires approval from @andralex. |
src/core/memory.d
Outdated
|
|
||
| extern (C) BlkInfo_ gc_query( void* p ) pure nothrow; | ||
| extern (C) GC.Stats gc_stats ( ) nothrow @nogc; | ||
| extern (C) GC.ProfileStats gc_profileStats ( ) nothrow @nogc; |
src/core/memory.d
Outdated
| /// total time spent doing GC in hnsecs | ||
| long totalCollectionTime; | ||
| // largest time spent doing one GC cycle in hnsecs | ||
| long maxCollectionTime; |
src/core/memory.d
Outdated
| /// total number of GC cycles | ||
| size_t numCollections; | ||
| /// total time spent doing GC in hnsecs | ||
| long totalCollectionTime; |
src/core/memory.d
Outdated
| * See `core.memory.GC.ProfileStats` for list of available metrics. | ||
| * Requires GC profiling to be on | ||
| */ | ||
| static ProfileStats profileStats() nothrow |
|
Will this be included in the next public release? |
|
@marcioapm We can't promise this as the next master-stable branch-off is in two weeks, but as Andrei has already approved this, it looks pretty good. |
|
I'm not a huge fan of adding interface members for every stat function which can be specific to a single GC. I think there should be a more generic way to request information from the GC, e.g. using a tagged union. Please also note that there are other PRs adding similar functions: #2052, #1846. Maybe we should also switch GC from an interface to a base class so that it can have (empty) default implementation. That way it might be easier to add functions without having to update every GC. In addition it could result in a tiny performance improvement because it doesn't need the interface thunks that adjusts the class instance offset. |
|
I would expect this to be nested under regular |
|
Filling in |
|
You don't expect to call The fact that it doesn't depend on GC profiling being on is no different for actual GC profiling data - it is always compiled as part of runtime and available to be used. So if you link it with some modules that are compiled with |
|
Oh, stupid me. I have read PR title and assumed it is also about Nevermind. |
|
This is failing because of a shell script. |
|
Don't worry about Jenkins - it's currently broken and known -> dlang/ci#190 (and here's yours: dlang/ci#193) |
rainers
left a comment
There was a problem hiding this comment.
I'm not very strongly against adding this. We might want to record timings unconditionally, though, to avoid the complication of having to enable it. These are only a couple of operations per collection, so it should not have a noticable effect.
On the other hand, you can also access these GC specific variables with a hack, e.g.:
import core.time;
import core.demangle;
extern __gshared pragma(mangle, mangle!Duration("gc.impl.conservative.gc.maxPauseTime")) Duration maxPauseTime;
src/core/memory.d
Outdated
| /// total number of GC cycles | ||
| size_t numCollections; | ||
| /// total time spent doing GC in hnsecs | ||
| ulong totalCollectionTime; |
There was a problem hiding this comment.
I think it would be better to keep Duration as the time type.
src/gc/impl/conservative/gc.d
Outdated
|
|
||
| ret.numCollections = numCollections; | ||
| ret.totalCollectionTime = (prepTime + markTime + sweepTime + recoverTime).total!"hnsecs"; | ||
| ret.maxCollectionTime = maxPauseTime.total!"hnsecs"; |
There was a problem hiding this comment.
collection time and pause time are not the same. The latter is the time that all other threads are suspended aka the world is stopped.
|
Please only use milestones for things that MUST be in the next release, e.g. because it completes an already merged PR. Please do not use them for changes you want in the next release or for general planning. We're releasing often enough so that nobody has to run for the release train. I understand that GH's issue tracker and milestone feature is designed for and often used for planning in other contexts though. |
|
What is the status of this? |
|
@rainers I think I got all your concerns addressed. |
|
LGTM but the The CI failures seem unrelated. core.sys.posix.stdio is not compiled into the druntime lib for some reason... |
src/core/memory.d
Outdated
| Duration totalCollectionTime; | ||
| /// total time threads were paused doing GC | ||
| Duration totalPauseTime; | ||
| // largest time threads were paused during one GC cycle |
src/core/memory.d
Outdated
|
|
||
| /** | ||
| * Aggregation of current profile information, requires profiling to be on | ||
| */ |
There was a problem hiding this comment.
The * are not aligned. I recommend using /// instead, which also will save two lines.
src/core/memory.d
Outdated
| /** | ||
| * Returns runtime profile stats for currently active GC implementation | ||
| * See `core.memory.GC.ProfileStats` for list of available metrics. | ||
| * Requires GC profiling to be on |
There was a problem hiding this comment.
Still mentions GC profiling needs to be on.
src/gc/gcinterface.d
Outdated
|
|
||
| /** | ||
| * Retrieve profile statistics about garbage collection. | ||
| * Useful for debugging and tuning. Requires profiling to be on. |
|
Closing and reopening to retrigger CIs. |
|
Rebased in #2332. |
|
I didn't intend to close this PR, GitHub somehow automatically did. I rebased @marcioapm's branch locally, but I couldn't force push it to his branch as the PR got closed, so I opened #2332 - let's continue the discussion there. |
Would be very helpful to get this in the next public release.