Skip to content

Commit f9dad98

Browse files
Merge branch 'mrtk_development' into vNEXT-EasyManagerAccess
# Conflicts: # Assets/MixedRealityToolkit/_Core/Managers/MixedRealityManager.cs
2 parents f99dff3 + cd20d72 commit f9dad98

File tree

83 files changed

+1741
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1741
-140
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ Assets/ThirdParty/
5454
Assets/ThirdParty.meta
5555
Assets/TextMesh Pro.meta
5656
Assets/TextMesh Pro/
57+
--Version/

Assets/MixedRealityToolkit-SDK/Features/Diagnostics.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
6+
using System.Diagnostics;
7+
8+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
9+
{
10+
internal class CpuUseTracker
11+
{
12+
private TimeSpan? processorTime;
13+
private Process currentProcess = Process.GetCurrentProcess();
14+
private TimeSpan[] readings = new TimeSpan[20];
15+
int index = 0;
16+
17+
public void Reset()
18+
{
19+
processorTime = null;
20+
}
21+
22+
public double GetReadingInMs()
23+
{
24+
if (!processorTime.HasValue)
25+
{
26+
processorTime = currentProcess.TotalProcessorTime;
27+
return 0;
28+
}
29+
30+
var currentTime = currentProcess.TotalProcessorTime;
31+
var diff = currentTime - processorTime.Value;
32+
processorTime = currentTime;
33+
34+
readings[index] = diff;
35+
index = (index + 1) % readings.Length;
36+
37+
return Math.Round(readings.Average(t => t.TotalMilliseconds), 2);
38+
}
39+
}
40+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Boundary;
5+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Diagnostics;
6+
using System;
7+
using System.Text;
8+
using UnityEngine;
9+
10+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
11+
{
12+
/// <summary>
13+
/// Behavior class for showing Diagnostic information. Implements <see cref="IMixedRealityDiagnosticsHandler"/>
14+
/// to manage setting updates.
15+
/// </summary>
16+
public class DiagnosticsHandler : MonoBehaviour, IMixedRealityDiagnosticsHandler
17+
{
18+
private bool showCpu;
19+
private bool ShowCpu
20+
{
21+
get { return showCpu; }
22+
set
23+
{
24+
if (showCpu != value)
25+
{
26+
showCpu = value;
27+
if (!showCpu)
28+
{
29+
cpuUseTracker.Reset();
30+
}
31+
}
32+
}
33+
}
34+
35+
private bool ShowFps { get; set; }
36+
private bool ShowMemory { get; set; }
37+
38+
private bool isShowingInformation;
39+
40+
private CpuUseTracker cpuUseTracker = new CpuUseTracker();
41+
private MemoryUseTracker memoryUseTracker = new MemoryUseTracker();
42+
private FpsUseTracker fpsUseTracker = new FpsUseTracker();
43+
StringBuilder displayText = new StringBuilder();
44+
45+
private GUIStyle style = new GUIStyle()
46+
{
47+
alignment = TextAnchor.UpperLeft,
48+
normal = new GUIStyleState()
49+
{
50+
textColor = new Color(0, 0, 0.5f, 1)
51+
}
52+
};
53+
54+
private Rect rect = new Rect();
55+
56+
/// <summary>
57+
/// Updates the diagnostic settings
58+
/// </summary>
59+
/// <param name="eventData"><see cref="DiagnosticsEventData"/> coming in</param>
60+
public void OnDiagnosticSettingsChanged(DiagnosticsEventData eventData)
61+
{
62+
this.ShowCpu = eventData.ShowCpu;
63+
this.ShowMemory = eventData.ShowMemory;
64+
this.ShowFps = eventData.ShowFps;
65+
this.enabled = eventData.Visible;
66+
}
67+
68+
private void UpdateIsShowingInformation()
69+
{
70+
isShowingInformation = ShowCpu ||
71+
ShowFps ||
72+
ShowMemory;
73+
}
74+
75+
private void Update()
76+
{
77+
UpdateIsShowingInformation();
78+
79+
if (!isShowingInformation)
80+
{
81+
return;
82+
}
83+
84+
displayText.Clear();
85+
86+
if (ShowFps)
87+
{
88+
var timeInSeconds = fpsUseTracker.GetFpsInSeconds();
89+
displayText.AppendLine($"Fps: {Math.Round(1.0f / timeInSeconds, 2)}");
90+
displayText.AppendLine($"Frame Time: {Math.Round(timeInSeconds * 1000, 2)} ms");
91+
}
92+
93+
if (ShowCpu)
94+
{
95+
var reading = cpuUseTracker.GetReadingInMs();
96+
displayText.AppendLine($"CPU Time: {reading} ms");
97+
}
98+
99+
if (ShowMemory)
100+
{
101+
var reading = memoryUseTracker.GetReading();
102+
displayText.AppendLine($"Memory: {Math.Round(BytesToMB(reading.GCMemoryInBytes), 2)} MB");
103+
}
104+
}
105+
106+
private void OnGUI()
107+
{
108+
if (!isShowingInformation || displayText.Length == 0)
109+
{
110+
return;
111+
}
112+
113+
int w = Screen.width, h = Screen.height;
114+
115+
rect.Set(0, 0, w, h * 2 / 100);
116+
117+
style.fontSize = h * 2 / 100;
118+
GUI.Label(rect, displayText.ToString(), style);
119+
}
120+
121+
private static float BytesToMB(long bytes)
122+
{
123+
return bytes / (float)(1024 * 1024);
124+
}
125+
}
126+
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/DiagnosticsHandler.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System.Linq;
5+
using UnityEngine;
6+
7+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
8+
{
9+
internal class FpsUseTracker
10+
{
11+
private int index = 0;
12+
private float[] timings = new float[10];
13+
14+
public float GetFpsInSeconds()
15+
{
16+
timings[index] = Time.unscaledDeltaTime;
17+
index = (index + 1) % timings.Length;
18+
19+
return timings.Average();
20+
}
21+
}
22+
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/FpsUseTracker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
6+
using System.Diagnostics;
7+
8+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
9+
{
10+
internal class MemoryUseTracker
11+
{
12+
private Process currentProcess = Process.GetCurrentProcess();
13+
private readonly MemoryReading[] memoryReadings;
14+
private int index = 0;
15+
16+
private MemoryReading sumReading = new MemoryReading();
17+
18+
public MemoryUseTracker()
19+
{
20+
memoryReadings = new MemoryReading[10];
21+
22+
for (int i = 0; i < memoryReadings.Length; i++)
23+
{
24+
memoryReadings[i] = new MemoryReading();
25+
}
26+
}
27+
28+
29+
public MemoryReading GetReading()
30+
{
31+
var reading = memoryReadings[index];
32+
33+
reading.VirtualMemoryInBytes = currentProcess.VirtualMemorySize64;
34+
reading.WorkingSetMemoryInBytes = currentProcess.WorkingSet64;
35+
reading.GCMemoryInBytes = GC.GetTotalMemory(false);
36+
37+
index = (index + 1) % memoryReadings.Length;
38+
39+
return memoryReadings.Aggregate(sumReading.Reset(), (a, b) => a + b) / memoryReadings.Length;
40+
}
41+
42+
public struct MemoryReading
43+
{
44+
public long VirtualMemoryInBytes { get; set; }
45+
public long WorkingSetMemoryInBytes { get; set; }
46+
public long GCMemoryInBytes { get; set; }
47+
48+
public MemoryReading Reset()
49+
{
50+
VirtualMemoryInBytes = 0;
51+
WorkingSetMemoryInBytes = 0;
52+
GCMemoryInBytes = 0;
53+
54+
return this;
55+
}
56+
57+
public static MemoryReading operator +(MemoryReading a, MemoryReading b)
58+
{
59+
a.VirtualMemoryInBytes += b.VirtualMemoryInBytes;
60+
a.WorkingSetMemoryInBytes += b.WorkingSetMemoryInBytes;
61+
a.GCMemoryInBytes += b.GCMemoryInBytes;
62+
63+
return a;
64+
}
65+
66+
public static MemoryReading operator /(MemoryReading a, int b)
67+
{
68+
a.VirtualMemoryInBytes /= b;
69+
a.WorkingSetMemoryInBytes /= b;
70+
a.GCMemoryInBytes /= b;
71+
72+
return a;
73+
}
74+
}
75+
}
76+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)