From bbd4db307395e8366ed316563881eaf3de6e356c Mon Sep 17 00:00:00 2001 From: Tim Macintyre <103250605+timmac-qmc@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:06:43 +0100 Subject: [PATCH 1/4] Catch process.TotalProcessorTime exception process.TotalProcessorTime is not supported on all platforms --- Backtrace/Model/JsonData/BacktraceAttributes.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Backtrace/Model/JsonData/BacktraceAttributes.cs b/Backtrace/Model/JsonData/BacktraceAttributes.cs index a6ea306..abcc5bf 100644 --- a/Backtrace/Model/JsonData/BacktraceAttributes.cs +++ b/Backtrace/Model/JsonData/BacktraceAttributes.cs @@ -232,15 +232,16 @@ 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) - { - Attributes["process.age"] = totalProcessAge; - } 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; + } + Attributes["cpu.process.count"] = Process.GetProcesses().Count(); //Resident memory usage. @@ -275,7 +276,7 @@ private void SetProcessAttributes() Attributes["vm.vma.peak"] = peakVirtualMemorySize; } } - catch (PlatformNotSupportedException) + catch (NotSupportedException) { Trace.TraceWarning($"Cannot retrieve information about process memory - platform not supported"); } From d7a8158364a9dfcb8b1e47afdce760ad3aba4d60 Mon Sep 17 00:00:00 2001 From: Tim Macintyre <103250605+timmac-qmc@users.noreply.github.com> Date: Tue, 10 Sep 2024 09:33:52 +0100 Subject: [PATCH 2/4] Update Backtrace/Model/JsonData/BacktraceAttributes.cs Co-authored-by: Sebastian Alex --- Backtrace/Model/JsonData/BacktraceAttributes.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Backtrace/Model/JsonData/BacktraceAttributes.cs b/Backtrace/Model/JsonData/BacktraceAttributes.cs index abcc5bf..ad8084f 100644 --- a/Backtrace/Model/JsonData/BacktraceAttributes.cs +++ b/Backtrace/Model/JsonData/BacktraceAttributes.cs @@ -241,7 +241,14 @@ private void SetProcessAttributes() { Attributes["process.age"] = totalProcessAge; } + } + catch (NotSupportedException) + { + Trace.TraceWarning($"Cannot retrieve process age - TotalProcessorTime is not supported"); + } + try + { Attributes["cpu.process.count"] = Process.GetProcesses().Count(); //Resident memory usage. From aa60a22b759b24a39454af970d94530f30011e5f Mon Sep 17 00:00:00 2001 From: Tim Macintyre <103250605+timmac-qmc@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:50:55 +0100 Subject: [PATCH 3/4] Fix formatting --- Backtrace/Model/JsonData/BacktraceAttributes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Backtrace/Model/JsonData/BacktraceAttributes.cs b/Backtrace/Model/JsonData/BacktraceAttributes.cs index ad8084f..0c7a3ed 100644 --- a/Backtrace/Model/JsonData/BacktraceAttributes.cs +++ b/Backtrace/Model/JsonData/BacktraceAttributes.cs @@ -246,7 +246,7 @@ private void SetProcessAttributes() { Trace.TraceWarning($"Cannot retrieve process age - TotalProcessorTime is not supported"); } - + try { Attributes["cpu.process.count"] = Process.GetProcesses().Count(); From cc058c6986c18b56a765ad4929f9942d33381de6 Mon Sep 17 00:00:00 2001 From: Tim Macintyre <103250605+timmac-qmc@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:20:29 +0100 Subject: [PATCH 4/4] Update BacktraceAttributes.cs Remove whitespace (that's not even an issue...) --- Backtrace/Model/JsonData/BacktraceAttributes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Backtrace/Model/JsonData/BacktraceAttributes.cs b/Backtrace/Model/JsonData/BacktraceAttributes.cs index 0c7a3ed..72eedac 100644 --- a/Backtrace/Model/JsonData/BacktraceAttributes.cs +++ b/Backtrace/Model/JsonData/BacktraceAttributes.cs @@ -248,7 +248,7 @@ private void SetProcessAttributes() } try - { + { Attributes["cpu.process.count"] = Process.GetProcesses().Count(); //Resident memory usage.