-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 GC committed bytes counter #50604
Merged
sywhang
merged 3 commits into
dotnet:main
from
sywhang:dev/suwhang/add-committed-size-counter
Apr 3, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#if USE_MDT_EVENTSOURCE | ||
using Microsoft.Diagnostics.Tracing; | ||
#else | ||
using System.Diagnostics.Tracing; | ||
#endif | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Diagnostics; | ||
|
||
namespace RuntimeEventCounterTests | ||
{ | ||
public class RuntimeCounterListener : EventListener | ||
{ | ||
public RuntimeCounterListener() | ||
{ | ||
observedRuntimeCounters = new Dictionary<string, bool>() { | ||
{ "cpu-usage" , false }, | ||
{ "working-set", false }, | ||
{ "gc-heap-size", false }, | ||
{ "gen-0-gc-count", false }, | ||
{ "gen-1-gc-count", false }, | ||
{ "gen-2-gc-count", false }, | ||
{ "threadpool-thread-count", false }, | ||
{ "monitor-lock-contention-count", false }, | ||
{ "threadpool-queue-length", false }, | ||
{ "threadpool-completed-items-count", false }, | ||
{ "alloc-rate", false }, | ||
{ "active-timer-count", false }, | ||
{ "gc-fragmentation", false }, | ||
{ "gc-committed", false }, | ||
{ "exception-count", false }, | ||
{ "time-in-gc", false }, | ||
{ "gen-0-size", false }, | ||
{ "gen-1-size", false }, | ||
{ "gen-2-size", false }, | ||
{ "loh-size", false }, | ||
{ "poh-size", false }, | ||
{ "assembly-count", false }, | ||
{ "il-bytes-jitted", false }, | ||
{ "methods-jitted-count", false } | ||
}; | ||
} | ||
private Dictionary<string, bool> observedRuntimeCounters; | ||
|
||
protected override void OnEventSourceCreated(EventSource source) | ||
{ | ||
if (source.Name.Equals("System.Runtime")) | ||
{ | ||
Dictionary<string, string> refreshInterval = new Dictionary<string, string>(); | ||
refreshInterval.Add("EventCounterIntervalSec", "1"); | ||
EnableEvents(source, EventLevel.Informational, (EventKeywords)(-1), refreshInterval); | ||
} | ||
} | ||
|
||
protected override void OnEventWritten(EventWrittenEventArgs eventData) | ||
{ | ||
|
||
for (int i = 0; i < eventData.Payload.Count; i++) | ||
{ | ||
IDictionary<string, object> eventPayload = eventData.Payload[i] as IDictionary<string, object>; | ||
if (eventPayload != null) | ||
{ | ||
foreach (KeyValuePair<string, object> payload in eventPayload) | ||
{ | ||
if (payload.Key.Equals("Name")) | ||
observedRuntimeCounters[payload.Value.ToString()] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public bool Verify() | ||
{ | ||
foreach (string counterName in observedRuntimeCounters.Keys) | ||
{ | ||
if (!observedRuntimeCounters[counterName]) | ||
{ | ||
Console.WriteLine($"Did not see {counterName}"); | ||
return false; | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Saw {counterName}"); | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
public partial class TestRuntimeEventCounter | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
// Create an EventListener. | ||
using (RuntimeCounterListener myListener = new RuntimeCounterListener()) | ||
{ | ||
Thread.Sleep(3000); | ||
if (myListener.Verify()) | ||
{ | ||
Console.WriteLine("Test passed"); | ||
return 100; | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Test Failed - did not see one or more of the expected runtime counters."); | ||
return 1; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestKind>BuildAndRun</CLRTestKind> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
<GCStressIncompatible>true</GCStressIncompatible> | ||
<!-- This test is timing sensitive and JIT timing affects the results of the test --> | ||
<JitOptimizationSensitive>true</JitOptimizationSensitive> | ||
<!-- This test has a secondary thread with an infinite loop --> | ||
<UnloadabilityIncompatible>true</UnloadabilityIncompatible> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="runtimecounters.cs" /> | ||
<ProjectReference Include="../common/common.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it seems like we could easily avoid calling GC.GetGCMemoryInfo again if we already had to call it to get the info for the counter right above...
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.
It's inside the lambda. Might be nice if there were some kind of facility for enabling all counters associated with the same event source to be handed the results of some shared computation, e.g. so that prior to invoking both gc-fragmentation and gc-committed, it could do a single GetGCMemoryInfo call that both would then be handed.
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.
Yes, this gets passed as a lambda and is executed by the CounterGroup. It would be nice to add what @stephentoub suggested so that counters within the same provider can share some state. I'll look into adding that in the future.
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.
sounds good, thanks @stephentoub and @sywhang.