-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_python_timeline.py
More file actions
51 lines (46 loc) · 1.6 KB
/
Copy pathparse_python_timeline.py
File metadata and controls
51 lines (46 loc) · 1.6 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
import json
with open('/Library/Logs/DiagnosticReports/JetsamEvent-2026-07-25-143652.ips') as f:
lines = f.readlines()
data = json.loads(''.join(lines[1:]))
# Incident time: 2026-07-25 14:36:52 CST
# age is in nanoseconds
incident_ts = 1784961412 # epoch for 2026-07-25 14:36:52 CST
print('=== Python process timeline (reverse calculated start time) ===')
for p in data['processes']:
name = p.get('name', '?')
if name != 'Python':
continue
pid = p.get('pid', 0)
age_ns = p.get('age', 0)
age_sec = age_ns / 1e9
age_min = age_sec / 60
age_hr = age_min / 60
start_ts = incident_ts - age_sec
import time
start_time = time.ctime(start_ts)
lm = p.get('lifetimeMax', 0)
cpu = p.get('cpuTime', 0)
mb = round(lm * 16384 / 1024 / 1024, 1)
print(f'pid={pid:6d} start={start_time} age={age_hr:.1f}h peak={mb:8.1f}MB cpu={cpu:7.1f}s')
print('\n=== zsh process timeline ===')
for p in data['processes']:
name = p.get('name', '?')
if name != 'zsh':
continue
pid = p.get('pid', 0)
age_ns = p.get('age', 0)
age_sec = age_ns / 1e9
start_ts = incident_ts - age_sec
start_time = time.ctime(start_ts)
print(f'pid={pid:6d} start={start_time} age={age_sec/60:.1f}min')
print('\n=== tail process timeline ===')
for p in data['processes']:
name = p.get('name', '?')
if name != 'tail':
continue
pid = p.get('pid', 0)
age_ns = p.get('age', 0)
age_sec = age_ns / 1e9
start_ts = incident_ts - age_sec
start_time = time.ctime(start_ts)
print(f'pid={pid:6d} start={start_time} age={age_sec/60:.1f}min')