-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtombstoned.py
85 lines (70 loc) · 2.54 KB
/
tombstoned.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import re
import time
import uuid
import datetime
from raven import Client
from raven.transport.http import HTTPTransport
from selfdrive.version import version, dirty
from selfdrive.swaglog import cloudlog
def get_tombstones():
return [("/data/tombstones/"+fn, int(os.stat("/data/tombstones/"+fn).st_ctime) )
for fn in os.listdir("/data/tombstones") if fn.startswith("tombstone")]
def report_tombstone(fn, client):
mtime = os.path.getmtime(fn)
with open(fn, "r") as f:
dat = f.read()
# see system/core/debuggerd/tombstone.cpp
parsed = re.match(r"[* ]*\n"
r"(?P<header>CM Version:[\s\S]*?ABI:.*\n)"
r"(?P<thread>pid:.*\n)"
r"(?P<signal>signal.*\n)?"
r"(?P<abort>Abort.*\n)?"
r"(?P<registers>\s+x0[\s\S]*?\n)\n"
r"(?:backtrace:\n"
r"(?P<backtrace>[\s\S]*?\n)\n"
r"stack:\n"
r"(?P<stack>[\s\S]*?\n)\n"
r")?", dat)
logtail = re.search(r"--------- tail end of.*\n([\s\S]*?\n)---", dat)
logtail = logtail and logtail.group(1)
if parsed:
parsedict = parsed.groupdict()
message = parsedict.get('thread') or ''
message += parsedict.get('signal') or ''
message += parsedict.get('abort') or ''
else:
parsedict = {}
message = fn+"\n"+dat[:1024]
client.send(
event_id=uuid.uuid4().hex,
timestamp=datetime.datetime.utcfromtimestamp(mtime),
logger='tombstoned',
platform='other',
sdk={'name': 'tombstoned', 'version': '0'},
extra={
'tombstone_fn': fn,
'header': parsedict.get('header'),
'registers': parsedict.get('registers'),
'backtrace': parsedict.get('backtrace'),
'logtail': logtail,
'version': version,
'dirty': not bool(os.environ.get('CLEAN')),
},
user={'id': os.environ.get('DONGLE_ID')},
message=message,
)
cloudlog.error({"tombstone": message})
def main(gctx):
initial_tombstones = set(get_tombstones())
client = Client('https://d3b175702f62402c91ade04d1c547e68:[email protected]/157615',
install_sys_hook=False, transport=HTTPTransport, release=version, tags={'dirty': dirty})
while True:
now_tombstones = set(get_tombstones())
for fn, ctime in (now_tombstones - initial_tombstones):
cloudlog.info("reporting new tombstone %s", fn)
report_tombstone(fn, client)
initial_tombstones = now_tombstones
time.sleep(5)
if __name__ == "__main__":
main(None)