forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GC committed bytes counter (dotnet#50604)
* Add GC committed bytes counter * Add tests * fix test
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
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> |