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 runtime memory information to event #627

Closed
bruno-garcia opened this issue Nov 28, 2020 · 0 comments · Fixed by #1337
Closed

Add runtime memory information to event #627

bruno-garcia opened this issue Nov 28, 2020 · 0 comments · Fixed by #1337
Labels
Feature New feature or request Up-For-Grabs
Milestone

Comments

@bruno-garcia
Copy link
Member

bruno-garcia commented Nov 28, 2020

.NET Core 3.0 added: GetGCMemoryInfo.

There's a post from Maoni on this topic.

GCMemoryInfo includes the following: information

Console.WriteLine($"FragmentedBytes {info.FragmentedBytes}");
Console.WriteLine($"HeapSizeBytes {info.HeapSizeBytes}");
Console.WriteLine($"MemoryLoadBytes {info.MemoryLoadBytes}");
Console.WriteLine($"TotalAvailableMemoryBytes {info.TotalAvailableMemoryBytes}");
Console.WriteLine($"HighMemoryLoadThresholdBytes {info.HighMemoryLoadThresholdBytes}");

For example the output on a simple app that didn't allocate much yet:

FragmentedBytes 0
HeapSizeBytes 0
MemoryLoadBytes 0
TotalAvailableMemoryBytes 34359738368
HighMemoryLoadThresholdBytes 30923764531

We have two sets of data here: Device data and Runtime data.

Add for builds targeting .NET Core 3.0+ (once #623 get merged which adds this TFM) this information to the protocol:

  • Runtime will take FragmentedBytes HeapSizeBytes MemoryLoadBytes

For .NET 5.0 builds there is more information available.
We need to figure out what should be sent out of the box on all events and could be an opt-in.

Sentry's front end can format bytes in a human readable form such as 1 KB, 1 GB.
This needs to be done also in the front end to make sure this readable is usable in Sentry.

Sample code that polls the API on each key hit. Eventually the SDK captures a OutOfMemoryException.

using System;
using System.Collections.Generic;
using Sentry;

static class Program
{
    static void Main()
    {
        using (SentrySdk.Init(o =>
        {
            o.Dsn = "https://80aed643f81249d4bed3e30687b310ab@o447951.ingest.sentry.io/5428537";
            o.Debug = true;
        }))
        {
            var size = 1;
            var strings = new List<string>();
            while (true)
            {
                size *= 10;
                // Assumes the assembly targets .NET Core 3.0 (serves 3.0 and 3.1) and .NET 5
#if NETCOREAPP3_0 || NET5_0
                var info = GC.GetGCMemoryInfo();
                Console.WriteLine($"FragmentedBytes {info.FragmentedBytes}");
                Console.WriteLine($"HeapSizeBytes {info.HeapSizeBytes}");
                Console.WriteLine($"MemoryLoadBytes {info.MemoryLoadBytes}");
                Console.WriteLine($"TotalAvailableMemoryBytes {info.TotalAvailableMemoryBytes}");
                Console.WriteLine($"HighMemoryLoadThresholdBytes {info.HighMemoryLoadThresholdBytes}");
#endif
                // API only available on .NET 5
#if NET5_0
                Console.WriteLine($"Compacted {info.Compacted}");
                Console.WriteLine($"Concurrent {info.Concurrent}");
                Console.WriteLine($"Generation {info.Generation}");
                Console.WriteLine($"Index {info.Index}");
                for (var i = 0; i < info.GenerationInfo.Length; i++)
                {
                    var genInfo = info.GenerationInfo[i];
                    Console.WriteLine($"\tFragmentationAfterBytes[{i}]: {genInfo.FragmentationAfterBytes}");
                    Console.WriteLine($"\tFragmentationBeforeBytes[{i}]: {genInfo.FragmentationBeforeBytes}");
                    Console.WriteLine($"\tSizeAfterBytes[{i}]: {genInfo.SizeAfterBytes}");
                    Console.WriteLine($"\tSizeBeforeBytes[{i}]: {genInfo.SizeBeforeBytes}");
                }
                foreach (var pauseDuration in info.PauseDurations)
                {
                    Console.WriteLine($"\tPauseDurations {pauseDuration}");
                }
                Console.WriteLine($"PromotedBytes {info.PromotedBytes}");
                Console.WriteLine($"FinalizationPendingCount {info.FinalizationPendingCount}");
                Console.WriteLine($"TotalCommittedBytes {info.TotalCommittedBytes}");
                Console.WriteLine($"PinnedObjectsCount {info.PinnedObjectsCount}");
                Console.WriteLine($"PauseTimePercentage {info.PauseTimePercentage}");
#endif

                strings.Add(new string('a', size));
                Console.ReadKey();
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request Up-For-Grabs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants