Skip to content

Commit

Permalink
Truly Dynamic Event (#2051)
Browse files Browse the repository at this point in the history
* Formatting

* Truly Dynamic Event

* Remove old tuning info

* Rename classes for code review feedback
  • Loading branch information
cshung authored Jul 15, 2024
1 parent d8706f2 commit eeb234e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 361 deletions.
24 changes: 0 additions & 24 deletions src/PerfView/GcStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,30 +481,6 @@ public static void ToXmlAttribs(TextWriter writer, TraceProcess stats, TraceLoad
writer.WriteLine("/>");
}

if (gc.HeapCountTuning != null || gc.HeapCountSample != null)
{
writer.Write(" <DynamicData");
if (gc.HeapCountTuning != null)
{
writer.Write(" NewHeapCount={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.NewHeapCount.ToString("n0"), 10));
writer.Write(" MedianThroughputCostPercent={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.MedianThroughputCostPercent.ToString("n3"), 10));
writer.Write(" SmoothedMedianThroughputCostPercent={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.SmoothedMedianThroughputCostPercent.ToString("n3"), 10));
writer.Write(" ThroughputCostPercentReductionPerStepUp={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.ThroughputCostPercentReductionPerStepUp.ToString("n3"), 10));
writer.Write(" ThroughputCostPercentIncreasePerStepDown={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.ThroughputCostPercentIncreasePerStepDown.ToString("n3"), 10));
writer.Write(" SpaceCostPercentIncreasePerStepUp={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.SpaceCostPercentIncreasePerStepUp.ToString("n3"), 10));
writer.Write(" SpaceCostPercentDecreasePerStepDown={0}", StringUtilities.QuotePadLeft(gc.HeapCountTuning.SpaceCostPercentDecreasePerStepDown.ToString("n3"), 10));
}

if (gc.HeapCountSample != null)
{
writer.Write(" ElapsedTimeBetweenGCsMSec={0}", StringUtilities.QuotePadLeft(gc.HeapCountSample.ElapsedTimeBetweenGCsMSec.ToString("n3"), 10));
writer.Write(" GCPauseTimeMSec={0}", StringUtilities.QuotePadLeft(gc.HeapCountSample.GCPauseTimeMSec.ToString("n3"), 10));
writer.Write(" MslWaitTimeMSec={0}", StringUtilities.QuotePadLeft(gc.HeapCountSample.MslWaitTimeMSec.ToString("n3"), 10));
}

writer.WriteLine("/>");
}

if (gc.HeapStats != null)
{
writer.Write(" <HeapStats");
Expand Down
81 changes: 31 additions & 50 deletions src/TraceEvent/Computers/TraceManagedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in.
// It is available from http://www.codeplex.com/hyperAddin
// using Microsoft.Diagnostics.Tracing.Parsers;

using Microsoft.Diagnostics.Tracing.Analysis.GC;
using Microsoft.Diagnostics.Tracing.Analysis.JIT;
using Microsoft.Diagnostics.Tracing.Etlx;
Expand Down Expand Up @@ -874,16 +874,10 @@ internal static void SetupCallbacks(TraceEventDispatcher source)
GCStats.ProcessCommittedUsage(stats, committedUsage);
};

source.Clr.GCDynamicEvent.GCHeapCountTuning += delegate (HeapCountTuningTraceEvent heapCountTuning)
{
var stats = currentManagedProcess(heapCountTuning.UnderlyingEvent);
GCStats.ProcessHeapCountTuning(stats, heapCountTuning);
};

source.Clr.GCDynamicEvent.GCHeapCountSample += delegate (HeapCountSampleTraceEvent heapCountSample)
source.Clr.GCDynamicEvent.GCDynamicTraceEvent += delegate (GCDynamicTraceEvent gcDynamic)
{
var stats = currentManagedProcess(heapCountSample.UnderlyingEvent);
GCStats.ProcessHeapCountSample(stats, heapCountSample);
var stats = currentManagedProcess(gcDynamic.UnderlyingEvent);
GCStats.ProcessGCDynamicEvent(stats, gcDynamic);
};

source.Clr.GCGlobalHeapHistory += delegate (GCGlobalHeapHistoryTraceData data)
Expand Down Expand Up @@ -2143,8 +2137,6 @@ public double PromotedMB
}
}

public HeapCountTuning HeapCountTuning { get; internal set; }
public HeapCountSample HeapCountSample { get; internal set; }
public CommittedUsage CommittedUsageBefore { get; internal set; }
public CommittedUsage CommittedUsageAfter { get; internal set; }

Expand Down Expand Up @@ -2416,7 +2408,7 @@ public GCCondemnedReasons[] PerHeapCondemnedReasons
}

public enum TimingType
{
{
/// <summary>
/// This field records the time spent for marking roots (except objects pointed by sizedref handle and their descendents)
///
Expand Down Expand Up @@ -2522,7 +2514,8 @@ public int FindFirstHighestCondemnedHeap()
if (gen == GenNumberHighest)
{
return HeapIndex;
} }
}
}

return 0;
}
Expand Down Expand Up @@ -3328,6 +3321,18 @@ public PinnedPlug(ulong s, ulong e)

private float[] GCCpuServerGCThreads = null;

private List<GCDynamicEvent> dynamicEvents = new List<GCDynamicEvent>();

public List<GCDynamicEvent> DynamicEvents
{
get { return this.dynamicEvents; }
}

internal void AddDynamicEvent(GCDynamicEvent dynamicEvent)
{
dynamicEvents.Add(dynamicEvent);
}

#endregion
}

Expand Down Expand Up @@ -4933,12 +4938,12 @@ internal static void ProcessCommittedUsage(TraceLoadedDotNetRuntime proc, Commit
{
CommittedUsage traceData = new CommittedUsage
{
Version = committedUsage.Version,
TotalCommittedInUse = committedUsage.TotalCommittedInUse,
Version = committedUsage.Version,
TotalCommittedInUse = committedUsage.TotalCommittedInUse,
TotalCommittedInGlobalDecommit = committedUsage.TotalCommittedInGlobalDecommit,
TotalCommittedInFree = committedUsage.TotalCommittedInFree,
TotalCommittedInGlobalFree = committedUsage.TotalCommittedInGlobalFree,
TotalBookkeepingCommitted = committedUsage.TotalBookkeepingCommitted
TotalCommittedInFree = committedUsage.TotalCommittedInFree,
TotalCommittedInGlobalFree = committedUsage.TotalCommittedInGlobalFree,
TotalBookkeepingCommitted = committedUsage.TotalBookkeepingCommitted
};

if (_event.CommittedUsageBefore == null)
Expand All @@ -4953,41 +4958,17 @@ internal static void ProcessCommittedUsage(TraceLoadedDotNetRuntime proc, Commit
}
}

internal static void ProcessHeapCountTuning(TraceLoadedDotNetRuntime proc, HeapCountTuningTraceEvent heapCountTuning)
{
TraceGC _event = GetGC(proc, heapCountTuning.GCIndex);
if (_event != null)
{
// Copy over the contents of the dynamic data to prevent issues when the event is reused.
_event.HeapCountTuning = new HeapCountTuning
{
Version = heapCountTuning.Version,
NewHeapCount = heapCountTuning.NewHeapCount,
GCIndex = heapCountTuning.GCIndex,
MedianThroughputCostPercent = heapCountTuning.MedianThroughputCostPercent,
SmoothedMedianThroughputCostPercent = heapCountTuning.SmoothedMedianThroughputCostPercent,
ThroughputCostPercentReductionPerStepUp = heapCountTuning.ThroughputCostPercentReductionPerStepUp,
ThroughputCostPercentIncreasePerStepDown = heapCountTuning.ThroughputCostPercentIncreasePerStepDown,
SpaceCostPercentIncreasePerStepUp = heapCountTuning.SpaceCostPercentIncreasePerStepUp,
SpaceCostPercentDecreasePerStepDown = heapCountTuning.SpaceCostPercentDecreasePerStepDown
};
}
}

internal static void ProcessHeapCountSample(TraceLoadedDotNetRuntime proc, HeapCountSampleTraceEvent heapCountSample)
internal static void ProcessGCDynamicEvent(TraceLoadedDotNetRuntime proc, GCDynamicTraceEvent gcDynamic)
{
TraceGC _event = GetLastGC(proc);
if (_event != null)
{
_event.HeapCountSample = new HeapCountSample
{
Version = heapCountSample.Version,
GCIndex = heapCountSample.GCIndex,
// Convert the microsecond properties to MSec to be consistent with the other time based metrics.
ElapsedTimeBetweenGCsMSec = heapCountSample.ElapsedTimeBetweenGCs / 1000.0,
GCPauseTimeMSec = heapCountSample.GCPauseTime / 1000.0,
MslWaitTimeMSec = heapCountSample.MslWaitTime / 1000.0
};
_event.AddDynamicEvent(new GCDynamicEvent
(
gcDynamic.UnderlyingEvent.Name,
gcDynamic.UnderlyingEvent.TimeStamp,
gcDynamic.DataField
));
}
}

Expand Down
Loading

0 comments on commit eeb234e

Please sign in to comment.