public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { var setting = UPRToolSetting.Instance; if (scriptBackend == ScriptingImplementation.Mono2x && (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64)) { string AssemblyPath = pathToBuiltProject.Replace(".exe", "_Data/Managed/"); if (setting.enableMonoProfiler) { InjectMethods.InjectAllMethods(AssemblyPath + "Assembly-CSharp.dll"); Debug.Log("Listening Lua Profiler Success"); } if (setting.loadScene) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "SceneManager", "LoadScene"); } if (setting.loadAsset) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadAsset"); } if (setting.loadAssetBundle) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadFromFile"); } if (setting.instantiate) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "Object", "Instantiate"); } } }
static public void LoadAssembly(string path, bool isInjectLua, bool isInjectMono) { try { File.Copy(path, path + ".bak", true); AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path); (assemblyDefinition.MainModule.AssemblyResolver as DefaultAssemblyResolver).AddSearchDirectory(Path.GetDirectoryName(path)); AssemblyDefinition assemblyDefinition2 = AssemblyDefinition.ReadAssembly("LuaProfilerDLL.dll"); assemblyDefinition.MainModule.AssemblyReferences.Add(assemblyDefinition2.Name); assemblyDefinition.Write(path); if (isInjectLua) { InjectMethods.HookLuaFun(path, "LuaProfilerDLL.dll"); } if (isInjectMono) { InjectMethods.InjectAllMethods(path, "LuaProfilerDLL.dll"); } string profilerDLLPath = Path.Combine(Path.GetDirectoryName(path), "LuaProfilerDLL.dll"); Console.WriteLine(profilerDLLPath); File.Copy("LuaProfilerDLL.dll", profilerDLLPath, true); Console.WriteLine("Inject Success"); } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } }
public void OnPostGenerateGradleAndroidProject(string path) { var setting = UPRToolSetting.Instance; var backend = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Android); if (backend == ScriptingImplementation.IL2CPP) { return; } // both for export android project and apk if (Directory.Exists(path + "/src/main/assets/bin/Data/Managed/")) { AssemblyPath = path + "/src/main/assets/bin/Data/Managed/"; } if (string.IsNullOrEmpty(AssemblyPath)) { Debug.Log("[UPR package]: Could not find assembly file. Injection Error"); return; } if (setting.enableMonoProfiler) { InjectMethods.InjectAllMethods(AssemblyPath + "Assembly-CSharp.dll"); Debug.Log("Listening Mono Profiler Success"); } if (backend == ScriptingImplementation.Mono2x) { if (setting.loadScene) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "SceneManager", "LoadScene"); } if (setting.loadAsset) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadAsset"); InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "Load"); } if (setting.loadAssetBundle) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadFromFile"); } if (setting.instantiate) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "Object", "Instantiate"); } } }
public void OnPostGenerateGradleAndroidProject(string path) { var setting = UPRToolSetting.Instance; var backend = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Android); if (!Directory.Exists(AssemblyPath)) { AssemblyPath = "./Temp/gradleOut/unityLibrary/src/main/assets/bin/Data/Managed/"; } if (setting.enableMonoProfiler) { InjectMethods.InjectAllMethods(AssemblyPath + "Assembly-CSharp.dll"); Debug.Log("Listening Mono Profiler Success"); } if (backend == ScriptingImplementation.Mono2x) { if (setting.loadScene) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "SceneManager", "LoadScene"); } if (setting.loadAsset) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadAsset"); InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "Load"); } if (setting.loadAssetBundle) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadFromFile"); } if (setting.instantiate) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "Object", "Instantiate"); } } }
void doPackage() { var setting = UPRToolSetting.Instance; var luasetting = LuaDeepProfilerSetting.Instance; #region settings GUILayout.Space(10); GUILayout.Label("Settings"); GUILayout.BeginVertical("Box"); GUILayout.Space(ui_DefaultMargin); GUILayout.BeginHorizontal(); GUILayout.Label("ProjectId"); projectId = GUILayout.TextField(projectId, GUILayout.Width(position.width-70)); if (UPRToolSetting.Instance.projectId != projectId) // if (!string.IsNullOrEmpty(projectId)) // { UPRToolSetting.Instance.projectId = projectId; // } // else //{ // projectId = Utils.GetProjectId(); //} GUILayout.EndHorizontal(); #region advanced settings GUILayout.Space(2); GUILayout.BeginHorizontal(); m_AdvancedSettings = EditorGUILayout.Foldout(m_AdvancedSettings, "Advanced Settings"); if (m_AdvancedSettings) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset")) { UPRToolSetting.Instance.Reset(); m_CustomizedServer = UPRToolSetting.Instance.customizedServer; } GUILayout.EndHorizontal(); GUILayout.Space(ui_DefaultMargin); GUILayout.BeginHorizontal(); GUILayout.Label("Custom Server"); m_CustomizedServer = GUILayout.TextField(m_CustomizedServer, GUILayout.Width(position.width - 120)); if (!string.IsNullOrEmpty(m_CustomizedServer)) { UPRToolSetting.Instance.customizedServer = m_CustomizedServer; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } GUILayout.EndHorizontal(); #endregion GUILayout.EndVertical(); #endregion #region deep function profiler GUILayout.Space(10); GUILayout.Label("Deep Function Profiler"); GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); setting.loadScene = GUILayout.Toggle(setting.loadScene, "LoadScene", GUILayout.Width(position.width/2 - ui_DefaultMargin)); setting.loadAsset = GUILayout.Toggle(setting.loadAsset, "LoadAsset"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); setting.loadAssetBundle = GUILayout.Toggle(setting.loadAssetBundle, "LoadAssetBundle", GUILayout.Width(position.width/2 - ui_DefaultMargin)); setting.instantiate = GUILayout.Toggle(setting.instantiate, "Instantiate"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); #endregion #region deep lua profiler GUILayout.Space(10); GUILayout.Label("Deep Lua Profiler"); GUILayout.BeginVertical("Box"); setting.enableMonoProfiler = GUILayout.Toggle(setting.enableMonoProfiler, "Enable Deep Mono"); if (setting.enableMonoProfiler) { InjectMethods.Recompile("MIKU_RECOMPILE",true); luasetting.isDeepMonoProfiler = true; EditorGUILayout.HelpBox("Package will inject the necessary code to collect Mono information, which will cause some performance loss.", MessageType.Warning); EditorGUILayout.HelpBox("This function doesn't support ios devices currently.", MessageType.Warning); if (!uprLuaProfiler) { uprLuaProfiler = true; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } else { luasetting.isDeepMonoProfiler = false; InjectMethods.Recompile("MIKU_RECOMPILE",false); if (!setting.enableLuaProfiler && uprLuaProfiler) { uprLuaProfiler = false; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } setting.enableLuaProfiler = GUILayout.Toggle(setting.enableLuaProfiler, "Enable Lua"); if (setting.enableLuaProfiler) { luasetting.isDeepLuaProfiler = true; EditorGUILayout.HelpBox("Package will load some simple lua function to collect lua information. You can easy control whether to send data on UPR website.(Could not support il2cpp)", MessageType.Warning); if (!useLua) { string[] dir = Directory.GetDirectories(Application.dataPath, "*LuaProfiler*", SearchOption.TopDirectoryOnly); if (dir.Length > 0) { useLua = false; EditorGUILayout.HelpBox("LuaProfiler is Find in the directory", MessageType.Warning); } else { useLua = true; } InjectMethods.Recompile("USE_LUA", useLua); } if (!uprLuaProfiler) { uprLuaProfiler = true; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } else { luasetting.isDeepLuaProfiler = false; if (useLua) { useLua = false; InjectMethods.Recompile("USE_LUA", false); } if (!setting.enableMonoProfiler && uprLuaProfiler) { uprLuaProfiler = false; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } GUILayout.EndVertical(); #endregion #if UNITY_2018_2_OR_NEWER #region shader variants check region GUILayout.Space(10); GUILayout.Label("Shader Variants Report"); GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); setting.enableShaderVariantsCheck = GUILayout.Toggle(setting.enableShaderVariantsCheck, "Enable Shader Variants Report"); GUILayout.EndHorizontal(); if (setting.enableShaderVariantsCheck) { if (string.IsNullOrEmpty(UPRToolSetting.Instance.projectId)) { EditorGUILayout.HelpBox( "ProjectId not specified, you could manually upload ShaderVariantsReport file on UPR website after build.", MessageType.Warning); } else { EditorGUILayout.HelpBox( "ShaderVariantsReport will be automatically uploaded to UPR server after build.", MessageType.Info); } } GUILayout.EndVertical(); #endregion #endif #region particle system profiler if (psProfilerRunning) { if (EditorUtility.DisplayCancelableProgressBar( "Profiling Particle Systems", String.Format("Playing {0} / {1}", profilingIndex + 1, enabledIds.Count), (profilingIndex+1) / enabledIds.Count)) { Debug.Log("Profiling canceled manually."); psProfilerRunning = false; EditorUtility.ClearProgressBar(); } } GUILayout.Space(2 * ui_DefaultMargin); m_ParticleSystem = EditorGUILayout.Foldout(m_ParticleSystem, "Particle System Profiler"); if (m_ParticleSystem) { GUILayout.BeginVertical("Box"); GUI.enabled = !psProfilerRunning; GUILayout.BeginHorizontal(); if (GUILayout.Button("Detect", GUILayout.Height(25))) { DetectParticleSystems(); } if (GUILayout.Button("Start", GUILayout.Height(25))) { StartProfileParticleSystems(); } GUILayout.EndHorizontal(); m_TreeView.OnGUI(multiColumnTreeViewRect); GUI.enabled = true; GUILayout.BeginArea(uploadResultViewRect); GUILayout.Space(2 * ui_DefaultMargin); GUILayout.BeginHorizontal(); GUILayout.Label("Result Path"); GUILayout.TextArea(profileResultPath, GUILayout.Width(position.width-120), GUILayout.Height(30)); GUILayout.EndHorizontal(); GUI.enabled = profilingDone; GUILayout.Space(ui_DefaultMargin); var uploadBtn = GUILayout.Button("Upload Result", GUILayout.Height(25)); GUILayout.Space(ui_DefaultMargin); GUILayout.EndArea(); if (uploadBtn) { Debug.Log("Particle System Profile Result: " + profileResultPath); Debug.Log("UPR ProjectId: " + UPRToolSetting.Instance.projectId); var profileResults = new ProfileResults(profileResultPath); profileResults.UploadResults(); } GUI.enabled = true; GUILayout.EndVertical(); } #endregion }
void doPackage() { var setting = UPRToolSetting.Instance; var luasetting = LuaDeepProfilerSetting.Instance; #region deep function profiler GUILayout.Space(10); GUILayout.Label("Deep Function Profiler"); GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); setting.loadScene = GUILayout.Toggle(setting.loadScene, "LoadScene "); /* setting.loadAsset = GUILayout.Toggle(setting.loadAsset, "LoadAsset "); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); setting.loadAssetBundle = GUILayout.Toggle(setting.loadAssetBundle, "LoadAssetBundle "); setting.instantiate = GUILayout.Toggle(setting.instantiate, "Instantiate "); */ GUILayout.EndHorizontal(); GUILayout.EndVertical(); #endregion #region deep lua profiler GUILayout.Space(10); GUILayout.Label("Deep Lua Profiler"); GUILayout.BeginVertical("Box"); setting.enableMonoProfiler = GUILayout.Toggle(setting.enableMonoProfiler, "Enable Deep Mono"); if (setting.enableMonoProfiler) { InjectMethods.Recompile("MIKU_RECOMPILE",true); luasetting.isDeepMonoProfiler = true; EditorGUILayout.HelpBox("Package will inject the necessary code to collect Mono information. This will cause some performance loss.", MessageType.Warning); EditorGUILayout.HelpBox("This function doesn't support ios devices currently.", MessageType.Warning); if (!uprLuaProfiler) { uprLuaProfiler = true; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } else { luasetting.isDeepMonoProfiler = false; InjectMethods.Recompile("MIKU_RECOMPILE",false); if (!setting.enableLuaProfiler && uprLuaProfiler) { uprLuaProfiler = false; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } setting.enableLuaProfiler = GUILayout.Toggle(setting.enableLuaProfiler, "Enable Lua"); if (setting.enableLuaProfiler) { luasetting.isDeepLuaProfiler = true; EditorGUILayout.HelpBox("Package will load some simple lua function to collect lua information. You can easy control whether to send data on UPR website.", MessageType.Warning); if (!useLua) { string[] dir = Directory.GetDirectories(Application.dataPath, "*LuaProfiler*", SearchOption.TopDirectoryOnly); if (dir.Length > 0) { useLua = false; EditorGUILayout.HelpBox("LuaProfiler is Find in the directory", MessageType.Warning); } else { useLua = true; } InjectMethods.Recompile("USE_LUA", useLua); } if (!uprLuaProfiler) { uprLuaProfiler = true; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } else { luasetting.isDeepLuaProfiler = false; if (useLua) { useLua = false; InjectMethods.Recompile("USE_LUA", false); } if (!setting.enableMonoProfiler && uprLuaProfiler) { uprLuaProfiler = false; InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } GUILayout.EndVertical(); #endregion }
private void GUI_LuaProfiler(ref bool varUprSetDirty) { GUILayout.Label("Deep Lua Profiler"); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var tempMonoEnableVal = GUILayout.Toggle(_UPRSetting.enableMonoProfiler, "Enable Deep Mono"); if (tempMonoEnableVal != _UPRSetting.enableMonoProfiler) { var tempTip = string.Format("This action will {0} \"MIKU_RECOMPILE\" Macro compiler project code.", tempMonoEnableVal ? "append" : "remove"); if (EditorUtility.DisplayDialog("Confirm", tempTip, "Just Do it!")) { _UPRSetting.enableMonoProfiler = tempMonoEnableVal; varUprSetDirty = true; _UPRSetting.enableMonoProfiler = tempMonoEnableVal; _UPRSetting.Save(); InjectMethods.Recompile(_UPRSetting.enableMonoProfiler); } } if (tempMonoEnableVal) { var tempTip = "Package will inject the necessary code to collect Mono information.\nThis will cause some performance loss.\nThis function doesn't support IOS devices currently."; EditorGUILayout.HelpBox(tempTip, MessageType.Warning); } var tempLuaEnbaleVal = GUILayout.Toggle(_UPRSetting.enableLuaProfiler, "Enable Lua"); if (tempLuaEnbaleVal != _UPRSetting.enableLuaProfiler) { varUprSetDirty = true; _UPRSetting.enableLuaProfiler = tempLuaEnbaleVal; } if (_UPRSetting.enableLuaProfiler) { EditorGUILayout.HelpBox("Package will load some simple lua function to collect lua information. You can easy control whether to send data on UPR website.", MessageType.Warning); if (!deplicated) { string[] dir = Directory.GetDirectories(Application.dataPath, "*LuaProfiler*", SearchOption.TopDirectoryOnly); if (dir.Length > 0) { deplicated = false; EditorGUILayout.HelpBox("LuaProfiler is Find in the directory", MessageType.Warning); } else { deplicated = true; } //InjectMethods.addDeplicated(deplicated); } } else { if (deplicated) { deplicated = false; //InjectMethods.Recompile("DEPLICATED", false); } } if (!(uprLuaProfiler && (_UPRSetting.enableLuaProfiler || _UPRSetting.enableMonoProfiler))) { uprLuaProfiler = !uprLuaProfiler; //InjectMethods.Recompile("UPR_LUA_PROFILER", uprLuaProfiler); } } }
public void OnPostBuildPlayerScriptDLLs(BuildReport report) { string AssemblyPath = ""; var platform = report.summary.platform; if ((report.summary.platform == BuildTarget.StandaloneWindows || report.summary.platform == BuildTarget.StandaloneWindows64) && scriptBackend == ScriptingImplementation.IL2CPP) { InjectMethods.Recompile("USE_LUA", false); // windows didn't support il2cpp injection Debug.Log("Windows IL2CPP hasn't support listening function"); return; /* * scriptBackend = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Standalone); * if (scriptBackend == ScriptingImplementation.IL2CPP) * { * AssemblyPath = "./Temp/StagingArea/Il2Cpp/Managed/"; * if (!Directory.Exists(AssemblyPath)) * { * AssemblyPath = "./Temp/StagingArea/Data/Managed/"; * } * } */ } if (platform == BuildTarget.Android) { scriptBackend = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Android); if (scriptBackend == ScriptingImplementation.IL2CPP) { InjectMethods.Recompile("USE_LUA", false); if (Directory.Exists("./Temp/StagingArea/Il2Cpp/Managed/")) { AssemblyPath = "./Temp/StagingArea/Il2Cpp/Managed/"; } if (Directory.Exists("./Temp/StagingArea/Data/Managed/")) { AssemblyPath = "./Temp/StagingArea/Data/Managed/"; } } } if (platform == BuildTarget.iOS || platform == BuildTarget.WebGL) { InjectMethods.Recompile("USE_LUA", false); if (Directory.Exists("./Temp/StagingArea/Il2Cpp/Managed/")) { AssemblyPath = "./Temp/StagingArea/Il2Cpp/Managed/"; } if (Directory.Exists("./Temp/StagingArea/Data/Managed/")) { AssemblyPath = "./Temp/StagingArea/Data/Managed/"; } } if (AssemblyPath != "") { var setting = UPRToolSetting.Instance; if (setting.enableMonoProfiler) { InjectMethods.InjectAllMethods(AssemblyPath + "Assembly-CSharp.dll"); Debug.Log("Listening Mono Profiler Success"); } if (setting.loadScene) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "SceneManager", "LoadScene"); } if (setting.loadAsset) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadAsset"); } if (setting.loadAssetBundle) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.AssetBundleModule.dll", "AssetBundle", "LoadFromFile"); } if (setting.instantiate) { InjectUtils.addProfiler(AssemblyPath, "UnityEngine.CoreModule.dll", "Object", "Instantiate"); } } }