aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrimiano Tucci <primiano@google.com>2023-06-12 20:00:04 +0100
committerDaniele Di Proietto <ddiproietto@google.com>2023-06-13 17:19:12 +0000
commited4fc107ea674cc50f1c70a89d4f079c52419cc6 (patch)
tree59b83e52d26f35612b316bc7ddf8eb0fefde9893
parent9bf4017e70115c08316b0c197972a1f736abcf25 (diff)
downloadperfetto-ed4fc107ea674cc50f1c70a89d4f079c52419cc6.tar.gz
traced: preserve UUID LSB when cloning a session
The LSB is used to correlate tracing sessions with statsd subscriptions. Retain the LSB to avoid breaking downstream pipelines that depend on this. Bug: b/260112703 Bug: 287071990 Test: TracingServiceImplTest.CloneSession (cherry picked from https://android-review.googlesource.com/q/commit:8755774a3fbe4e8c664a6436eb4fd9ea5e34a297) Merged-In: I4c512701143a21ac1b01a2f785ebe005e9983556 Change-Id: I4c512701143a21ac1b01a2f785ebe005e9983556
-rw-r--r--src/tracing/core/tracing_service_impl.cc8
-rw-r--r--src/tracing/core/tracing_service_impl_unittest.cc9
2 files changed, 14 insertions, 3 deletions
diff --git a/src/tracing/core/tracing_service_impl.cc b/src/tracing/core/tracing_service_impl.cc
index b32a65854..16ef09e7c 100644
--- a/src/tracing/core/tracing_service_impl.cc
+++ b/src/tracing/core/tracing_service_impl.cc
@@ -3614,8 +3614,14 @@ base::Status TracingServiceImpl::DoCloneSession(ConsumerEndpointImpl* consumer,
std::forward_as_tuple(tsid, consumer, src->config, task_runner_))
.first->second;
+ // Generate a new UUID for the cloned session, but preserve the LSB. In some
+ // contexts the LSB is used to tie the trace back to the statsd subscription
+ // that triggered it. See the corresponding code in perfetto_cmd.cc which
+ // reads at triggering_subscription_id().
+ const int64_t orig_uuid_lsb = src->trace_uuid.lsb();
cloned_session->state = TracingSession::CLONED_READ_ONLY;
- cloned_session->trace_uuid = base::Uuidv4(); // Generate a new UUID.
+ cloned_session->trace_uuid = base::Uuidv4();
+ cloned_session->trace_uuid.set_lsb(orig_uuid_lsb);
*new_uuid = cloned_session->trace_uuid;
for (auto& kv : buf_snaps) {
diff --git a/src/tracing/core/tracing_service_impl_unittest.cc b/src/tracing/core/tracing_service_impl_unittest.cc
index fb175e990..dcfcfa6c1 100644
--- a/src/tracing/core/tracing_service_impl_unittest.cc
+++ b/src/tracing/core/tracing_service_impl_unittest.cc
@@ -4419,6 +4419,8 @@ TEST_F(TracingServiceImplTest, CloneSession) {
TraceConfig trace_config;
trace_config.add_buffers()->set_size_kb(32); // Buf 0.
trace_config.add_buffers()->set_size_kb(32); // Buf 1.
+ trace_config.set_trace_uuid_lsb(4242);
+ trace_config.set_trace_uuid_msb(3737);
auto* ds_cfg = trace_config.add_data_sources()->mutable_config();
ds_cfg->set_name("ds_1");
ds_cfg->set_target_buffer(0);
@@ -4469,8 +4471,11 @@ TEST_F(TracingServiceImplTest, CloneSession) {
[clone_done, &clone_uuid](const Consumer::OnSessionClonedArgs& args) {
ASSERT_TRUE(args.success);
ASSERT_TRUE(args.error.empty());
- ASSERT_NE(args.uuid.msb(), 0);
- ASSERT_NE(args.uuid.lsb(), 0);
+ // Ensure the LSB is preserved, but the MSB is different. See
+ // comments in tracing_service_impl.cc and perfetto_cmd.cc around
+ // triggering_subscription_id().
+ ASSERT_EQ(args.uuid.lsb(), 4242);
+ ASSERT_NE(args.uuid.msb(), 3737);
clone_uuid = args.uuid;
clone_done();
}));