Skip to content

Commit

Permalink
Skip CPU time on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Jul 24, 2024
1 parent bebcfaa commit 4f89894
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ static RuntimeMetrics()
description: "The number of processors available to the process.");

private static readonly ObservableCounter<double>? s_processCpuTime =
OperatingSystem.IsBrowser() || OperatingSystem.IsTvOS() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) ?
null :
s_meter.CreateObservableCounter(
"dotnet.process.cpu.time",
GetCpuTime,
unit: "s",
description: "CPU time used by the process.");
OperatingSystem.IsBrowser() || OperatingSystem.IsTvOS() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) ?
null :
s_meter.CreateObservableCounter(
"dotnet.process.cpu.time",
GetCpuTime,
unit: "s",
description: "CPU time used by the process.");

public static bool IsEnabled()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void GcCollectionsCount()
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMobile))]
public void CpuTime()
{
using InstrumentRecorder<double> instrumentRecorder = new("dotnet.process.cpu.time");
Expand All @@ -125,7 +125,7 @@ public void CpuTime()

bool[] foundCpuModes = [false, false];

foreach (Measurement<double> measurement in instrumentRecorder.GetMeasurements().Where(m => m.Value >= 0))
foreach (Measurement<double> measurement in instrumentRecorder.GetMeasurements())
{
var tags = measurement.Tags.ToArray();
var tag = tags.SingleOrDefault(k => k.Key == "cpu.mode");
Expand Down

0 comments on commit 4f89894

Please sign in to comment.