Skip to content

Commit

Permalink
Add a few profiling markers and make errors pink
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Mar 19, 2020
1 parent d3dbc79 commit f72479e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using UnityEditor;
using UnityEngine;
using UnityEngine.Profiling;

namespace UdonSharp
{
Expand Down Expand Up @@ -42,11 +43,16 @@ public int Compile(List<ClassDefinition> classDefinitions)
if (programAsset.sourceCsScript == null)
throw new System.ArgumentException($"Asset '{AssetDatabase.GetAssetPath(programAsset)}' does not have a valid program source to compile from");

Profiler.BeginSample("Compile Module");

programAsset.compileErrors.Clear();

sourceCode = File.ReadAllText(AssetDatabase.GetAssetPath(programAsset.sourceCsScript));

Profiler.BeginSample("Parse AST");
SyntaxTree tree = CSharpSyntaxTree.ParseText(sourceCode);
Profiler.EndSample();

int errorCount = 0;

string errorString = "";
Expand All @@ -71,9 +77,11 @@ public int Compile(List<ClassDefinition> classDefinitions)
if (errorCount > 0)
{
ErrorCount = errorCount;
Profiler.EndSample();
return errorCount;
}

Profiler.BeginSample("Visit");
UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers);
fieldVisitor.Visit(tree.GetRoot());

Expand Down Expand Up @@ -112,19 +120,27 @@ public int Compile(List<ClassDefinition> classDefinitions)

errorCount++;
}
Profiler.EndSample();

if (errorCount == 0)
{
Profiler.BeginSample("Build assembly");
string dataBlock = BuildHeapDataBlock();
string codeBlock = visitor.GetCompiledUasm();

programAsset.SetUdonAssembly(dataBlock + codeBlock);
Profiler.EndSample();

Profiler.BeginSample("Assemble Program");
programAsset.AssembleCsProgram((uint)(moduleSymbols.GetAllUniqueChildSymbols().Count + visitor.GetExternStrCount()));
Profiler.EndSample();
programAsset.behaviourIDHeapVarName = visitor.GetIDHeapVarName();

programAsset.fieldDefinitions = visitor.visitorContext.localFieldDefinitions;
}

Profiler.EndSample();

return errorCount;
}

Expand Down
5 changes: 5 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CSharp;
using UnityEditor;
using UnityEngine;
using UnityEngine.Profiling;
using VRC.Udon.Common.Interfaces;

namespace UdonSharp
Expand All @@ -33,6 +34,8 @@ public UdonSharpCompiler(UdonSharpProgramAsset[] programAssets)

public void Compile()
{
Profiler.BeginSample("UdonSharp Compile");

System.Diagnostics.Stopwatch compileTimer = new System.Diagnostics.Stopwatch();
compileTimer.Start();

Expand Down Expand Up @@ -90,6 +93,8 @@ public void Compile()
Debug.Log($"[UdonSharp] Compile of script{(modules.Length > 1 ? "s" : "")} {string.Join(", ", modules.Select(e => Path.GetFileName(AssetDatabase.GetAssetPath(e.programAsset.sourceCsScript))))} finished in {compileTimer.Elapsed.ToString("mm\\:ss\\.fff")}");
}
}

Profiler.EndSample();
}

public int AssignHeapConstants()
Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void DrawCompileErrorTextArea()

// todo: convert this to a tree view that just has a list of selectable items that jump to the error
EditorGUILayout.LabelField($"Compile Error{(compileErrors.Count > 1 ? "s" : "")}", EditorStyles.boldLabel);
EditorGUILayout.TextArea(string.Join("\n", compileErrors.Select(e => e.Replace("[UdonSharp] ", ""))), errorTextStyle);
EditorGUILayout.TextArea(string.Join("\n", compileErrors.Select(e => e.Replace("[<color=#FF00FF>UdonSharp</color>] ", ""))), errorTextStyle);
}

protected override void DrawProgramSourceGUI(UdonBehaviour udonBehaviour, ref bool dirty)
Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public static string LogBuildError(string message, string filePath, int line, in
{
MethodInfo buildErrorLogMethod = typeof(UnityEngine.Debug).GetMethod("LogPlayerBuildError", BindingFlags.NonPublic | BindingFlags.Static);

string errorMessage = $"[UdonSharp] {filePath}({line},{character}): {message}";
string errorMessage = $"[<color=#FF00FF>UdonSharp</color>] {filePath}({line},{character}): {message}";

buildErrorLogMethod.Invoke(null, new object[] {
errorMessage,
Expand Down

0 comments on commit f72479e

Please sign in to comment.