From 4b20a565664bba4b245a269da3abefa1ad7c38c5 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 25 Sep 2024 17:34:03 +0100 Subject: [PATCH 1/5] Util to read current git branch --- Assets/Scripts/Util/GitUtils.cs | 24 ++++++++++++++++++++++++ Assets/Scripts/Util/GitUtils.cs.meta | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 Assets/Scripts/Util/GitUtils.cs create mode 100644 Assets/Scripts/Util/GitUtils.cs.meta diff --git a/Assets/Scripts/Util/GitUtils.cs b/Assets/Scripts/Util/GitUtils.cs new file mode 100644 index 000000000..db805e323 --- /dev/null +++ b/Assets/Scripts/Util/GitUtils.cs @@ -0,0 +1,24 @@ +using System.Diagnostics; + +namespace TiltBrush +{ + public static class GitUtils + { + public static string GetGitBranchName() + { + ProcessStartInfo startInfo = new ProcessStartInfo("git", "rev-parse --abbrev-ref HEAD") + { + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + using (Process process = Process.Start(startInfo)) + { + process.WaitForExit(); + string output = process.StandardOutput.ReadToEnd().Trim(); + return output; + } + } + } +} diff --git a/Assets/Scripts/Util/GitUtils.cs.meta b/Assets/Scripts/Util/GitUtils.cs.meta new file mode 100644 index 000000000..2b497dc98 --- /dev/null +++ b/Assets/Scripts/Util/GitUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b85862c054f14289a78ca374f6613854 +timeCreated: 1727268299 \ No newline at end of file From ea10dbacf776963d3fe5b1918c6314591346d699 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 25 Sep 2024 17:34:48 +0100 Subject: [PATCH 2/5] Allow loading of bundled sketches with "tiltbrush://builtin/" prefix --- Assets/Scripts/App.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/App.cs b/Assets/Scripts/App.cs index 26a949e98..d7d5a6f37 100644 --- a/Assets/Scripts/App.cs +++ b/Assets/Scripts/App.cs @@ -72,6 +72,7 @@ public partial class App : MonoBehaviour private const int kHttpListenerPort = 40074; private const string kProtocolHandlerPrefix = "tiltbrush://remix/"; + private const string kBuiltInSketchPrefix = "tiltbrush://builtin/"; private const string kFileMoveFilename = "WhereHaveMyFilesGone.txt"; private const string kFileMoveContents = @@ -638,11 +639,18 @@ void Start() foreach (string s in Config.m_SketchFiles) { - // Assume all relative paths are relative to the Sketches directory. string sketch = s; - if (!System.IO.Path.IsPathRooted(sketch)) + if (s.StartsWith(kBuiltInSketchPrefix)) { - sketch = System.IO.Path.Combine(App.UserSketchPath(), sketch); + sketch = s; + } + else + { + // Assume all relative paths are relative to the Sketches directory. + if (!System.IO.Path.IsPathRooted(sketch)) + { + sketch = System.IO.Path.Combine(App.UserSketchPath(), sketch); + } } m_RequestedTiltFileQueue.Enqueue(sketch); if (Config.m_SdkMode == SdkMode.Ods || Config.OfflineRender) @@ -1475,6 +1483,15 @@ private bool HandleExternalTiltOpenRequest() return HandlePolyRequest(path); } + if (path.StartsWith(kBuiltInSketchPrefix)) + { + path = path.Substring(kBuiltInSketchPrefix.Length); + path = Path.Join(FeaturedSketchesPath(), path); + SketchControlsScript.m_Instance.IssueGlobalCommand( + SketchControlsScript.GlobalCommands.LoadNamedFile, sParam: path); + return true; + } + // Copy to sketch folder in order to discourage the user from explicitly saving // to gallery for future access, which would (by design) strip attribution. // Crypto hash suffix is added to the filename for (deterministic) uniqueness. From f051a8a3456a1ea4cb7baeb99728569a5e1ef898 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 25 Sep 2024 17:35:17 +0100 Subject: [PATCH 3/5] Tweak location and content of profiling summary --- Assets/Scripts/Debug/ProfilingManager.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Debug/ProfilingManager.cs b/Assets/Scripts/Debug/ProfilingManager.cs index 50610c762..d4b3616c0 100644 --- a/Assets/Scripts/Debug/ProfilingManager.cs +++ b/Assets/Scripts/Debug/ProfilingManager.cs @@ -156,7 +156,7 @@ private string GetProfilingFilename() string dateTime = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); filename = string.Format("Profile_{0}.data", dateTime); } - return Path.Combine(Application.persistentDataPath, filename); + return filename; } // Grabs the frame times and any functions being profiled. @@ -212,6 +212,12 @@ private void OutputStats() ? SaveLoadScript.m_Instance.GetLastFileHumanName() : App.UserConfig.Profiling.ProfileName; message.AppendLine("TBProfile: START"); +#if UNITY_EDITOR + string branch = GitUtils.GetGitBranchName(); + message.AppendLine($"Git branch: {branch}"); +#endif + message.AppendLine($"Profile name: {profileName} Filename: {fileName} Human name: {humanName}"); + if (App.UserConfig.Profiling.PerfgateOutput) { PerfgateOutput(message, m_FrameTimes.ToArray(), numBatches, numTriangles, file); @@ -230,6 +236,11 @@ private void OutputStats() message.AppendLine("TBProfile: END"); Debug.Log(message.ToString()); + + string path = Path.Join( + App.UserPath(), + $"{GetProfilingFilename()}_summary.txt"); + File.WriteAllText(path, message.ToString()); } private void HumanReadableOutput(StringBuilder output, Statistics.Summary stats, int numBatches, From 0eb2fe63ecf297b769c3326413e8ab005daf9e05 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 25 Sep 2024 18:52:11 +0100 Subject: [PATCH 4/5] Fix speling --- .github/workflows/build.yml | 2 +- Assets/Scripts/SketchControlsScript.cs | 4 ++-- Assets/Scripts/UserConfig.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fd83a93f..4901fd1e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,7 +136,7 @@ jobs: env: PRERELEASE: ${{ steps.version.outputs.prerelease }} run: | - # For a PR action (i.e., syncronize / open), the value of github.ref will be refs/pull/1234/merge + # For a PR action (i.e., synchronize / open), the value of github.ref will be refs/pull/1234/merge # For a push action, it will be either refs/heads/foo_branch_name OR refs/tags/v1234. # We want to use the base name for pushes of tags or to main, the PR number for PRs, and the branch name for named branches. if [[ "$PRERELEASE" == "false" || ${{ github.ref }} == refs/heads/main ]] diff --git a/Assets/Scripts/SketchControlsScript.cs b/Assets/Scripts/SketchControlsScript.cs index 294099a13..4577277be 100644 --- a/Assets/Scripts/SketchControlsScript.cs +++ b/Assets/Scripts/SketchControlsScript.cs @@ -5105,7 +5105,7 @@ private void ToggleProfiling() } else { - ProfilingManager.Instance.StartProfiling(App.UserConfig.Profiling.ProflingMode); + ProfilingManager.Instance.StartProfiling(App.UserConfig.Profiling.ProfilingMode); } } @@ -5142,7 +5142,7 @@ private IEnumerator DoProfiling(bool andQuit = false) InputManager.Wand.Geometry.transform.rotation = Camera.main.transform.rotation; m_PanelManager.LockPanelsToController(); - ProfilingManager.Instance.StartProfiling(App.UserConfig.Profiling.ProflingMode); + ProfilingManager.Instance.StartProfiling(App.UserConfig.Profiling.ProfilingMode); yield return new WaitForSeconds(App.UserConfig.Profiling.Duration); ProfilingManager.Instance.StopProfiling(); diff --git a/Assets/Scripts/UserConfig.cs b/Assets/Scripts/UserConfig.cs index b789dbe44..313c82fdc 100644 --- a/Assets/Scripts/UserConfig.cs +++ b/Assets/Scripts/UserConfig.cs @@ -601,7 +601,7 @@ public struct ProfilingConfig { public const int kDefaultScreenshotResolution = 1000; public string[] ProfilingFunctions { get; private set; } - public ProfilingManager.Mode ProflingMode { get; private set; } + public ProfilingManager.Mode ProfilingMode { get; private set; } public string Mode { @@ -609,7 +609,7 @@ public string Mode { try { - ProflingMode = (ProfilingManager.Mode)Enum.Parse(typeof(ProfilingManager.Mode), value); + ProfilingMode = (ProfilingManager.Mode)Enum.Parse(typeof(ProfilingManager.Mode), value); } catch (ArgumentException) { From a767a522d9b8ad9b970e5bf09a0eb8017add5526 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Wed, 25 Sep 2024 18:52:59 +0100 Subject: [PATCH 5/5] Include build string in profile summary. Add a 40fps bucket --- Assets/Scripts/App.cs | 2 +- Assets/Scripts/Debug/ProfilingManager.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/App.cs b/Assets/Scripts/App.cs index d7d5a6f37..c26e70c58 100644 --- a/Assets/Scripts/App.cs +++ b/Assets/Scripts/App.cs @@ -473,7 +473,7 @@ void DestroyIntroSketch() Resources.UnloadUnusedAssets(); } - static string GetStartupString() + public static string GetStartupString() { string str = $"{App.kAppDisplayName} {Config.m_VersionNumber}"; diff --git a/Assets/Scripts/Debug/ProfilingManager.cs b/Assets/Scripts/Debug/ProfilingManager.cs index d4b3616c0..41f7e51a4 100644 --- a/Assets/Scripts/Debug/ProfilingManager.cs +++ b/Assets/Scripts/Debug/ProfilingManager.cs @@ -59,7 +59,7 @@ private struct Sample private List m_FrameTimes; private const int k_NumFrames = 75 * 6; // enough space for six seconds of samples. private Coroutine m_UpdateCoroutine; - private int[] m_ValidFramerates = { 90, 75, 60, 1 }; + private int[] m_ValidFramerates = { 90, 75, 60, 40, 1 }; private List m_Samples = new List(); public static ProfilingManager Instance @@ -216,6 +216,7 @@ private void OutputStats() string branch = GitUtils.GetGitBranchName(); message.AppendLine($"Git branch: {branch}"); #endif + message.AppendLine($"Build: {App.GetStartupString()}"); message.AppendLine($"Profile name: {profileName} Filename: {fileName} Human name: {humanName}"); if (App.UserConfig.Profiling.PerfgateOutput)