mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +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:
parent
eb2c7e488b
commit
cf4d3b5f4c
@ -234,27 +234,7 @@ class DmesgCollector(CollectorBase):
|
|||||||
if entry.timestamp > timestamp
|
if entry.timestamp > timestamp
|
||||||
]
|
]
|
||||||
|
|
||||||
def reset(self):
|
def _get_output(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):
|
|
||||||
levels_list = list(takewhile(
|
levels_list = list(takewhile(
|
||||||
lambda level: level != self.level,
|
lambda level: level != self.level,
|
||||||
self.LOG_LEVELS
|
self.LOG_LEVELS
|
||||||
@ -270,6 +250,27 @@ class DmesgCollector(CollectorBase):
|
|||||||
|
|
||||||
self._dmesg_out = self.target.execute(cmd, as_root=self.needs_root)
|
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):
|
def set_output(self, output_path):
|
||||||
self.output_path = output_path
|
self.output_path = output_path
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user