microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Diagnostics Profiler shows 2048 Mb available when system has more #5904

Closed erhavir closed 5 years ago

erhavir commented 5 years ago

Overview

The Profiler shows a max memory of 2048 Mb on HoloLens 2. I just went over that (2.6 Gb) and the blue line went off the edge of the profiler. 2048 Mb was also the noted limit in the profiler. it does show a higher limit when I run the project on my PC.

Noted in the device portal, Available is 2048 Mb. However, it's nearly double that for total, and I am using more than Available.

Expected Behavior

The Profiler should show the actual top limit of memory available on the system.

Actual Behavior

The Profiler shows less than the available memory on the system.

Steps to reproduce

  1. Load a scene on HoloLens 2 with the Profiler visible.
  2. Load the System Performance in the Windows Device Portal.
  3. Compare.

Unity Editor Version

2018.4.1.8f1

Mixed Reality Toolkit Release Version

MRTK 2.0.0

erhavir commented 5 years ago

Sorry. I made a mistake above. For instance, when I was using 2.4 Gb, 1.4 Gb was available and the total was 3.8 Gb. None of the values in Device Portal showed 2 Gb, while 2048.0 Mb was shown as the limit.

wiwei commented 5 years ago

Note that the diagnostic tools use the unity SystemInfo.systemMemorySize API, which are documented to not work on UWP. On UWP it uses AppMemoryUsageLimit, which is a sandboxed version of memory information (i.e. we report what the system reports.

This is a limitation of the UWP platform itself - the app can only show what it is told its limits are, as it isn't told anything about the overall system.

https://social.msdn.microsoft.com/Forums/Windows/en-US/b652afb8-a04c-4741-99af-a7a8601f025e/uwp-get-total-disk-space-current-ram-total-ram-of-system-in-uwp-application?forum=wpdevelop

@erhavir, do you think it would be better in this case to NOT show the upper limit (i.e. just show current usage?)

erhavir commented 5 years ago

I think showing usage is helpful. It sure helped me when I was hitting against upper limits. Since there are MRTK profiles for HoloLens 1 and HoloLens 2, do you think we could make that upper limit a part of the profile since the memory limits are fixed and we know what they are? In the case of other platforms, such as running on PC in editor or on other MR devices that wouldn't be possible. Do we know the end-point that they are on when displaying the panel?

wiwei commented 5 years ago

We don't actually know the end point when things are running on device (there are numerous threads internal and external about why UWP doesn't allow for this, so it's not worth going down that rabbit hole).

However, the concept of having an "override" for a particular platform (i.e. a hololens1visualprofile.asset) which hardcodes the memory on device seems reasonable.

For other UWP (i.e. VR) applications we'd still be stuck with the current 2048 number or whatever the system reports.

Troy-Ferrell commented 5 years ago

FYI @Cameron-Micka since he built the visual profiler

Cameron-Micka commented 5 years ago

Hey @erhavir, if you look at how the Visual Profiler calculates the maximum memory it uses the method @wiwei mentions above: https://github.com/microsoft/VisualProfiler-Unity/blob/master/VisualProfiler.cs#L698 I'm curious how you were able to go above this limit? Usually when I see Unity apps go above that threshold they crash due to unhandled out of memory exceptions. I would be hesitant to hardcode memory size into MRTK profiles since nothing stops users from using them on other platforms.

It would be interesting to see what Unity's SystemInfo.systemMemorySize returns in UWP apps?

wiwei commented 5 years ago

@Cameron-Micka I think on UWP apps it will:

Windows Store Apps: This function is not supported on Windows Store Apps and will always return 0.

Per https://docs.unity3d.com/ScriptReference/SystemInfo-systemMemorySize.html

Cameron-Micka commented 5 years ago

Ah, I didn't catch that! That must be why I added a special case for UWP. Do we know from the platform team if there is a more appropriate method to use if this one is reporting an inaccurate ammount?

wiwei commented 5 years ago

I think that this is the only API we can use.

AFAIK the platform intentionally doesn't expose the underlying system RAM information so as to not leak information about the system.

Another idea may just be to say "App Limit" instead of "Limit" to be clear it's the limit for the app. I don't know if we should really go down a path of working around underlying system APIs for querying system memory.

Cameron-Micka commented 5 years ago

Sounds good to me, seems like we should report this issue to the platform team because as a developer I would assume: MemoryManager.AppMemoryUsage is always <= MemoryManager.AppMemoryUsageLimit