The sysfs documentation mentions that the value written
to buffer_size_kb ftrace field may be rounded up.
So skip the verify loop on this field.
The case we are worried about, a requested buffer
size that the target cannot fulfill is caught anyway,
as the sysfs write returns with an error that is caught.
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
Add a Collector for accessing Google's Perfetto tracing infrastructure.
The Collector takes a path to an on-device config file, starts tracing
in the background using the perfetto binary and then stops by killing
the tracing process.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Since we now set the top buffer size to be the same as the devlib buffer
size, this effectively halves the maximum available buffer size that can
be set while using devlib. Whatever size is passed as `buffer_size` will
be allocated twice, even if the top buffer is hardly used at all.
This commit separates them into `buffer_size` and `top_buffer_size`. If
the latter is not passed, the behaviour will not change compared to now.
Fixes: e0c53d09990b5501e493d048a5dce067d8990281
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
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().
trace-cmd start -B devlib -b 42 will set the buffer size for the
"devlib" ftrace instance but will not set the buffer size of the
top-level buffer.
Unfortunately, some events still end up in the top-level buffer
regardless of any configuration such as the "print" event. This can lead
to lost events because the buffer size was too small.
Avoid that by using the buffer size for both top-level and devlib's
instance.
FtraceCollector.available_events is not memoized anymore as the set of
events supported by the target can change dynamically (e.g. loading a
kernel module).
This means that calling self.available_events is somewhat expensive, so
avoid doing it in a loop. Instead, save the events in a variable and
reuse it in the function to save a substantial amount of time.
Use a buffer named "devlib" instead of using the top-level default
buffer. That will improve interop with other tools trying to collect a
trace at the same time as devlib.
Remove the "future" dependency as devlib does not support Python 2
anymore.
Also remove the "from __future__ import division" as this is the default
in Python 3.
When no entry has been recorded by the collector, return an empty string
rather than returning the full dmesg log.
Also fix get_data() that would fail try to add None + '\n' if dmesg_out
property returns None.
Rather than systematically clearing the buffer on reset(), record the
timestamp of the last entry and use it to filter-out old entries in
DmesgCollector.entries property.
This also allows detecting if the ring buffer has ran out of memory, or
if something has cleared the buffer while collecting, leading to missing
entries.
Change default FtraceCollector(tracing_path=...) to None, and
auto-detect mount point when None is given.
Also expose an FtraceCollector.find_tracing_path() method so that user
code can also access this path without having to instantiate an
FtraceCollector.
If simpleperf record is called with "-f N", we may want to run
"simpleperf report-sample" on the output to dump the periodic
records. Let the PerfCollector() run report-sample in the target,
similar to how we run report.
The stop() command of the PerfCollector kills all sleep commands in
the target, saying "We hope that no other important sleep is
on-going". This is only needed if we are running "perf stat",
simpleperf does not need this. Background the
perf/simpleperf command and only kill all sleeps in that specific case.
Some kernels compiled with CONFIG_SECURITY_DMESG_RESTRICT can restrict
reading the dmesg buffer to root user as a security hardening measure.
Detect this case and use root accordingly.
If you want to collect events by event id (eg. in simpleperf, "rNNN"
with NNN a number), you must run it as root. Otherwise, simpleperf
fails with a SIGABRT.
Run simpleperf as root by default if the target is rooted to avoid
this.
logcat -v lets you specify the format for the logcat output. Add a
parameter to the LogcatCollector to allow us to pass that information
down to the logcat invocation.
Pipe the list of perf events via cat to ensure that a pager is not
used to display the output as this can cause some systems to hang
waiting for user input.
Update the interface to make use of the collector interface.
Notable changes are the removal of the `output_path` path provided on
initialisation which will now be provided by the dedicated `set_output`
method.
Update `get_trace` to `get_data` to better reflect the purpose.
The return type of said method will be a `CollectorOutput` object will
contain one or more `CollectorOutputEntry` objects which will be used to
provide the `path`and `path_kind` attributes to indicate the path to the
obtained output and it's type (currently a "file" or "directory")
respectively.