From 8cefa8e11686038bb3249b4ad4a5a435a8644936 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Sat, 14 Dec 2024 11:26:04 +0000 Subject: [PATCH 1/8] Do not use "#" in build names See https://github.com/icosa-foundation/open-brush/pull/796 [CI BUILD] --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d22599a7..8d42a864 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -148,7 +148,7 @@ jobs: else if [[ ${{ github.ref }} == refs/pull/* ]] then - DESCRIPTION="PR#$(echo ${{ github.ref }} | sed -e 's#refs/pull/##' -e 's#/merge##')" + DESCRIPTION="PR$(echo ${{ github.ref }} | sed -e 's#refs/pull/##' -e 's#/merge##')" elif [[ ${{ github.ref }} == refs/heads/* ]] then DESCRIPTION="$(echo ${{ github.ref }} | sed -e 's#refs/heads/##')" From f752474227d9823f39f654cb020197a86ebc0afc Mon Sep 17 00:00:00 2001 From: Klara Date: Mon, 16 Dec 2024 18:53:01 +0000 Subject: [PATCH 2/8] Destroy MeshCycler meshes when opening new model --- Assets/Scripts/model/main/PeltzerMain.cs | 2 ++ .../Scripts/tools/utils/HighlightStyles/MeshCycler.cs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Assets/Scripts/model/main/PeltzerMain.cs b/Assets/Scripts/model/main/PeltzerMain.cs index 3f91f076..c8cb7b31 100644 --- a/Assets/Scripts/model/main/PeltzerMain.cs +++ b/Assets/Scripts/model/main/PeltzerMain.cs @@ -1550,6 +1550,8 @@ public void CreateNewModel(bool clearReferenceImages = true, bool resetAttention zoomer.ClearState(); model.Clear(worldSpace); volumeInserter.ClearState(); + MeshCycler.DestroyMeshes(); + spatialIndex.Reset(DEFAULT_BOUNDS); if (resetAttentionCaller) { diff --git a/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs b/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs index b9a11379..14560190 100644 --- a/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs +++ b/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs @@ -86,5 +86,15 @@ public static void ResetCycler() } meshDict.Clear(); } + + public static void DestroyMeshes() + { + ResetCycler(); + foreach (Mesh mesh in meshPool) + { + Object.Destroy(mesh); + } + meshPool.Clear(); + } } } From 5d17be01ae64d4b22e91631db377a9b2fbfa4704 Mon Sep 17 00:00:00 2001 From: Klara Date: Mon, 16 Dec 2024 19:13:02 +0000 Subject: [PATCH 3/8] Destroy meshes in Remesher on Clear --- Assets/Scripts/model/render/ReMesher.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/model/render/ReMesher.cs b/Assets/Scripts/model/render/ReMesher.cs index 836fc2b6..85558645 100644 --- a/Assets/Scripts/model/render/ReMesher.cs +++ b/Assets/Scripts/model/render/ReMesher.cs @@ -19,6 +19,8 @@ using com.google.apps.peltzer.client.model.core; using com.google.apps.peltzer.client.model.util; using com.google.apps.peltzer.client.model.main; +using UnityEditor; +using Object = UnityEngine.Object; namespace com.google.apps.peltzer.client.model.render { @@ -342,8 +344,14 @@ public static void InitBufferCaches() public void Clear() { - meshInfosByMaterial.Clear(); + foreach (var meshInfo in allMeshInfos) + { + Object.Destroy(meshInfo.mesh); + Object.Destroy(meshInfo.materialAndColor.material); + } allMeshInfos.Clear(); + meshInfosByMaterial.Clear(); + meshInfosByMesh.Clear(); meshesPendingAdd.Clear(); meshesPendingRemove.Clear(); meshInfosPendingRegeneration.Clear(); From 02f698359d22a8e09ad2d00c50392883d2faab43 Mon Sep 17 00:00:00 2001 From: Klara Date: Mon, 16 Dec 2024 19:15:32 +0000 Subject: [PATCH 4/8] Destroy meshes before remeshing --- Assets/Scripts/model/render/MeshHelper.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Assets/Scripts/model/render/MeshHelper.cs b/Assets/Scripts/model/render/MeshHelper.cs index e6c54f7d..30f17413 100644 --- a/Assets/Scripts/model/render/MeshHelper.cs +++ b/Assets/Scripts/model/render/MeshHelper.cs @@ -21,6 +21,7 @@ using com.google.apps.peltzer.client.model.import; using com.google.apps.peltzer.client.model.main; using com.google.apps.peltzer.client.model.util; +using Object = System.Object; namespace com.google.apps.peltzer.client.model.render { @@ -165,6 +166,11 @@ public static void UpdateMeshes(MMesh updatedMesh, List existi newPos.Count != uMesh.mesh.vertices.Count()) { // If materials changed, easiest action is to remesh everything. + foreach (var mm in existing) + { + UnityEngine.Object.Destroy(mm.mesh); + UnityEngine.Object.Destroy(mm.materialAndColor.material); + } existing.Clear(); // This method is used to update a GameObject, and as such we do not want the vert positions in model space, // it is the gameObject that will be placed and rotated in the world. From 716dd0b5aa80c46a6a9d35e23ac5b0b9fc466c7f Mon Sep 17 00:00:00 2001 From: Klara Date: Mon, 16 Dec 2024 19:18:46 +0000 Subject: [PATCH 5/8] Destroy meshes when destroying MeshWithMaterialRenderer --- Assets/Scripts/model/core/MeshWithMaterialRenderer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs b/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs index 2ac21955..6f18c996 100644 --- a/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs +++ b/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs @@ -51,6 +51,14 @@ public void UsePreviewShader(bool usePreview) // Which Layer this mesh will be drawn to. public int Layer = DEFAULT_LAYER; + public void OnDestroy() + { + foreach (MeshWithMaterial meshWithMaterial in meshes) + { + Destroy(meshWithMaterial.mesh); + } + } + public void Init(WorldSpace worldSpace) { this.worldSpace = worldSpace; From e569c525e7213a0a1eb8058d29631967f6576f9f Mon Sep 17 00:00:00 2001 From: Klara Date: Mon, 16 Dec 2024 19:27:55 +0000 Subject: [PATCH 6/8] Add memory usage info to palette --- Assets/Prefabs/CameraRig.prefab | 252 +++++++++++++++++++++++++++++++- Assets/Profiler.cs | 87 +++++++++++ Assets/Profiler.cs.meta | 11 ++ 3 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 Assets/Profiler.cs create mode 100644 Assets/Profiler.cs.meta diff --git a/Assets/Prefabs/CameraRig.prefab b/Assets/Prefabs/CameraRig.prefab index 59e6e648..33f68fac 100644 --- a/Assets/Prefabs/CameraRig.prefab +++ b/Assets/Prefabs/CameraRig.prefab @@ -3760,6 +3760,7 @@ Transform: m_Children: - {fileID: 4908724992920432} - {fileID: 4657463438926638} + - {fileID: 5076219253652055847} m_Father: {fileID: 4136544352420854} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1058421795516628 @@ -30445,7 +30446,7 @@ Camera: m_Depth: 0 m_CullingMask: serializedVersion: 2 - m_Bits: 4294952671 + m_Bits: 4294952703 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 @@ -74905,6 +74906,121 @@ Camera: m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 +--- !u!1 &6249299646841875550 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5076219253652055847} + - component: {fileID: 4506482073504366338} + - component: {fileID: 2095997645222470298} + - component: {fileID: 4216401758512156658} + - component: {fileID: 4674249550964265817} + m_Layer: 5 + m_Name: Profiler + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &5076219253652055847 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6249299646841875550} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: 0, y: 0, z: -0.2139} + m_LocalScale: {x: 0.0006, y: 0.0006, z: 0.0006} + m_ConstrainProportionsScale: 1 + m_Children: + - {fileID: 6483366733439243235} + m_Father: {fileID: 4219182568934276} + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0.0561, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} +--- !u!223 &4506482073504366338 +Canvas: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6249299646841875550} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 2 + m_Camera: {fileID: 20010936846075698} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_VertexColorAlwaysGammaSpace: 0 + m_AdditionalShaderChannelsFlag: 25 + m_UpdateRectTransformForStandalone: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 +--- !u!114 &2095997645222470298 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6249299646841875550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 0 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 800, y: 600} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 0 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 + m_PresetInfoIsWorld: 1 +--- !u!114 &4216401758512156658 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6249299646841875550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &4674249550964265817 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6249299646841875550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 94a65a525dc833d44b703c9497a38f71, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &8311839842708757556 GameObject: m_ObjectHideFlags: 0 @@ -74937,6 +75053,140 @@ Transform: - {fileID: 4836180625913568720} m_Father: {fileID: 4657463438926638} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &8691313442411617469 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6483366733439243235} + - component: {fileID: 202643350866492317} + - component: {fileID: 4993443190278709601} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &6483366733439243235 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8691313442411617469} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 5076219253652055847} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0.5} + m_AnchorMax: {x: 0, y: 0.5} + m_AnchoredPosition: {x: 0, y: -7} + m_SizeDelta: {x: 360, y: 50} + m_Pivot: {x: 0, y: 0} +--- !u!222 &202643350866492317 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8691313442411617469} + m_CullTransparentMesh: 1 +--- !u!114 &4993443190278709601 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8691313442411617469} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 100 MB memory used + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 30 + m_fontSizeBase: 30 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &8697257038037221240 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Profiler.cs b/Assets/Profiler.cs new file mode 100644 index 00000000..e45f57c7 --- /dev/null +++ b/Assets/Profiler.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Unity.Collections; +using Unity.Profiling.Memory; +using UnityEngine; + +public class Profiler : MonoBehaviour +{ + private TMPro.TextMeshProUGUI text; + private float timeSinceLastUpdate; + const int kFreeBlockPow2Buckets = 24; + // Start is called before the first frame update + private bool lowMemory; + + private void LowMemory() + { + lowMemory = true; + } + + void Start() + { + text = GetComponentInChildren(); + // Application.lowMemory += LowMemory; + } + + // Update is called once per frame + void Update() + { + timeSinceLastUpdate += Time.deltaTime; + if (timeSinceLastUpdate >= 1.0f) + { + var totalAllocatedMemory = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong() / 1024 / 1024; + // var totalReservedMemory = UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong() / 1024 / 1024; + // var totalUnusedReservedMemory = UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong() / 1024 / 1024; + // var graphicsAllocatedMemory = UnityEngine.Profiling.Profiler.GetAllocatedMemoryForGraphicsDriver() / 1024 / 1024; + // var usedHeapSize = UnityEngine.Profiling.Profiler.usedHeapSizeLong / 1024 / 1024; + + // var freeStats = new NativeArray(kFreeBlockPow2Buckets, Allocator.Temp); + // var freeBlocks = UnityEngine.Profiling.Profiler.GetTotalFragmentationInfo(freeStats); + + // if memory is low show text in red: + // text.color = lowMemory ? Color.red : Color.white; + + // format text + text.text = $"{totalAllocatedMemory:D} MB memory used\n"; + // $"{totalReservedMemory:F} MB total reserved mem \n" + + // $"{totalUnusedReservedMemory:F} MB total unused reserved mem \n" + + // $"{graphicsAllocatedMemory:F} MB graphics alloc mem \n" + + // $"{totalAllocatedMemory + graphicsAllocatedMemory:F} MB total alloc mem + graphics alloc mem \n"; + // $"{usedHeapSize:F} MB \n/ " + + // $"{freeBlocks}"; + // if (lowMemory) + // { + // text.text += "(low memory!!!)"; + // } + // #if UNITY_ANDROID && !UNITY_EDITOR + // CheckAndroidMemory(); + // #endif + timeSinceLastUpdate = 0; + } + } + + void CheckAndroidMemory() + { + using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + using (AndroidJavaObject currentActivity = unityPlayer.GetStatic("currentActivity")) + using (AndroidJavaObject activityManager = currentActivity.Call("getSystemService", "activity")) + { + AndroidJavaObject memoryInfo = new AndroidJavaObject("android.app.ActivityManager$MemoryInfo"); + activityManager.Call("getMemoryInfo", memoryInfo); + long totalMem = memoryInfo.Get("totalMem"); + long availMem = memoryInfo.Get("availMem"); + long threshold = memoryInfo.Get("threshold"); + bool lowMemory = memoryInfo.Get("lowMemory"); + text.text += // $"{totalMem / (1024 * 1024)} MB andr totl mem \n" + + $"{availMem / (1024 * 1024)} MB avail mem \n" + + $"{threshold / (1024 * 1024)} MB threshold \n"; + // $"{lowMemory} low Mem\n"; + } + } + + private void OnDestroy() + { + Application.lowMemory -= LowMemory; + } +} diff --git a/Assets/Profiler.cs.meta b/Assets/Profiler.cs.meta new file mode 100644 index 00000000..61c9b149 --- /dev/null +++ b/Assets/Profiler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 94a65a525dc833d44b703c9497a38f71 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 2067f40bf50e15793567b594c45a3a4e7bac3043 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Tue, 17 Dec 2024 10:25:33 +0000 Subject: [PATCH 7/8] Replicate the fix from open brush pr #799 https://github.com/icosa-foundation/open-brush/pull/799 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d42a864..15482133 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -207,7 +207,7 @@ jobs: echo "Initial free space" df -h / echo "Removing all pre-loaded docker images" - docker rmi $(docker image ls -aq) # Removes ~3GB + docker image ls -aq | xargs -r docker rmi # Removes ~3GB df -h / echo "Listing 100 largest packages" dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | head -n 100 From b86aeddef8a30e00e559dae1e6916c93ade36f80 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Tue, 17 Dec 2024 12:00:59 +0000 Subject: [PATCH 8/8] Revert "Add memory usage info to palette" This reverts commit e569c525e7213a0a1eb8058d29631967f6576f9f. --- Assets/Prefabs/CameraRig.prefab | 252 +------------------------------- Assets/Profiler.cs | 87 ----------- Assets/Profiler.cs.meta | 11 -- 3 files changed, 1 insertion(+), 349 deletions(-) delete mode 100644 Assets/Profiler.cs delete mode 100644 Assets/Profiler.cs.meta diff --git a/Assets/Prefabs/CameraRig.prefab b/Assets/Prefabs/CameraRig.prefab index 33f68fac..59e6e648 100644 --- a/Assets/Prefabs/CameraRig.prefab +++ b/Assets/Prefabs/CameraRig.prefab @@ -3760,7 +3760,6 @@ Transform: m_Children: - {fileID: 4908724992920432} - {fileID: 4657463438926638} - - {fileID: 5076219253652055847} m_Father: {fileID: 4136544352420854} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1058421795516628 @@ -30446,7 +30445,7 @@ Camera: m_Depth: 0 m_CullingMask: serializedVersion: 2 - m_Bits: 4294952703 + m_Bits: 4294952671 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 @@ -74906,121 +74905,6 @@ Camera: m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 ---- !u!1 &6249299646841875550 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 5076219253652055847} - - component: {fileID: 4506482073504366338} - - component: {fileID: 2095997645222470298} - - component: {fileID: 4216401758512156658} - - component: {fileID: 4674249550964265817} - m_Layer: 5 - m_Name: Profiler - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &5076219253652055847 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6249299646841875550} - m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: -0.2139} - m_LocalScale: {x: 0.0006, y: 0.0006, z: 0.0006} - m_ConstrainProportionsScale: 1 - m_Children: - - {fileID: 6483366733439243235} - m_Father: {fileID: 4219182568934276} - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0.0561, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0, y: 0} ---- !u!223 &4506482073504366338 -Canvas: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6249299646841875550} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 2 - m_Camera: {fileID: 20010936846075698} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 0 - m_OverridePixelPerfect: 0 - m_SortingBucketNormalizedSize: 0 - m_VertexColorAlwaysGammaSpace: 0 - m_AdditionalShaderChannelsFlag: 25 - m_UpdateRectTransformForStandalone: 0 - m_SortingLayerID: 0 - m_SortingOrder: 0 - m_TargetDisplay: 0 ---- !u!114 &2095997645222470298 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6249299646841875550} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} - m_Name: - m_EditorClassIdentifier: - m_UiScaleMode: 0 - m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 - m_MatchWidthOrHeight: 0 - m_PhysicalUnit: 3 - m_FallbackScreenDPI: 96 - m_DefaultSpriteDPI: 96 - m_DynamicPixelsPerUnit: 1 - m_PresetInfoIsWorld: 1 ---- !u!114 &4216401758512156658 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6249299646841875550} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} - m_Name: - m_EditorClassIdentifier: - m_IgnoreReversedGraphics: 1 - m_BlockingObjects: 0 - m_BlockingMask: - serializedVersion: 2 - m_Bits: 4294967295 ---- !u!114 &4674249550964265817 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6249299646841875550} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 94a65a525dc833d44b703c9497a38f71, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &8311839842708757556 GameObject: m_ObjectHideFlags: 0 @@ -75053,140 +74937,6 @@ Transform: - {fileID: 4836180625913568720} m_Father: {fileID: 4657463438926638} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &8691313442411617469 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 6483366733439243235} - - component: {fileID: 202643350866492317} - - component: {fileID: 4993443190278709601} - m_Layer: 5 - m_Name: Text (TMP) - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &6483366733439243235 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8691313442411617469} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 5076219253652055847} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 0, y: 0.5} - m_AnchoredPosition: {x: 0, y: -7} - m_SizeDelta: {x: 360, y: 50} - m_Pivot: {x: 0, y: 0} ---- !u!222 &202643350866492317 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8691313442411617469} - m_CullTransparentMesh: 1 ---- !u!114 &4993443190278709601 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8691313442411617469} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_text: 100 MB memory used - m_isRightToLeft: 0 - m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_fontSharedMaterials: [] - m_fontMaterial: {fileID: 0} - m_fontMaterials: [] - m_fontColor32: - serializedVersion: 2 - rgba: 4294967295 - m_fontColor: {r: 1, g: 1, b: 1, a: 1} - m_enableVertexGradient: 0 - m_colorMode: 3 - m_fontColorGradient: - topLeft: {r: 1, g: 1, b: 1, a: 1} - topRight: {r: 1, g: 1, b: 1, a: 1} - bottomLeft: {r: 1, g: 1, b: 1, a: 1} - bottomRight: {r: 1, g: 1, b: 1, a: 1} - m_fontColorGradientPreset: {fileID: 0} - m_spriteAsset: {fileID: 0} - m_tintAllSprites: 0 - m_StyleSheet: {fileID: 0} - m_TextStyleHashCode: -1183493901 - m_overrideHtmlColors: 0 - m_faceColor: - serializedVersion: 2 - rgba: 4294967295 - m_fontSize: 30 - m_fontSizeBase: 30 - m_fontWeight: 400 - m_enableAutoSizing: 0 - m_fontSizeMin: 18 - m_fontSizeMax: 72 - m_fontStyle: 0 - m_HorizontalAlignment: 1 - m_VerticalAlignment: 256 - m_textAlignment: 65535 - m_characterSpacing: 0 - m_wordSpacing: 0 - m_lineSpacing: 0 - m_lineSpacingMax: 0 - m_paragraphSpacing: 0 - m_charWidthMaxAdj: 0 - m_enableWordWrapping: 1 - m_wordWrappingRatios: 0.4 - m_overflowMode: 0 - m_linkedTextComponent: {fileID: 0} - parentLinkedComponent: {fileID: 0} - m_enableKerning: 1 - m_enableExtraPadding: 0 - checkPaddingRequired: 0 - m_isRichText: 1 - m_parseCtrlCharacters: 1 - m_isOrthographic: 1 - m_isCullingEnabled: 0 - m_horizontalMapping: 0 - m_verticalMapping: 0 - m_uvLineOffset: 0 - m_geometrySortingOrder: 0 - m_IsTextObjectScaleStatic: 0 - m_VertexBufferAutoSizeReduction: 0 - m_useMaxVisibleDescender: 1 - m_pageToDisplay: 1 - m_margin: {x: 0, y: 0, z: 0, w: 0} - m_isUsingLegacyAnimationComponent: 0 - m_isVolumetricText: 0 - m_hasFontAssetChanged: 0 - m_baseMaterial: {fileID: 0} - m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &8697257038037221240 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Profiler.cs b/Assets/Profiler.cs deleted file mode 100644 index e45f57c7..00000000 --- a/Assets/Profiler.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Unity.Collections; -using Unity.Profiling.Memory; -using UnityEngine; - -public class Profiler : MonoBehaviour -{ - private TMPro.TextMeshProUGUI text; - private float timeSinceLastUpdate; - const int kFreeBlockPow2Buckets = 24; - // Start is called before the first frame update - private bool lowMemory; - - private void LowMemory() - { - lowMemory = true; - } - - void Start() - { - text = GetComponentInChildren(); - // Application.lowMemory += LowMemory; - } - - // Update is called once per frame - void Update() - { - timeSinceLastUpdate += Time.deltaTime; - if (timeSinceLastUpdate >= 1.0f) - { - var totalAllocatedMemory = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong() / 1024 / 1024; - // var totalReservedMemory = UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong() / 1024 / 1024; - // var totalUnusedReservedMemory = UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong() / 1024 / 1024; - // var graphicsAllocatedMemory = UnityEngine.Profiling.Profiler.GetAllocatedMemoryForGraphicsDriver() / 1024 / 1024; - // var usedHeapSize = UnityEngine.Profiling.Profiler.usedHeapSizeLong / 1024 / 1024; - - // var freeStats = new NativeArray(kFreeBlockPow2Buckets, Allocator.Temp); - // var freeBlocks = UnityEngine.Profiling.Profiler.GetTotalFragmentationInfo(freeStats); - - // if memory is low show text in red: - // text.color = lowMemory ? Color.red : Color.white; - - // format text - text.text = $"{totalAllocatedMemory:D} MB memory used\n"; - // $"{totalReservedMemory:F} MB total reserved mem \n" + - // $"{totalUnusedReservedMemory:F} MB total unused reserved mem \n" + - // $"{graphicsAllocatedMemory:F} MB graphics alloc mem \n" + - // $"{totalAllocatedMemory + graphicsAllocatedMemory:F} MB total alloc mem + graphics alloc mem \n"; - // $"{usedHeapSize:F} MB \n/ " + - // $"{freeBlocks}"; - // if (lowMemory) - // { - // text.text += "(low memory!!!)"; - // } - // #if UNITY_ANDROID && !UNITY_EDITOR - // CheckAndroidMemory(); - // #endif - timeSinceLastUpdate = 0; - } - } - - void CheckAndroidMemory() - { - using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) - using (AndroidJavaObject currentActivity = unityPlayer.GetStatic("currentActivity")) - using (AndroidJavaObject activityManager = currentActivity.Call("getSystemService", "activity")) - { - AndroidJavaObject memoryInfo = new AndroidJavaObject("android.app.ActivityManager$MemoryInfo"); - activityManager.Call("getMemoryInfo", memoryInfo); - long totalMem = memoryInfo.Get("totalMem"); - long availMem = memoryInfo.Get("availMem"); - long threshold = memoryInfo.Get("threshold"); - bool lowMemory = memoryInfo.Get("lowMemory"); - text.text += // $"{totalMem / (1024 * 1024)} MB andr totl mem \n" + - $"{availMem / (1024 * 1024)} MB avail mem \n" + - $"{threshold / (1024 * 1024)} MB threshold \n"; - // $"{lowMemory} low Mem\n"; - } - } - - private void OnDestroy() - { - Application.lowMemory -= LowMemory; - } -} diff --git a/Assets/Profiler.cs.meta b/Assets/Profiler.cs.meta deleted file mode 100644 index 61c9b149..00000000 --- a/Assets/Profiler.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 94a65a525dc833d44b703c9497a38f71 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: