Commit 7ae9ceaf authored by Ben Gamari's avatar Ben Gamari 🐢

ghc_timings: Use pandas

parent f9207038
......@@ -38,6 +38,8 @@ let
--prefix PATH : ${python3.withPackages (pkgs: with pkgs; [ matplotlib pandas tabulate ])}/bin
makeWrapper ${./sample_proc.py} $out/bin/sample-proc \
--prefix PATH : ${python3.withPackages (pkgs: with pkgs; [ matplotlib pandas tabulate ])}/bin
makeWrapper ${./ghc_timings.py} $out/bin/ghc-timings \
--prefix PATH : ${python3.withPackages (pkgs: with pkgs; [ matplotlib pandas tabulate ])}/bin
'';
};
gdb = import ./gdb { inherit nixpkgs; };
......
......@@ -4,6 +4,7 @@
import re
import sys
import typing
import pandas as pd
from typing import Iterator
class Timing(typing.NamedTuple):
......@@ -12,7 +13,7 @@ class Timing(typing.NamedTuple):
time: float
allocd: float
def parse_timings(s: str) -> Iterator[Timing]:
def parse_timings_raw(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)
......@@ -20,12 +21,16 @@ def parse_timings(s: str) -> Iterator[Timing]:
allocd = float(m.group(4))
yield Timing(phase, module, time, allocd)
def parse_timings(s: str) -> pd.DataFrame:
xs = list(parse_timings_raw(s))
df = pd.DataFrame(xs, columns=['phase', 'module', 'time', 'allocd'])
df['n'] = df.index
df.sort_values(by=['module', 'n'], inplace=True)
return df.drop(columns='n')
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))
print(parse_timings(s).to_markdown())
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment