Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add event to RuntimeEventSource for AppContext switches
Fixes #56142
  • Loading branch information
agocke authored and github-actions committed Aug 20, 2021
commit ec11694beb11c38896a448a8c9774ac1f69e576a
17 changes: 17 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ public static void SetSwitch(string switchName, bool isEnabled)
}
}

internal static void LogSwitchValues(RuntimeEventSource ev)
{
if (s_switches is null)
{
return;
}

lock (s_switches)
{
foreach (var (k, v) in s_switches)
{
// Convert bool to int because it's cheaper to log (no boxing)
ev.LogAppContextSwitch(k, v ? 0 : 1);
}
}
}

#if !CORERT
internal static unsafe void Setup(char** pNames, char** pValues, int count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public static void Initialize()
// as you can't make a constructor partial.
private RuntimeEventSource(int _) { }

[Event(2, Level = EventLevel.Informational)]
internal void LogAppContextSwitch(string switchName, int value)
{
base.WriteEvent(2, switchName, value);
}

protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable)
Expand Down Expand Up @@ -87,6 +93,8 @@ protected override void OnEventCommand(EventCommandEventArgs command)
_ilBytesJittedCounter ??= new PollingCounter("il-bytes-jitted", this, () => System.Runtime.JitInfo.GetCompiledILBytes()) { DisplayName = "IL Bytes Jitted", DisplayUnits = "B" };
_methodsJittedCounter ??= new PollingCounter("methods-jitted-count", this, () => System.Runtime.JitInfo.GetCompiledMethodCount()) { DisplayName = "Number of Methods Jitted" };
_jitTimeCounter ??= new IncrementingPollingCounter("time-in-jit", this, () => System.Runtime.JitInfo.GetCompilationTime().TotalMilliseconds) { DisplayName = "Time spent in JIT", DisplayUnits = "ms", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };

AppContext.LogSwitchValues(this);
}

}
Expand Down