From 88c93795203558e0d6edabba55098615fb75db55 Mon Sep 17 00:00:00 2001 From: Ryan Zuklie Date: Fri, 7 Apr 2023 09:50:22 -0700 Subject: [PATCH] Drain BPF ring buffer after disabling tracing. This should ensure that we don't have stale packets next time we start a trace. Bug: 246985031 Test: flash & trace with long (1m+) poll (used to get stale, now not) Change-Id: I6085d4a97688a221d26c095ef9073360292fd1ec --- .../native/libs/libnetworkstats/NetworkTracePoller.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service-t/native/libs/libnetworkstats/NetworkTracePoller.cpp b/service-t/native/libs/libnetworkstats/NetworkTracePoller.cpp index 5cf62627ee..3de98973f3 100644 --- a/service-t/native/libs/libnetworkstats/NetworkTracePoller.cpp +++ b/service-t/native/libs/libnetworkstats/NetworkTracePoller.cpp @@ -99,9 +99,14 @@ bool NetworkTracePoller::Stop() { ALOGW("Failed to disable tracing: %s", res.error().message().c_str()); } - // make sure everything in the system has actually seen the 'false' we just wrote + // Make sure everything in the system has actually seen the 'false' we just + // wrote, things should now be well and truly disabled. synchronizeKernelRCU(); - // things should now be well and truly disabled + + // Drain remaining events from the ring buffer now that tracing is disabled. + // This prevents the next trace from seeing stale events and allows writing + // the last batch of events to Perfetto. + ConsumeAllLocked(); mTaskRunner.reset(); mRingBuffer.reset();