DumpProfile.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Ryujinx.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. namespace Ryujinx.Profiler
  7. {
  8. public static class DumpProfile
  9. {
  10. public static void ToFile(string path, InternalProfile profile)
  11. {
  12. String fileData = "Category,Session Group,Session Item,Count,Average(ms),Total(ms)\r\n";
  13. foreach (KeyValuePair<ProfileConfig, TimingInfo> time in profile.Timers.OrderBy(key => key.Key.Tag))
  14. {
  15. fileData += $"{time.Key.Category}," +
  16. $"{time.Key.SessionGroup}," +
  17. $"{time.Key.SessionItem}," +
  18. $"{time.Value.Count}," +
  19. $"{time.Value.AverageTime / PerformanceCounter.TicksPerMillisecond}," +
  20. $"{time.Value.TotalTime / PerformanceCounter.TicksPerMillisecond}\r\n";
  21. }
  22. // Ensure file directory exists before write
  23. FileInfo fileInfo = new FileInfo(path);
  24. if (fileInfo == null)
  25. throw new Exception("Unknown logging error, probably a bad file path");
  26. if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
  27. Directory.CreateDirectory(fileInfo.Directory.FullName);
  28. File.WriteAllText(fileInfo.FullName, fileData);
  29. }
  30. }
  31. }