mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
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>
50 lines
1.2 KiB
Python
Executable File
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())
|