Skip to content

Commit 0066ca7

Browse files
authored
Fix error autodetection (#69)
* Fix error autodetection * Fix error autodetection
1 parent 8007706 commit 0066ca7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Profiler/Trace-Script.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ function Trace-Script {
172172
$ticks = if (0 -ne $total.Ticks) { $total.Ticks } else { 1 }
173173
$line.Percent = [Math]::Round($line.Duration.Ticks / $ticks, 5, [System.MidpointRounding]::AwayFromZero) * 100
174174
$line.SelfPercent = [Math]::Round($line.SelfDuration.Ticks / $ticks, 5, [System.MidpointRounding]::AwayFromZero) * 100
175-
$line.MemoryPercent = [Math]::Round($line.Memory / $totalMem, 5, [System.MidpointRounding]::AwayFromZero) * 100
176-
$line.SelfMemoryPercent = [Math]::Round($line.SelfMemory / $totalMem, 5, [System.MidpointRounding]::AwayFromZero) * 100
175+
$line.MemoryPercent = if (0 -ne $totalMem) { [Math]::Round($line.Memory / $totalMem, 5, [System.MidpointRounding]::AwayFromZero) * 100 } else { 100 }
176+
$line.SelfMemoryPercent = if (0 -ne $totalMem) { [Math]::Round($line.SelfMemory / $totalMem, 5, [System.MidpointRounding]::AwayFromZero) * 100 } else { 100 }
177177
$line
178178
}
179179
Write-TimeAndRestart $sw

csharp/Profiler/Tracer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ private static bool HasDifferentTracer(ITracer currentTracer, object newTracer)
7474
private static void EnsureTracingWasNotCorrupted()
7575
{
7676
// Code like Set-PSDebug -Trace 0, or Get-PSBreakPoint | Remove-PSBreakPoint will break the tracing, and we will lose data,
77-
// the only line that is allowed to do that is $corruptionAutodetectionVariable = Set-PsDebug -Trace 0
77+
// the only line that is allowed to do that is $corruptionAutodetectionVariable = Set-PSDebug -Trace 0
7878
// This line should be the second to last line that was executed. We re-enable the trace in Profiler, so the last line (::Unregister or ::Unpatch) is
7979
// captured even when tracing is broken by user.
80-
var corrupted = LastTraceItem.Extent?.Text != null && LastTraceItem.Extent.Text != "$corruptionAutodetectionVariable = Set-PsDebug -Trace 0";
80+
const string autodetectionText = "$corruptionAutodetectionVariable = Set-PSDebug -Trace 0";
81+
var corrupted = LastTraceItem.Extent?.Text != null && !LastTraceItem.Extent.Text.Equals(autodetectionText, StringComparison.OrdinalIgnoreCase);
8182
if (corrupted)
8283
{
8384
throw new InvalidOperationException($"Trace was broken by: {LastTraceItem.Extent.Text} from {LastTraceItem.Extent.File}:{LastTraceItem.Extent.StartLineNumber}");

0 commit comments

Comments
 (0)