ghc_timings.py 866 Bytes
Newer Older
Ben Gamari's avatar
Ben Gamari committed
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import sys
import typing
from typing import Iterator

class Timing(typing.NamedTuple):
    phase: str
    module: str
    time: float
    allocd: float

def parse_timings(s: str) -> Iterator[Timing]:
    for m in re.finditer(r'!!! ([\w \d]+) \[([\w\d_\.]+)\]: finished in (\d+\.\d+) milliseconds, allocated (\d+\.\d+) megabytes', s):
        phase = m.group(1)
        module = m.group(2)
        time = float(m.group(3))
        allocd = float(m.group(4))
        yield Timing(phase, module, time, allocd)

def main() -> None:
    s = sys.stdin.read()
    print('| module | phase | time (ms) | alloc (MB) |')
    print('| ------ | ----- | --------- | ---------- |')
    for t in parse_timings(s):
        print('| {module} | {phase} | {time} | {allocd} |'.format(**t))

if __name__ == '__main__':
    main()