Logger.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public static void StartPass(PassName name)
  15. {
  16. #if M_DEBUG
  17. WriteOutput(name + " pass started...");
  18. _startTime = Stopwatch.GetTimestamp();
  19. #endif
  20. }
  21. public static void EndPass(PassName name, ControlFlowGraph cfg)
  22. {
  23. #if M_DEBUG
  24. EndPass(name);
  25. WriteOutput("IR after " + name + " pass:");
  26. WriteOutput(IRDumper.GetDump(cfg));
  27. #endif
  28. }
  29. public static void EndPass(PassName name)
  30. {
  31. #if M_DEBUG
  32. long elapsedTime = Stopwatch.GetTimestamp() - _startTime;
  33. _accumulatedTime[(int)name] += elapsedTime;
  34. WriteOutput($"{name} pass ended after {GetMilliseconds(_accumulatedTime[(int)name])} ms...");
  35. #endif
  36. }
  37. private static long GetMilliseconds(long ticks)
  38. {
  39. return (long)(((double)ticks / Stopwatch.Frequency) * 1000);
  40. }
  41. private static void WriteOutput(string text)
  42. {
  43. Console.WriteLine(text);
  44. }
  45. }
  46. }