Fixup qlog size (#32719)

* stash

* Revert "stash"

This reverts commit 5a22b44919.

* improvements

* rm

* method 2

* Revert "method 2"

This reverts commit 7112d95b3e.

* unreal for now

* stash

* Revert "stash"

This reverts commit a7c5b31d80.

* clean up

* update description
old-commit-hash: 81dc33e569
testing-closet^2
Shane Smiskol 11 months ago committed by GitHub
parent 272216b2a8
commit e3c7bdf0a4
  1. 39
      selfdrive/debug/internal/qlog_size.py

@ -5,24 +5,30 @@ from collections import defaultdict
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from cereal.services import SERVICE_LIST
from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.route import Route
MIN_SIZE = 0.5 # Percent size of total to show as separate entry 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()}
total = sum(compressed_length_by_type.values()) total = sum(compressed_length_by_type.values())
uncompressed_total = len(b"".join([m.as_builder().to_bytes() for m in msgs]))
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} - 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))]
@ -35,28 +41,11 @@ 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='View log size breakdown by message type')
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