11import subprocess
2- import re
3-
4- TRACE_PATTERN = re .compile (
5- rb"^(.{1,16}?)-(\d+)\s+\[(\d+)\]\s+([a-zA-Z.]+)\s+([0-9.]+):\s+.*?:\s+(.*)$"
6- )
72
83
94def trace_pipe ():
@@ -20,12 +15,42 @@ def trace_fields():
2015 while True :
2116 line = f .readline ().rstrip ()
2217
23- if not line or line .startswith (b"CPU:" ):
18+ if not line :
19+ continue
20+
21+ # Skip lost event lines
22+ if line .startswith (b"CPU:" ):
2423 continue
2524
26- match = TRACE_PATTERN .match (line )
27- if not match :
25+ # Parse BCC-style: first 16 bytes = task
26+ task = line [:16 ].lstrip ().decode ("utf-8" )
27+ line = line [17 :] # Skip past task field and space
28+
29+ # Find the colon that ends "pid cpu flags timestamp"
30+ ts_end = line .find (b":" )
31+ if ts_end == - 1 :
2832 raise ValueError ("Cannot parse trace line" )
2933
30- task , pid , cpu , flags , ts , msg = match .groups ()
31- return (task .strip (), int (pid ), int (cpu ), flags , float (ts ), msg )
34+ # Split "pid [cpu] flags timestamp"
35+ try :
36+ parts = line [:ts_end ].split ()
37+ if len (parts ) < 4 :
38+ raise ValueError ("Not enough fields" )
39+
40+ pid = int (parts [0 ])
41+ cpu = parts [1 ][1 :- 1 ] # Remove brackets from [cpu]
42+ cpu = int (cpu )
43+ flags = parts [2 ]
44+ ts = float (parts [3 ])
45+ except (ValueError , IndexError ):
46+ raise ValueError ("Cannot parse trace line" )
47+
48+ # Get message: skip ": symbol:" part
49+ line = line [ts_end + 1 :] # Skip first ":"
50+ sym_end = line .find (b":" )
51+ if sym_end != - 1 :
52+ msg = line [sym_end + 2 :].decode ("utf-8" ) # Skip ": " after symbol
53+ else :
54+ msg = line .lstrip ().decode ("utf-8" )
55+
56+ return (task , pid , cpu , flags , ts , msg )
0 commit comments