Try to fix and diagnose Perfetto flush errors.
Around 10% of the traces with Nettrace have "traced_final_flush_failed" errors. It is believed that Network Tracing isn't writing enough data to fill one "Chunk" in Perfetto's buffer. Although this should still be saved by Perfetto, it doesn't seem to be. This change records the number of packets read from the ring buffer to understand whether the error coincided with low-data cases. It also tries to flush the data OnStop to potentially fix the issue. Test: flash and run trace Change-Id: I92c8d2d8d47d1ed123585e1cfdde802d286f120f
This commit is contained in:
@@ -30,6 +30,7 @@ cc_library {
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"liblog",
|
||||
],
|
||||
static_libs: [
|
||||
@@ -81,6 +82,7 @@ cc_test {
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libandroid_net",
|
||||
],
|
||||
compile_multilib: "both",
|
||||
|
||||
@@ -149,6 +149,18 @@ void NetworkTraceHandler::OnStop(const StopArgs&) {
|
||||
if (mIsTest) return; // Don't touch non-hermetic bpf in test.
|
||||
if (mStarted) sPoller.Stop();
|
||||
mStarted = false;
|
||||
|
||||
// Although this shouldn't be required, there seems to be some cases when we
|
||||
// don't fill enough of a Perfetto Chunk for Perfetto to automatically commit
|
||||
// the traced data. This manually flushes OnStop so we commit at least once.
|
||||
NetworkTraceHandler::Trace([&](NetworkTraceHandler::TraceContext ctx) {
|
||||
perfetto::LockedHandle<NetworkTraceHandler> handle =
|
||||
ctx.GetDataSourceLocked();
|
||||
// Trace is called for all active handlers, only flush our context. Since
|
||||
// handle doesn't have a `.get()`, use `*` and `&` to get what it points to.
|
||||
if (&(*handle) != this) return;
|
||||
ctx.Flush();
|
||||
});
|
||||
}
|
||||
|
||||
void NetworkTraceHandler::Write(const std::vector<PacketTrace>& packets,
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
|
||||
#define LOG_TAG "NetworkTrace"
|
||||
#define ATRACE_TAG ATRACE_TAG_NETWORK
|
||||
|
||||
#include "netdbpf/NetworkTracePoller.h"
|
||||
|
||||
#include <bpf/BpfUtils.h>
|
||||
#include <cutils/trace.h>
|
||||
#include <log/log.h>
|
||||
#include <perfetto/tracing/platform.h>
|
||||
#include <perfetto/tracing/tracing.h>
|
||||
@@ -133,6 +135,8 @@ bool NetworkTracePoller::ConsumeAllLocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
ATRACE_INT("NetworkTracePackets", packets.size());
|
||||
|
||||
mCallback(packets);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user