Repository navigation
Expand file tree
/
Copy pathttgrep.py
More file actions
executable file
·68 lines (60 loc) · 1.82 KB
/
Copy pathttgrep.py
File metadata and controls
executable file
·68 lines (60 loc) · 1.82 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
# Copyright (c) 2019-2022 Homa Developers
# SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+
"""
Scan the time trace data in a log file; find all records whose events
match a given Python regular expression, and output only those records.
If the --rebase argument is present, times are offset so the first event
is at time 0. If the file is omitted, standard input is used.
Usage: ttgrep.py [--rebase] regex [file]
"""
from __future__ import annotations
from typing import TextIO
from glob import glob
from optparse import OptionParser
import math
import os
import re
import string
import sys
rebase = False
def scan(f: TextIO, pattern: str) -> None:
"""
Scan the log file given by 'f' (handle for an open file) and output
all-time trace records that match pattern.
"""
global rebase
startTime = 0.0
prevTime = 0.0
writes = 0
compiled = re.compile(pattern)
for line in f:
match = re.match(r' *([-0-9.]+) us \(\+ *([0-9.]+) us\) (.*)',
line)
if not match:
continue
time = float(match.group(1))
interval = float(match.group(2))
event = match.group(3)
if (not compiled.search(event)) and ("Freez" not in event):
continue
if startTime == 0.0:
startTime = time
prevTime = time
if rebase:
printTime = time - startTime
else:
printTime = time
print("%9.3f us (+%8.3f us) %s" % (printTime,
time - prevTime, event))
prevTime = time
if (len(sys.argv) > 1) and (sys.argv[1] == "--rebase"):
rebase = True
del sys.argv[1]
f = sys.stdin
if len(sys.argv) == 3:
f = open(sys.argv[2])
elif len(sys.argv) != 2:
print("Usage: %s [--rebase] regex [logFile]" % (sys.argv[0]))
sys.exit(1)
scan(f, sys.argv[1])