improvements

pull/32719/head
Shane Smiskol 1 year ago
parent 22955b183e
commit 871fd18a47
  1. 39
      selfdrive/debug/internal/qlog_size.py

@ -13,16 +13,28 @@ MIN_SIZE = 0.5 # Percent size of total to show as separate entry
def make_pie(msgs, typ): def make_pie(msgs, typ):
compressed_length_by_type = {k: len(bz2.compress(b"".join(v))) for k, v in msgs.items()}
msgs_by_type = defaultdict(list)
for m in msgs:
msgs_by_type[m.which()].append(m.as_builder().to_bytes())
length_by_type = {k: len(b"".join(v)) for k, v in msgs_by_type.items()}
compressed_length_by_type = {k: len(bz2.compress(b"".join(v))) for k, v in msgs_by_type.items()}
real_total = len(bz2.compress(b"".join([m.as_builder().to_bytes() for m in msgs])))
uncompressed_total = len(b"".join([m.as_builder().to_bytes() for m in msgs]))
total = sum(compressed_length_by_type.values()) total = sum(compressed_length_by_type.values())
sizes = sorted(compressed_length_by_type.items(), key=lambda kv: kv[1]) sizes = sorted(compressed_length_by_type.items(), key=lambda kv: kv[1])
print(f"{typ} - Total {total / 1024:.2f} kB") print("name - comp. size (uncomp. size)")
for (name, sz) in sizes: for (name, sz) in sizes:
print(f"{name} - {sz / 1024:.2f} kB") print(f"{name:<22} - {sz / 1024:.2f} kB ({length_by_type[name] / 1024:.2f} kB)")
print() print()
print(f"{typ} - Total {total / 1024:.2f} kB")
print(f"{typ} - Real {real_total / 1024:.2f} kB")
print(f"{typ} - Uncompressed total {uncompressed_total / 1024 / 1024:.2f} MB")
sizes_large = [(k, sz) for (k, sz) in sizes if sz >= total * MIN_SIZE / 100] sizes_large = [(k, sz) for (k, sz) in sizes if sz >= total * MIN_SIZE / 100]
sizes_large += [('other', sum(sz for (_, sz) in sizes if sz < total * MIN_SIZE / 100))] sizes_large += [('other', sum(sz for (_, sz) in sizes if sz < total * MIN_SIZE / 100))]
@ -37,26 +49,9 @@ def make_pie(msgs, typ):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check qlog size based on a rlog') parser = argparse.ArgumentParser(description='Check qlog size based on a rlog')
parser.add_argument('route', help='route to use') parser.add_argument('route', help='route to use')
parser.add_argument('segment', type=int, help='segment number to use')
args = parser.parse_args() args = parser.parse_args()
r = Route(args.route) msgs = list(LogReader(args.route))
rlog = r.log_paths()[args.segment]
msgs = list(LogReader(rlog))
msgs_by_type = defaultdict(list)
for m in msgs:
msgs_by_type[m.which()].append(m.as_builder().to_bytes())
qlog_by_type = defaultdict(list)
for name, service in SERVICE_LIST.items():
if service.decimation is None:
continue
for i, msg in enumerate(msgs_by_type[name]):
if i % service.decimation == 0:
qlog_by_type[name].append(msg)
make_pie(msgs_by_type, 'rlog') make_pie(msgs, 'qlog')
make_pie(qlog_by_type, 'qlog')
plt.show() plt.show()

Loading…
Cancel
Save