openpilot v0.5.11 release

This commit is contained in:
Vehicle Researcher
2019-04-23 01:41:19 +00:00
parent 790732bea3
commit 2f92d577f9
99 changed files with 2744 additions and 1607 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ def can_printer(bus=0, max_msg=None, addr="127.0.0.1"):
for k,v in sorted(zip(msgs.keys(), map(lambda x: x[-1].encode("hex"), msgs.values()))):
if max_msg is None or k < max_msg:
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k,k),len(msgs[k]), v)
print dd
print(dd)
lp = sec_since_boot()
if __name__ == "__main__":
+99
View File
@@ -0,0 +1,99 @@
import psutil
import time
import os
import sys
import numpy as np
import argparse
import re
'''
System tools like top/htop can only show current cpu usage values, so I write this script to do statistics jobs.
Features:
Use psutil library to sample cpu usage(avergage for all cores) of OpenPilot processes, at a rate of 5 samples/sec.
Do cpu usage statistics periodically, 5 seconds as a cycle.
Caculate the average cpu usage within this cycle.
Caculate minumium/maximium/accumulated_average cpu usage as long term inspections.
Monitor multiple processes simuteneously.
Sample usage:
root@localhost:/data/openpilot$ python selfdrive/debug/cpu_usage_stat.py boardd,ubloxd
('Add monitored proc:', './boardd')
('Add monitored proc:', 'python locationd/ubloxd.py')
boardd: 1.96%, min: 1.96%, max: 1.96%, acc: 1.96%
ubloxd.py: 0.39%, min: 0.39%, max: 0.39%, acc: 0.39%
'''
# Do statistics every 5 seconds
PRINT_INTERVAL = 5
SLEEP_INTERVAL = 0.2
monitored_proc_names = [
'ubloxd', 'thermald', 'uploader', 'controlsd', 'plannerd', 'radard', 'mapd', 'loggerd' , 'logmessaged', 'tombstoned',
'logcatd', 'proclogd', 'boardd', 'pandad', './ui', 'calibrationd', 'locationd', 'visiond', 'sensord', 'updated', 'gpsd', 'athena']
def get_arg_parser():
parser = argparse.ArgumentParser(
description="Unlogger and UI",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("proc_names", nargs="?", default='',
help="Process names to be monitored, comma seperated")
parser.add_argument("--list_all", nargs="?", type=bool, default=False,
help="Show all running processes' cmdline")
return parser
if __name__ == "__main__":
args = get_arg_parser().parse_args(sys.argv[1:])
if args.list_all:
for p in psutil.process_iter():
print('cmdline', p.cmdline(), 'name', p.name())
sys.exit(0)
if len(args.proc_names) > 0:
monitored_proc_names = args.proc_names.split(',')
monitored_procs = []
stats = {}
for p in psutil.process_iter():
if p == psutil.Process():
continue
matched = any([l for l in p.cmdline() if any([pn for pn in monitored_proc_names if re.match(r'.*{}.*'.format(pn), l, re.M | re.I)])])
if matched:
k = ' '.join(p.cmdline())
print('Add monitored proc:', k)
stats[k] = {'cpu_samples': [], 'avg_cpu': None, 'min': None, 'max': None}
monitored_procs.append(p)
i = 0
interval_int = int(PRINT_INTERVAL / SLEEP_INTERVAL)
while True:
for p in monitored_procs:
k = ' '.join(p.cmdline())
stats[k]['cpu_samples'].append(p.cpu_percent())
time.sleep(SLEEP_INTERVAL)
i += 1
if i % interval_int == 0:
l = []
avg_cpus = []
for k, stat in stats.items():
if len(stat['cpu_samples']) <= 0:
continue
avg_cpu = np.array(stat['cpu_samples']).mean()
c = len(stat['cpu_samples'])
stat['cpu_samples'] = []
if not stat['avg_cpu']:
stat['avg_cpu'] = avg_cpu
else:
stat['avg_cpu'] = (stat['avg_cpu'] * (c + i) + avg_cpu * c) / (c + i + c)
if not stat['min'] or avg_cpu < stat['min']:
stat['min'] = avg_cpu
if not stat['max'] or avg_cpu > stat['max']:
stat['max'] = avg_cpu
msg = 'avg: {1:.2f}%, min: {2:.2f}%, max: {3:.2f}% {0}'.format(os.path.basename(k), stat['avg_cpu'], stat['min'], stat['max'])
l.append((os.path.basename(k), avg_cpu, msg))
avg_cpus.append(avg_cpu)
l.sort(key= lambda x: -x[1])
for x in l:
print(x[2])
print('avg sum: {0:.2f}%\n'.format(
sum([stat['avg_cpu'] for k, stat in stats.items()])
))
+7 -7
View File
@@ -52,7 +52,7 @@ if __name__ == "__main__":
server_thread = Thread(target=run_server, args=(socketio,))
server_thread.daemon = True
server_thread.start()
print 'server running'
print('server running')
values = None
if args.values:
@@ -68,7 +68,7 @@ if __name__ == "__main__":
if sock in republish_socks:
republish_socks[sock].send(msg)
if args.map and evt.which() == 'liveLocation':
print 'send loc'
print('send loc')
socketio.emit('location', {
'lat': evt.liveLocation.lat,
'lon': evt.liveLocation.lon,
@@ -83,15 +83,15 @@ if __name__ == "__main__":
elif args.json:
print(json.loads(msg))
elif args.dump_json:
print json.dumps(evt.to_dict())
print(json.dumps(evt.to_dict()))
elif values:
print "logMonotime = {}".format(evt.logMonoTime)
print("logMonotime = {}".format(evt.logMonoTime))
for value in values:
if hasattr(evt, value[0]):
item = evt
for key in value:
item = getattr(item, key)
print "{} = {}".format(".".join(value), item)
print ""
print("{} = {}".format(".".join(value), item))
print("")
else:
print evt
print(evt)
+2 -2
View File
@@ -26,5 +26,5 @@ while True:
fingerprint = ', '.join("%d: %d" % v for v in sorted(msgs.items()))
print "number of messages:", len(msgs)
print "fingerprint", fingerprint
print("number of messages {0}:".format(len(msgs)))
print("fingerprint {0}".format(fingerprint))
+1 -1
View File
@@ -98,4 +98,4 @@ def getframes(front=False):
if __name__ == "__main__":
for buf in getframes():
print buf.shape, buf[101, 101]
print("{0} {1}".format(buf.shape, buf[101, 101]))