Created
April 10, 2018 10:43
-
-
Save ericallam/c769cedb7050e8057230cc9d15492718 to your computer and use it in GitHub Desktop.
Unity - Log Assembly Compilation times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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