Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow profiler to use bundled sketches #769

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Assets/Scripts/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion Assets/Scripts/Debug/ProfilingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions Assets/Scripts/Util/GitUtils.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Util/GitUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading