mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-10 20:02:13 +08:00
Fixup qlog size (#32719)
* stash * Revert "stash" This reverts commit 5a22b44919d4cb8681cc08d99656954423abda93. * improvements * rm * method 2 * Revert "method 2" This reverts commit 7112d95b3eead8bfdd8efb1dcefd4edbe9107680. * unreal for now * stash * Revert "stash" This reverts commit a7c5b31d8043b8da96c21a8d40281cece3cada61. * clean up * update description old-commit-hash: 81dc33e56994c364a2100978654c5abf4cacbe4e
This commit is contained in:
@@ -5,24 +5,30 @@ from collections import defaultdict
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from cereal.services import SERVICE_LIST
|
||||
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
|
||||
|
||||
|
||||
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())
|
||||
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])
|
||||
|
||||
print(f"{typ} - Total {total / 1024:.2f} kB")
|
||||
print("name - comp. size (uncomp. size)")
|
||||
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(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 += [('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__":
|
||||
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('segment', type=int, help='segment number to use')
|
||||
args = parser.parse_args()
|
||||
|
||||
r = Route(args.route)
|
||||
rlog = r.log_paths()[args.segment]
|
||||
msgs = list(LogReader(rlog))
|
||||
msgs = list(LogReader(args.route))
|
||||
|
||||
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(qlog_by_type, 'qlog')
|
||||
make_pie(msgs, 'qlog')
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user