Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Comments

Add access to GC runtime profile stats#2155

Closed
marcioapm wants to merge 0 commit intodlang:masterfrom
marcioapm:master
Closed

Add access to GC runtime profile stats#2155
marcioapm wants to merge 0 commit intodlang:masterfrom
marcioapm:master

Conversation

@marcioapm
Copy link
Contributor

Would be very helpful to get this in the next public release.

@wilzbach
Copy link
Contributor

This will need a changelog entry - see the changelog folder.

@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your 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 locally

If 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"

@wilzbach wilzbach added the @andralex Approval from Andrei is required label Mar 28, 2018
@wilzbach
Copy link
Contributor

@marcioapm FYI as this is a new symbol it requires approval from @andralex.
I'm also CCing @rainers and @DmitryOlshansky who are our GC experts.


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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safe too please

/// total time spent doing GC in hnsecs
long totalCollectionTime;
// largest time spent doing one GC cycle in hnsecs
long maxCollectionTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ulong

/// total number of GC cycles
size_t numCollections;
/// total time spent doing GC in hnsecs
long totalCollectionTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ulong

* See `core.memory.GC.ProfileStats` for list of available metrics.
* Requires GC profiling to be on
*/
static ProfileStats profileStats() nothrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safe nogc

@marcioapm
Copy link
Contributor Author

Will this be included in the next public release?

@wilzbach wilzbach removed the @andralex Approval from Andrei is required label Apr 2, 2018
@wilzbach
Copy link
Contributor

wilzbach commented Apr 2, 2018

@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.
This just needs to be looked at by one of our GC experts - I don't see anything else that's blocking this.

@wilzbach wilzbach added this to the 2.080.0 milestone Apr 2, 2018
@rainers
Copy link
Member

rainers commented Apr 2, 2018

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.

@mihails-strasuns-sociomantic
Copy link
Contributor

I would expect this to be nested under regular GC.Stats

@marcioapm
Copy link
Contributor Author

Filling in GC.Stats is not O(1), requires a lock, and doesn't depend on GC profiling being on.
They are somewhat related, but GC.Stats seems to be about memory statistics, at least in it's current form, whilst GC.ProfileStats is about performance.

@mihails-strasuns-sociomantic
Copy link
Contributor

You don't expect to call ProfileStats in a hot loop, do you? Because implementation of actual GC profiling is very far from being usable for that (I tweak that a bit in #1846 but that is still different league of performance).

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 -profile=gc, it will get populated, and otherwise it will stay zero. But it is still there all the time - and in presence of shared libraries it is not even known if it will stay zero if nothing uses GC profiling right now. This is exactly why I expect it to be an inherent part of GC stats.

@mihails-strasuns-sociomantic
Copy link
Contributor

Oh, stupid me. I have read PR title and assumed it is also about -profile=gc stats - and only now paid attention to actual content - which seems to be for --DRT-opt profile thing.

Nevermind.

@marcioapm
Copy link
Contributor Author

This is failing because of a shell script.

[libdparse] Running shell script
+ cd test
+ ./run_tests.sh
find: ‘../stdx-allocator/source’: No such file or directory
Compiling unit tests...../src/dparse/parser.d(9): Error: module `mallocator` is in file 'stdx/allocator/mallocator.d' which cannot be read
import path[0] = ../src/
import path[1] = ../stdx-allocator/source
import path[2] = /var/lib/jenkins/dlang_projects@3/distribution/bin/../imports
+ find test/coverage -type f -exec mv {} . ;
find: ‘test/coverage’: No such file or directory
script returned exit code 1```

@wilzbach
Copy link
Contributor

wilzbach commented Apr 4, 2018

Don't worry about Jenkins - it's currently broken and known -> dlang/ci#190 (and here's yours: dlang/ci#193)

Copy link
Member

@rainers rainers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

/// total number of GC cycles
size_t numCollections;
/// total time spent doing GC in hnsecs
ulong totalCollectionTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep Duration as the time type.


ret.numCollections = numCollections;
ret.totalCollectionTime = (prepTime + markTime + sweepTime + recoverTime).total!"hnsecs";
ret.maxCollectionTime = maxPauseTime.total!"hnsecs";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MartinNowak MartinNowak removed this from the 2.080.0 milestone Apr 17, 2018
@MartinNowak
Copy link
Member

MartinNowak commented Apr 17, 2018

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.
Milestones are used as a communication tool so we don't miss to release essential PRs.

I understand that GH's issue tracker and milestone feature is designed for and often used for planning in other contexts though.

@jacob-carlborg
Copy link
Contributor

What is the status of this?

@marcioapm
Copy link
Contributor Author

@rainers I think I got all your concerns addressed.

@rainers
Copy link
Member

rainers commented Sep 12, 2018

LGTM but the Requires GC profiling to be active. hints are no longer valid.

The CI failures seem unrelated. core.sys.posix.stdio is not compiled into the druntime lib for some reason...

Duration totalCollectionTime;
/// total time threads were paused doing GC
Duration totalPauseTime;
// largest time threads were paused during one GC cycle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ddoc /// here and below, too.


/**
* Aggregation of current profile information, requires profiling to be on
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The * are not aligned. I recommend using /// instead, which also will save two lines.

/**
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still mentions GC profiling needs to be on.


/**
* Retrieve profile statistics about garbage collection.
* Useful for debugging and tuning. Requires profiling to be on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, too.

@rainers
Copy link
Member

rainers commented Sep 23, 2018

Closing and reopening to retrigger CIs.

@PetarKirov
Copy link
Member

Rebased in #2332.

@PetarKirov
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants