Skip to content

Commit

Permalink
Close target perf counters when the targetprocess exits (#2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
zadesai authored May 17, 2024
1 parent 70595ee commit 7830239
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tools/PI/DevHome.PI/Models/PerfCounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ private void TargetApp_PropertyChanged(object? sender, PropertyChangedEventArgs
if (e.PropertyName == nameof(TargetAppData.TargetProcess))
{
ThreadPool.QueueUserWorkItem((o) => UpdateTargetProcess(TargetAppData.Instance.TargetProcess));
}
else if (e.PropertyName == nameof(TargetAppData.HasExited))
{
CloseTargetCounters();
}
}

Expand Down Expand Up @@ -130,15 +134,26 @@ public void Stop()
private void CloseTargetCounters()
{
cpuCounter?.Close();
cpuCounter?.Dispose();
cpuCounter = null;
ramCounter?.Close();
ramCounter?.Dispose();
ramCounter = null;

foreach (var counter in gpuCounters ?? Enumerable.Empty<PerformanceCounter>())
{
counter.Close();
}
counter.Dispose();
}

gpuCounters?.Clear();

readCounter?.Close();
readCounter?.Dispose();
readCounter = null;
writeCounter?.Close();
writeCounter?.Dispose();
writeCounter = null;
}

public static List<PerformanceCounter> GetGpuCounters(int pid)
Expand Down

0 comments on commit 7830239

Please sign in to comment.