Skip to content

Commit

Permalink
MAVExplorer: Fix stats command for DF text and TLOG logs
Browse files Browse the repository at this point in the history
For DF text: name not message id is used to index counts, and count is
not set for messages that are never seen.

For TLOG: As we don't have a formats attribute on the mavmmaplog class,
we count message instances rather than size in bytes.
Output formatting is adjusted to take account of the longest name.

The filehandle attribute is called f instead in mavmmaplog class, so
updated MPDataLogChildTask class of multiproc_util.py to handle this.
  • Loading branch information
shancock884 authored and peterbarker committed Jan 24, 2024
1 parent c4619af commit 6b30791
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
43 changes: 32 additions & 11 deletions MAVProxy/modules/lib/msgstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,52 @@ def child_task(self):

def show_stats(mlog):
'''show stats on a file'''
if not hasattr(mlog, 'formats'):
print("Must be DF log")
return
sizes = {}
total_size = 0
names = mlog.name_to_id.keys()
pairs = []
maxnamelen = 4

for name in names:
sizes[name] = 0

for name in names:
mid = mlog.name_to_id[name]
count = mlog.counts[mid]
mlen = mlog.formats[mid].len
size = count * mlen
total_size += size
sizes[name] += size
pairs.append((name, count*mlen))
# DFReader_text logs use the name directly as the index to the dictionaries
if hasattr(mlog, 'formats') and mid not in mlog.formats:
mid = name
# In DFReader_text logs count is a dictionary, which is not set for
# messages that are never seen in the log.
if isinstance(mlog.counts,dict) and mid not in mlog.counts:
count = 0
else:
count = mlog.counts[mid]
# mavmmaplog class (tlogs) does not contain formats attribute, so instead of
# counting size in bytes, we count the number of messages
if hasattr(mlog, 'formats'):
mlen = mlog.formats[mid].len
size = count * mlen
total_size += size
sizes[name] += size
pairs.append((name, count*mlen))
else:
total_size += count
pairs.append((name, count))
if count>0 and len(name)>maxnamelen:
maxnamelen = len(name)

# mavmmaplog class (tlogs) does not contain formats attribute, so instead of
# counting size in bytes, we count the number of messages
if not hasattr(mlog, 'formats'):
print("Total number of messages: %u" % total_size)
else:
print("Total size: %u" % total_size)

# Print out the percentage for each message, from lowest to highest
pairs = sorted(pairs, key = lambda p : p[1])
print("Total size: %u" % total_size)
for (name,size) in pairs:
if size > 0:
print("%-4s %.2f%%" % (name, 100.0 * size / total_size))
print("%-*s %.2f%%" % (maxnamelen, name, 100.0 * size / total_size))

print("")
category_total = 0
Expand Down
19 changes: 14 additions & 5 deletions MAVProxy/modules/lib/multiproc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def __init__(self, *args, **kwargs):
'''
Parameters
----------
mlog : DFReader
mlog : DFReader / mavmmaplog
A dataflash or telemetry log
'''
super(MPDataLogChildTask, self).__init__(*args, **kwargs)
Expand All @@ -282,22 +282,31 @@ def wrap(self):
'''Apply custom pickle wrappers to non-pickleable attributes'''

# wrap filehandle and mmap in mlog for pickling
filehandle = self._mlog.filehandle
if hasattr(self._mlog,'filehandle'):
filehandle = self._mlog.filehandle
elif hasattr(self._mlog,'f'):
filehandle = self._mlog.f
data_map = self._mlog.data_map
data_len = self._mlog.data_len
self._mlog.filehandle = WrapFileHandle(filehandle)
if hasattr(self._mlog,'filehandle'):
self._mlog.filehandle = WrapFileHandle(filehandle)
elif hasattr(self._mlog,'f'):
self._mlog.f = WrapFileHandle(filehandle)
self._mlog.data_map = WrapMMap(data_map, filehandle, data_len)

# @override
def unwrap(self):
'''Unwrap custom pickle wrappers of non-pickleable attributes'''

# restore the state of mlog
self._mlog.filehandle = self._mlog.filehandle.unwrap()
if hasattr(self._mlog,'filehandle'):
self._mlog.filehandle = self._mlog.filehandle.unwrap()
elif hasattr(self._mlog,'f'):
self._mlog.f = self._mlog.f.unwrap()
self._mlog.data_map = self._mlog.data_map.unwrap()

@property
def mlog(self):
'''The dataflash log (DFReader)'''
'''The dataflash or telemetry log (DFReader / mavmmaplog)'''

return self._mlog

0 comments on commit 6b30791

Please sign in to comment.