File: startup-timings

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (50 lines) | stat: -rwxr-xr-x 1,337 bytes parent folder | download
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
#!/usr/bin/env python3

import json
import re
import logging
import argparse


def parse_arguments():
    parser = argparse.ArgumentParser(description="startup timings parser")
    parser.add_argument("log", help="snap startup log")
    parser.add_argument(
        "-v", "--verbose", help="verbose", action="store_true", default=False
    )
    return parser.parse_args()


def main(opts):
    if opts.verbose:
        logging.basicConfig(level=logging.DEBUG)

    with open(opts.log, encoding="utf-8") as inf:
        lines = inf.readlines()

    steps = []
    for line in lines:
        match = re.match(r".*-- snap startup ({.*?})", line)
        if match:
            logging.debug("got match: %s", match.group(1))
            cleaned_data = match.group(1).replace('\\"', '"')
            rawdata = json.loads(cleaned_data)
            steps.append(rawdata)
    if not steps:
        print("no logs found")

    total = 0.0
    for idx, current in enumerate(steps):
        if idx == 0:
            last = current
            continue
        diff = float(current["time"]) - float(last["time"])
        total += diff
        print("{2:3f}s\t{0} -> {1}".format(last["stage"], current["stage"], diff))
        last = current

    print("approx. total: {0:3f}s".format(total))


if __name__ == "__main__":
    main(parse_arguments())