aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Profiler/DumpProfile.cs
blob: 62a027615d0f5af61069f38c458104408a1a0eaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Ryujinx.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Ryujinx.Profiler
{
    public static class DumpProfile
    {
        public static void ToFile(string path, InternalProfile profile)
        {
            String fileData = "Category,Session Group,Session Item,Count,Average(ms),Total(ms)\r\n";

            foreach (KeyValuePair<ProfileConfig, TimingInfo> time in profile.Timers.OrderBy(key => key.Key.Tag))
            {
                fileData += $"{time.Key.Category}," +
                            $"{time.Key.SessionGroup}," +
                            $"{time.Key.SessionItem}," +
                            $"{time.Value.Count}," +
                            $"{time.Value.AverageTime / PerformanceCounter.TicksPerMillisecond}," +
                            $"{time.Value.TotalTime / PerformanceCounter.TicksPerMillisecond}\r\n";
            }

            // Ensure file directory exists before write
            FileInfo fileInfo = new FileInfo(path);
            if (fileInfo == null)
                throw new Exception("Unknown logging error, probably a bad file path");
            if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
                Directory.CreateDirectory(fileInfo.Directory.FullName);

            File.WriteAllText(fileInfo.FullName, fileData);
        }
    }
}