Skip to content

Instantly share code, notes, and snippets.

@ericallam
Created April 10, 2018 10:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericallam/c769cedb7050e8057230cc9d15492718 to your computer and use it in GitHub Desktop.
Save ericallam/c769cedb7050e8057230cc9d15492718 to your computer and use it in GitHub Desktop.
Unity - Log Assembly Compilation times
namespace Editor {
public class AssemblyCompilationReporter {
[InitializeOnLoadMethod]
private static void Init() {
CompilationPipeline.assemblyCompilationStarted += CompilationPipelineOnAssemblyCompilationStarted;
CompilationPipeline.assemblyCompilationFinished += CompilationPipelineOnAssemblyCompilationFinished;
}
private static void CompilationPipelineOnAssemblyCompilationFinished(string s, CompilerMessage[] compilerMessages) {
var startTimeInTicks = PlayerPrefs.GetString($"CompileStartTime{s}");
var startTime = new DateTime(Convert.ToInt64(startTimeInTicks));
var compileTime = DateTime.Now - startTime;
Debug.Log($"=== CompilationPipeline Assembly Finished {s} ({compileTime.ToString("s\\.fff")}s)");
foreach (var compilerMessage in compilerMessages) {
switch (compilerMessage.type) {
case CompilerMessageType.Error:
Debug.LogError($"==== {compilerMessage.file}[{compilerMessage.line}:{compilerMessage.column}] {compilerMessage.message}");
break;
case CompilerMessageType.Warning:
Debug.LogWarning($"==== {compilerMessage.file}[{compilerMessage.line}:{compilerMessage.column}] {compilerMessage.message}");
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private static void CompilationPipelineOnAssemblyCompilationStarted(string s) {
PlayerPrefs.SetString($"CompileStartTime{s}", Convert.ToString(DateTime.Now.Ticks));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment