Skip to content

Commit 9fc2955

Browse files
author
David Kline
authored
Merge pull request #2906 from ryzngard/ryzng/uwp_process_fix
Fix dotnet runtime for UWP
2 parents 637c1ba + bab5498 commit 9fc2955

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/CpuUseTracker.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
1010
internal class CpuUseTracker
1111
{
1212
private TimeSpan? processorTime;
13-
private Process currentProcess = Process.GetCurrentProcess();
1413
private TimeSpan[] readings = new TimeSpan[20];
15-
int index = 0;
14+
private int index = 0;
15+
16+
#if !WINDOWS_UWP || ENABLE_IL2CPP
17+
private Process currentProcess = Process.GetCurrentProcess();
18+
#endif
1619

1720
public void Reset()
1821
{
@@ -21,6 +24,10 @@ public void Reset()
2124

2225
public double GetReadingInMs()
2326
{
27+
#if WINDOWS_UWP && !ENABLE_IL2CPP
28+
// UWP doesn't support process with dotnet runtime, so we can't get CPU readings with the current pattern.
29+
return -1;
30+
#else
2431
if (!processorTime.HasValue)
2532
{
2633
processorTime = currentProcess.TotalProcessorTime;
@@ -35,6 +42,7 @@ public double GetReadingInMs()
3542
index = (index + 1) % readings.Length;
3643

3744
return Math.Round(readings.Average(t => t.TotalMilliseconds), 2);
45+
#endif
3846
}
3947
}
4048
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/MemoryUseTracker.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
99
{
1010
internal class MemoryUseTracker
1111
{
12-
private Process currentProcess = Process.GetCurrentProcess();
1312
private readonly MemoryReading[] memoryReadings;
1413
private int index = 0;
1514

@@ -29,9 +28,6 @@ public MemoryUseTracker()
2928
public MemoryReading GetReading()
3029
{
3130
var reading = memoryReadings[index];
32-
33-
reading.VirtualMemoryInBytes = currentProcess.VirtualMemorySize64;
34-
reading.WorkingSetMemoryInBytes = currentProcess.WorkingSet64;
3531
reading.GCMemoryInBytes = GC.GetTotalMemory(false);
3632

3733
index = (index + 1) % memoryReadings.Length;
@@ -41,32 +37,24 @@ public MemoryReading GetReading()
4137

4238
public struct MemoryReading
4339
{
44-
public long VirtualMemoryInBytes { get; set; }
45-
public long WorkingSetMemoryInBytes { get; set; }
4640
public long GCMemoryInBytes { get; set; }
4741

4842
public MemoryReading Reset()
4943
{
50-
VirtualMemoryInBytes = 0;
51-
WorkingSetMemoryInBytes = 0;
5244
GCMemoryInBytes = 0;
5345

5446
return this;
5547
}
5648

5749
public static MemoryReading operator +(MemoryReading a, MemoryReading b)
5850
{
59-
a.VirtualMemoryInBytes += b.VirtualMemoryInBytes;
60-
a.WorkingSetMemoryInBytes += b.WorkingSetMemoryInBytes;
6151
a.GCMemoryInBytes += b.GCMemoryInBytes;
6252

6353
return a;
6454
}
6555

6656
public static MemoryReading operator /(MemoryReading a, int b)
6757
{
68-
a.VirtualMemoryInBytes /= b;
69-
a.WorkingSetMemoryInBytes /= b;
7058
a.GCMemoryInBytes /= b;
7159

7260
return a;

0 commit comments

Comments
 (0)