Files
snapd/debug-tools/startup-timings
Maciej Borzecki 840ce01e92 debug-tools: trivial script to process startup timings
The script parses startup logs obtained with SNAPD_DEBUG=1, extracts relevant
messages and presents an overview of the timings, which looks like so:

0.026017s       start -> snap to snap-confine
0.003458s       snap to snap-confine -> snap-confine enter
0.000892s       snap-confine enter -> snap-confine mount namespace start
0.106204s       snap-confine mount namespace start -> snap-confine mount namespace finish
0.001186s       snap-confine mount namespace finish -> snap-confine to snap-exec
0.002771s       snap-confine to snap-exec -> snap-exec to app
approx. total: 0.140528s

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-05-16 12:20:42 +02:00

50 lines
1.2 KiB
Python
Executable File

#!/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))
rawdata = json.loads(match.group(1))
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())