Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagnostic tracker API #17961

Closed
terrajobst opened this issue Jul 29, 2016 · 14 comments
Closed

Add diagnostic tracker API #17961

terrajobst opened this issue Jul 29, 2016 · 14 comments
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Diagnostics
Milestone

Comments

@terrajobst
Copy link
Member

As discussed in issue #17891, we would like a higher-level tracking API for measuring allocations. The goal is to make an API that is similar to Stopwatch:

namespace System.Diagnostics
{
    public class ManagedAllocationTracker
    {
        public static ManagedAllocationTracker StartNew();
        public long AllocatedBytes { get; }
    }
}

This API will also allow tracking bytes across execution contexts.

@KrzysztofCwalina suggested to make it even more general purpose and allow the tracker to track more diagnostic information.

@terrajobst terrajobst changed the title Add tracker API Add diagnostic tracker API Jul 29, 2016
@benaadams
Copy link
Member

Also public long AllocatedObjects { get; }?

@Maoni0
Copy link
Member

Maoni0 commented Aug 1, 2016

@benaadams, can you please give a scenario where you make use of # of allocated objects?

@vancem
Copy link
Contributor

vancem commented Aug 1, 2016

The reason behind Maoni's question is that unlike the byte pointer (which we track because it is needed for the implementation, an object counter is not, and thus is 'pure overhead'. It is not large, but anything done on every allocation (by default), is overhead we really don't want.

We are likely to want to leave it out for that reason...

@benaadams
Copy link
Member

It gives more character to the allocations; so if I did:

var tracker = ManagedAllocationTracker.StartNew();

streamIn.CopyTo(streamOut);

tracker.Stop(); // Maybe, similar to Stopwatch?

It would tell me 82kB which I might think is crazy high; however the objects allocated would be 1 which would provide context.

There is always memory tracing for investigation, which is fully featured in .NET, so if it came at an extra overhead I don't think it would be worth it.

However, the other stopwatch methods could be useful e.g.
Reset(), Restart(), Start(), Stop()

This could easily be handled in the external code, but it would be less messy if it could be internalized into the tracer instance.

@mattwarren
Copy link
Contributor

Out of interest, will this API be added to Desktop CLR as well or is it intended for CoreCLR only?

@KrzysztofCwalina suggested to make it even more general purpose and allow the tracker to track more diagnostic information.

What additional diagnostic information could it track?

@mattwarren
Copy link
Contributor

Also, will the API be fine-grained enough to support code like this, i.e. get the size of a single object?

var tracker = ManagedAllocationTracker.StartNew();
var text = "Some Text";
// will tracker.AllocatedBytes now be the exact size of the string "Some Text"?
var textSize = tracker.AllocatedBytes;

@MendelMonteiro
Copy link

This would be extremely handy for us in unit testing code which we try to make allocation free. Currently we monitor the GC count before and after but the number of iterations needed to guarantee that it is allocation free is completely arbitrary and increases the test time.

In our use case it is fairly binary, AllocatedBytes > 0 == bad, and so the number of allocated objects is irrelevant.

@khellang
Copy link
Member

How do you stop it? 🚎

@vancem
Copy link
Contributor

vancem commented Aug 11, 2016

The class should have a Stop() method (analogous to Stopwatch), but it will also stop when the object dies. It should also probably have the other analogous methods like Reset() and Start() and Restart() and IsRunning().

@khellang
Copy link
Member

I've always liked using blocks for these things. They make it pretty clear whre the allocations are measured.

@vancem
Copy link
Contributor

vancem commented Aug 11, 2016

Supporting IDisposable is also very reasonable.

@Maoni0 Maoni0 assigned Maoni0 and unassigned vancem Oct 3, 2016
@karelz
Copy link
Member

karelz commented Nov 10, 2016

We need formal API proposal.

@stephentoub
Copy link
Member

@terrajobst, given that we have https://github.com/dotnet/corefx/issues/10157, and given https://github.com/dotnet/corefx/issues/30644 and https://github.com/dotnet/corefx/issues/34631, is this still something we're pursuing, or can this issue be closed?

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Mar 7, 2020
@tommcdon
Copy link
Member

tommcdon commented Aug 7, 2020

It seems like this issue was addressed and has no activity for over a year, so closing

@tommcdon tommcdon closed this as completed Aug 7, 2020
.NET Core Diagnostics automation moved this from Backlog to Done Aug 7, 2020
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Diagnostics
Projects
Development

No branches or pull requests