Logger.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using ARMeilleure.Translation;
  2. using System;
  3. using System.Diagnostics;
  4. namespace ARMeilleure.Diagnostics
  5. {
  6. static class Logger
  7. {
  8. private static long _startTime;
  9. private static long[] _accumulatedTime;
  10. static Logger()
  11. {
  12. _accumulatedTime = new long[(int)PassName.Count];
  13. }
  14. [Conditional("M_DEBUG")]
  15. public static void StartPass(PassName name)
  16. {
  17. WriteOutput(name + " pass started...");
  18. _startTime = Stopwatch.GetTimestamp();
  19. }
  20. [Conditional("M_DEBUG")]
  21. public static void EndPass(PassName name, ControlFlowGraph cfg)
  22. {
  23. EndPass(name);
  24. WriteOutput("IR after " + name + " pass:");
  25. WriteOutput(IRDumper.GetDump(cfg));
  26. }
  27. [Conditional("M_DEBUG")]
  28. public static void EndPass(PassName name)
  29. {
  30. long elapsedTime = Stopwatch.GetTimestamp() - _startTime;
  31. _accumulatedTime[(int)name] += elapsedTime;
  32. WriteOutput($"{name} pass ended after {GetMilliseconds(_accumulatedTime[(int)name])} ms...");
  33. }
  34. private static long GetMilliseconds(long ticks)
  35. {
  36. return (long)(((double)ticks / Stopwatch.Frequency) * 1000);
  37. }
  38. private static void WriteOutput(string text)
  39. {
  40. Console.WriteLine(text);
  41. }
  42. }
  43. }