aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Diagnostics/Logger.cs
blob: 29d9c79b939605c46b1d0be8c1f9385e158a3783 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using ARMeilleure.Translation;
using System;
using System.Diagnostics;

namespace ARMeilleure.Diagnostics
{
    static class Logger
    {
        private static long _startTime;

        private static long[] _accumulatedTime;

        static Logger()
        {
            _accumulatedTime = new long[(int)PassName.Count];
        }

        public static void StartPass(PassName name)
        {
#if M_DEBUG
            WriteOutput(name + " pass started...");

            _startTime = Stopwatch.GetTimestamp();
#endif
        }

        public static void EndPass(PassName name, ControlFlowGraph cfg)
        {
#if M_DEBUG
            EndPass(name);

            WriteOutput("IR after " + name + " pass:");

            WriteOutput(IRDumper.GetDump(cfg));
#endif
        }

        public static void EndPass(PassName name)
        {
#if M_DEBUG
            long elapsedTime = Stopwatch.GetTimestamp() - _startTime;

            _accumulatedTime[(int)name] += elapsedTime;

            WriteOutput($"{name} pass ended after {GetMilliseconds(_accumulatedTime[(int)name])} ms...");
#endif
        }

        private static long GetMilliseconds(long ticks)
        {
            return (long)(((double)ticks / Stopwatch.Frequency) * 1000);
        }

        private static void WriteOutput(string text)
        {
            Console.WriteLine(text);
        }
    }
}