├── .gitignore ├── Editor.meta ├── Editor ├── ProfilerSnapshotUtils.cs └── ProfilerSnapshotUtils.cs.meta ├── README.md ├── README.md.meta ├── Unity.WorldBuilding.ProfilerSnapshot.asmdef ├── Unity.WorldBuilding.ProfilerSnapshot.asmdef.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio cache directory 9 | .vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | *.opendb 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | *.pdb.meta 30 | 31 | # Unity3D Generated File On Crash Reports 32 | sysinfo.txt 33 | 34 | # Builds 35 | *.apk 36 | *.unitypackage 37 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb65dc6a52a74344d9ea979d57e5ebc3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ProfilerSnapshotUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEditorInternal; 6 | using UnityEngine; 7 | using UnityEngine.Profiling; 8 | 9 | namespace Unity.WorldBuilding.Profiling 10 | { 11 | public static class ProfilerSnapshotUtils 12 | { 13 | private const string k_ProfilerFolder = "ProfilerLogs"; 14 | private static readonly string k_ProjectFolder = Application.dataPath.Replace("/Assets", ""); 15 | 16 | private static bool m_IsSilentMode = false; 17 | private static bool m_IsSnapshotting = false; 18 | private static GUIStyle m_SceneWarningStyle; 19 | 20 | [InitializeOnLoadMethod] 21 | private static void Init() 22 | { 23 | SceneView.onSceneGUIDelegate += OnSceneGUI; 24 | } 25 | 26 | private static void OnSceneGUI(SceneView sceneview) 27 | { 28 | EnsureStyleGenerated(); 29 | 30 | if (m_IsSnapshotting && !m_IsSilentMode) 31 | { 32 | Handles.BeginGUI(); 33 | GUI.contentColor = Color.white; 34 | GUI.backgroundColor = Color.black; 35 | GUI.Box(new Rect(5, 5, 300, 35), "Profiler Snapshot in Progress", m_SceneWarningStyle); 36 | Handles.EndGUI(); 37 | } 38 | } 39 | 40 | [MenuItem("Tests/Profiler/Toggle Snapshot %m")] 41 | private static void ToggleSnapshot() 42 | { 43 | if (Profiler.enabled) 44 | { 45 | StopSnapshot(); 46 | } 47 | else 48 | { 49 | StartSnapshot(false); 50 | } 51 | } 52 | 53 | public static void StartSnapshot(bool silent) 54 | { 55 | StartSnapshot(silent, string.Format("[{0:MM-dd-yyyy.HH.mm}]-profiler-log", DateTime.Now)); 56 | } 57 | 58 | public static void StartSnapshot(bool silent, string fileName) 59 | { 60 | if (m_IsSnapshotting) 61 | return; 62 | 63 | if (!Directory.Exists(k_ProfilerFolder)) 64 | { 65 | Directory.CreateDirectory(k_ProfilerFolder); 66 | } 67 | 68 | if (silent) 69 | { 70 | Debug.LogFormat("Profiler Snapshot Started [editorProfile={0} | deepProfile={1}]", 71 | ProfilerDriver.profileEditor, ProfilerDriver.deepProfiling); 72 | } 73 | 74 | ProfilerDriver.ClearAllFrames(); 75 | ProfilerDriver.enabled = true; 76 | 77 | m_IsSilentMode = silent; 78 | m_IsSnapshotting = true; 79 | } 80 | 81 | public static void StopSnapshot() 82 | { 83 | if (!m_IsSnapshotting) 84 | return; 85 | 86 | m_IsSnapshotting = false; 87 | 88 | ProfilerDriver.enabled = false; 89 | string filePath = string.Format("{0}/{1}", k_ProjectFolder, "somefile.raw"); 90 | ProfilerDriver.SaveProfile(filePath); 91 | 92 | if (!m_IsSilentMode) 93 | { 94 | Debug.LogFormat("Profiler Snapshot Stopped. Profiler raw file create at path {0}", filePath); 95 | ProfilerDriver.LoadProfile(filePath, false); 96 | OpenProfilerWindow(); 97 | } 98 | 99 | m_IsSilentMode = false; 100 | } 101 | 102 | private static void OpenProfilerWindow() 103 | { 104 | Assembly assembly = typeof(EditorWindow).Assembly; 105 | EditorWindow.GetWindow(assembly.GetType("UnityEditor.ProfilerWindow")); 106 | } 107 | 108 | private static void EnsureStyleGenerated() 109 | { 110 | if (m_SceneWarningStyle == null) 111 | { 112 | m_SceneWarningStyle = new GUIStyle(EditorStyles.helpBox) 113 | { 114 | alignment = TextAnchor.MiddleCenter, 115 | fontSize = 16, 116 | fontStyle = FontStyle.Bold 117 | }; 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Editor/ProfilerSnapshotUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea365233b8c94854ca260f226ebf53eb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # description 2 | Tool to make it easier to profile the editor without having the profiler window open. Uses current profiler settings so can also be used to profile outside of the editor. To use it: Tests/Profiler/Toggle Snapshot. 3 | 4 | 5 | # install 6 | 7 | - Open `Packages/manifest.json` 8 | - Add `"com.unity.worldbuilding.profilersnapshot":"https://github.com/Unity-Technologies/profiler-snapshot-tool.git"` to the `dependencies` list 9 | 10 | ``` 11 | { 12 | "dependencies": { 13 | "com.unity.worldbuilding.profilersnapshot": "https://github.com/Unity-Technologies/profiler-snapshot-tool.git" 14 | } 15 | } 16 | ``` 17 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c43692bace235545a01bed217b06c45 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity.WorldBuilding.ProfilerSnapshot.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.WorldBuilding.ProfilerSnapshot", 3 | "references": [], 4 | "optionalUnityReferences": [], 5 | "includePlatforms": [ 6 | "Editor" 7 | ], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [] 14 | } -------------------------------------------------------------------------------- /Unity.WorldBuilding.ProfilerSnapshot.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49356d341d04fbe468c600930abec2e6 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.unity.worldbuilding.profilersnapshot", 3 | "displayName": "Profiler Snapshot Tool", 4 | "version": "1.0.1-preview", 5 | "unity": "2018.1", 6 | "description": "", 7 | "dependencies": { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d34576f3ff169942803b404fd961f07 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------