#!/usr/bin/env python3 """Stop-the-world pauses from a -Xlog:gc*:...:time,uptime log, restricted to an epoch-ms window. usage: gc_pauses.py LOG WINDOW_START_MS WINDOW_END_MS A pause is a log line that contains "Pause" and ends in "ms" (G1 "Pause Young ... 4.2ms", ZGC "Y: Pause Mark Start 0.018ms", Shenandoah "Pause Init Mark 0.052ms"). The line without a duration that G1 and Shenandoah print when a pause *starts* is ignored, so nothing is counted twice. """ import re import sys from datetime import datetime LINE = re.compile(r"^\[(\d{4}-\d\d-\d\dT[\d:.]+[+-]\d{4})\].*?\bGC\(\d+\) .*Pause .* ([0-9.]+)ms$") log, lo, hi = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]) pauses = [] for line in open(log, errors="replace"): m = LINE.match(line.rstrip("\n")) if not m: continue ts = datetime.strptime(m.group(1), "%Y-%m-%dT%H:%M:%S.%f%z").timestamp() * 1000 if lo <= ts <= hi: pauses.append(float(m.group(2))) pauses.sort() n = len(pauses) def q(p): return pauses[min(n - 1, int(p * n))] if n else 0.0 print(f"pauses={n} pause_p50_ms={q(0.50):.3f} pause_p99_ms={q(0.99):.3f} pause_max_ms={pauses[-1] if n else 0.0:.3f} pause_total_ms={sum(pauses):.1f}")