Add support for concurrent data sources.
Perfetto allows multiple trace sessions to run in parallel. Each trace
session creates an instance of the registered DataSource. Bpf ring
buffers only support a single consumer, so we don't want multiple
instances reading concurrently.
This patch fixes things by making the DataSource a very thing wrapper
which delegates everything to a singleton. The singleton counts the
number of active sessions so that start is only called if not already
started, and stop is called if there are no remaining sessions.
Note: it's not clear whether it would be better to take the min or max
of poll_ms for active sessions. Min would be good for callers wanting
high throughput data collection, but doing so could jeopordise callers
using the poll_ms to limit the trace size (e.g. longer traces that are
alright dropping >5kpps scenarios). In this change, we use whichever
poll_ms was set first and make no promises.
Bug: 246985031
Test: atest libnetworkstats_test
Change-Id: Ic85cab2205e6d426bcfc913450edff50be373bb0
3 files changed