-
-
Notifications
You must be signed in to change notification settings - Fork 421
Exposes minimal GC stats via gc_usage #1591
Conversation
Fixes issue 16019
|
Whitespace issue. |
|
It is currently not exposed being current GC implementation detail. As far as I understand, reason for that was that full
I wasn't sure either but code looks like it : https://github.com/dlang/druntime/blob/master/src/gc/gc.d#L1262-L1264 |
Oops, it must be |
What I think may be a better option than creating a redundant, less powerful, but more general and stable function, is to document which of the The gc_stats function itself can remain undocumented for now (and sociomantic just knows that it's there). This can't be any worse than your current situation. |
So what API would you envision for actual public function? One additional problem with exposing |
@@ -130,6 +130,8 @@ private | |||
extern (C) void* gc_addrOf( void* p ) pure nothrow; | |||
extern (C) size_t gc_sizeOf( void* p ) pure nothrow; | |||
|
|||
extern (C) void gc_usage( out size_t used, out size_t free) nothrow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return a struct instead of using out parameters.
That implies moving GCStats to core.memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it's already there, so please just forward to gc_stats here, and change the GCStats members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it's already there
? There is no GCStats
in core.memory
, it is only defined in gc stats module. This is why I am not sure about how to proceed here.
How about introducing new core.gcapi
module that can be imported by both GC implementations and core.memory
? This whole business of manually maintaining extern(C)
declarations in sync feels like legacy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @MartinNowak
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about introducing new core.gcapi module that can be imported by both GC implementations and core.memory?
That's more or less what gc.gcinterface does in #1581.
This whole business of manually maintaining extern(C) declarations in sync feels like legacy.
I agree. If the extern(C) interface is to stay (it is barely useful to begin with), it should be opt-in provided by a GC proxy. Having the calls go through an extern(C) interface also inhibits some inlining for the common case.
I'd opt for struct GCStats
{
size_t heapsize; /// total size of GC heap
size_t freesize; /// free bytes on the GC heap (might only get updated after a collection)
} atm. |
Thanks, will keep it in mind |
A common technique is to have a field with flags for valid info fields in the info struct, for example https://technet.microsoft.com/en-us/library/bb146197(v=vs.110).aspx
Importing |
Sounds like a good approach indeed.
It looks semantically wrong though, considering it is |
I thought so too, but it turns out it is by design. See: |
@ZombineDev that doesn't contradict my proposal of |
Let's not overcomplicate things, we can go with a minimal API first and extend it later, e.g. by adding a name argument and a separate float value for that field.
We won't add any expensive stat functions. The values might be outdated and/or estimates. The path forward here is the following.
|
Replaced by #1610 |
https://issues.dlang.org/show_bug.cgi?id=16019
This is one very minor utility that we have in Sociomantic GC API that makes it different from current upstream one - and which is used quite extensively. One of most important use cases of having these stats is to be able write a test that memory consumption is O(1) for a function that can't be
@nogc
.Ping @MartinNowak