1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-30 17:50:46 +00:00

collector/dmesg: Avoid unnecessary dmesg command

Only run the minimal amount of commands, as executing a command can be
costly.

In the sequence reset() -> start(), we only need to get the output of
dmesg upon start() to know what part of the log will be ignored
(everything before the call to start()). There is no need to perform
that upon reset() since the sequence:

    reset() -> start() -> stop() -> start() -> stop()
               \______1________/    \______2________/

is anyway equivalent to:

    reset() -> start() -> stop()
               \______2________/

So reset() can essentially be a no-op and the actual reset logic lives
in start().
This commit is contained in:
Douglas Raillard 2023-07-17 12:07:58 +01:00 committed by Marc Bonnici
parent eb2c7e488b
commit cf4d3b5f4c

View File

@ -234,27 +234,7 @@ class DmesgCollector(CollectorBase):
if entry.timestamp > timestamp
]
def reset(self):
# If the buffer is emptied on start(), it does not matter as we will
# not end up with entries dating from before start()
if self.empty_buffer:
# Empty the dmesg ring buffer. This requires root in all cases
self.target.execute('dmesg -c', as_root=True)
else:
self.stop()
try:
entry = self.entries[-1]
except IndexError:
pass
else:
self._begin_timestamp = entry.timestamp
self._dmesg_out = None
def start(self):
self.reset()
def stop(self):
def _get_output(self):
levels_list = list(takewhile(
lambda level: level != self.level,
self.LOG_LEVELS
@ -270,6 +250,27 @@ class DmesgCollector(CollectorBase):
self._dmesg_out = self.target.execute(cmd, as_root=self.needs_root)
def reset(self):
self._dmesg_out = None
def start(self):
# If the buffer is emptied on start(), it does not matter as we will
# not end up with entries dating from before start()
if self.empty_buffer:
# Empty the dmesg ring buffer. This requires root in all cases
self.target.execute('dmesg -c', as_root=True)
else:
self._get_output()
try:
entry = self.entries[-1]
except IndexError:
pass
else:
self._begin_timestamp = entry.timestamp
def stop(self):
self._get_output()
def set_output(self, output_path):
self.output_path = output_path