Skip to content

[API Proposal]: Exposing the total paused duration in GC. #66036

@cshung

Description

@cshung

Background and motivation

Today we have already exposed the total paused time as a percentage of the process time on the GetGCMemoryInfo API.

In particular, through the PauseTimePercentage field on the GCMemoryInfo struct.

This is useful, but what if I only want to numerator (i.e. the total amount of time paused in GC since the beginning of the process?). There is no way to get that value for now.

API Proposal

I am proposing to add an API on System.GC as follow:

TimeSpan System.GC.GetTotalPauseDuration()

This will return the total paused duration in the GC

API Usage

...
TimeSpan start = System.GC.GetTotalPauseDuration();
// ... Perform some work ...
TimeSpan end= System.GC.GetTotalPauseDuration();
Console.WriteLine(end - start + " was spent pausing in GC");
...

Alternative Designs

We have considered the alternative to add a field on the GetGCMemoryInfo API, this will also work, but if the only thing we wanted is just the total pause time, that API will carry a larger overhead than necessary.

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-GC-coreclr

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions