Skip to content

Commit

Permalink
Merge pull request #44 from timmac-qmc/patch-1
Browse files Browse the repository at this point in the history
Catch process.TotalProcessorTime exception
  • Loading branch information
perf2711 authored Sep 24, 2024
2 parents 60fd847 + cc058c6 commit 8b34165
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Backtrace/Model/JsonData/BacktraceAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,21 @@ private void SetProcessAttributes()
{
return;
}
//How long the application has been running in secounds
var processAge = Math.Round(process.TotalProcessorTime.TotalSeconds);
var totalProcessAge = unchecked((long)processAge);
if (totalProcessAge > 0)
try
{
//How long the application has been running in secounds
var processAge = Math.Round(process.TotalProcessorTime.TotalSeconds);
var totalProcessAge = unchecked((long)processAge);
if (totalProcessAge > 0)
{
Attributes["process.age"] = totalProcessAge;
}
}
catch (NotSupportedException)
{
Attributes["process.age"] = totalProcessAge;
Trace.TraceWarning($"Cannot retrieve process age - TotalProcessorTime is not supported");
}

try
{
Attributes["cpu.process.count"] = Process.GetProcesses().Count();
Expand Down Expand Up @@ -275,7 +283,7 @@ private void SetProcessAttributes()
Attributes["vm.vma.peak"] = peakVirtualMemorySize;
}
}
catch (PlatformNotSupportedException)
catch (NotSupportedException)
{
Trace.TraceWarning($"Cannot retrieve information about process memory - platform not supported");
}
Expand Down

0 comments on commit 8b34165

Please sign in to comment.