xref: /aosp_15_r20/external/perfetto/src/tracing/virtual_destructors.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker /*
2*6dbdd20aSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*6dbdd20aSAndroid Build Coastguard Worker  *
4*6dbdd20aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*6dbdd20aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*6dbdd20aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*6dbdd20aSAndroid Build Coastguard Worker  *
8*6dbdd20aSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*6dbdd20aSAndroid Build Coastguard Worker  *
10*6dbdd20aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*6dbdd20aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*6dbdd20aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*6dbdd20aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*6dbdd20aSAndroid Build Coastguard Worker  * limitations under the License.
15*6dbdd20aSAndroid Build Coastguard Worker  */
16*6dbdd20aSAndroid Build Coastguard Worker 
17*6dbdd20aSAndroid Build Coastguard Worker #include "perfetto/tracing/internal/tracing_tls.h"
18*6dbdd20aSAndroid Build Coastguard Worker #include "perfetto/tracing/tracing.h"
19*6dbdd20aSAndroid Build Coastguard Worker #include "perfetto/tracing/tracing_backend.h"
20*6dbdd20aSAndroid Build Coastguard Worker 
21*6dbdd20aSAndroid Build Coastguard Worker // This translation unit contains the definitions for the destructor of pure
22*6dbdd20aSAndroid Build Coastguard Worker // virtual interfaces for the src/public:public target. The alternative would be
23*6dbdd20aSAndroid Build Coastguard Worker // introducing a one-liner .cc file for each pure virtual interface, which is
24*6dbdd20aSAndroid Build Coastguard Worker // overkill. This is for compliance with -Wweak-vtables.
25*6dbdd20aSAndroid Build Coastguard Worker 
26*6dbdd20aSAndroid Build Coastguard Worker namespace perfetto {
27*6dbdd20aSAndroid Build Coastguard Worker namespace internal {
28*6dbdd20aSAndroid Build Coastguard Worker 
~TracingTLS()29*6dbdd20aSAndroid Build Coastguard Worker TracingTLS::~TracingTLS() {
30*6dbdd20aSAndroid Build Coastguard Worker   // Avoid entering trace points while the thread is being torn down.
31*6dbdd20aSAndroid Build Coastguard Worker   // This is the problem: when a thread exits, the at-thread-exit destroys the
32*6dbdd20aSAndroid Build Coastguard Worker   // TracingTLS. As part of that the various TraceWriter for the active data
33*6dbdd20aSAndroid Build Coastguard Worker   // sources are destroyd. A TraceWriter dtor will issue a PostTask on the IPC
34*6dbdd20aSAndroid Build Coastguard Worker   // thread to issue a final flush and unregister its ID with the service.
35*6dbdd20aSAndroid Build Coastguard Worker   // The PostTask, in chromium, might have a trace event that will try to
36*6dbdd20aSAndroid Build Coastguard Worker   // re-enter the tracing system.
37*6dbdd20aSAndroid Build Coastguard Worker   // We fix this by resetting the TLS key to the TracingTLS object that is
38*6dbdd20aSAndroid Build Coastguard Worker   // being destroyed in the platform impl (platform_posix.cc,
39*6dbdd20aSAndroid Build Coastguard Worker   // platform_windows.cc, chromium's platform.cc). We carefully rely on the fact
40*6dbdd20aSAndroid Build Coastguard Worker   // that all the tracing path that will be invoked during thread exit will
41*6dbdd20aSAndroid Build Coastguard Worker   // early out if |is_in_trace_point| == true and will not depend on the other
42*6dbdd20aSAndroid Build Coastguard Worker   // TLS state that has been destroyed.
43*6dbdd20aSAndroid Build Coastguard Worker   is_in_trace_point = true;
44*6dbdd20aSAndroid Build Coastguard Worker }
45*6dbdd20aSAndroid Build Coastguard Worker 
46*6dbdd20aSAndroid Build Coastguard Worker }  // namespace internal
47*6dbdd20aSAndroid Build Coastguard Worker 
48*6dbdd20aSAndroid Build Coastguard Worker TracingProducerBackend::~TracingProducerBackend() = default;
49*6dbdd20aSAndroid Build Coastguard Worker TracingConsumerBackend::~TracingConsumerBackend() = default;
50*6dbdd20aSAndroid Build Coastguard Worker TracingBackend::~TracingBackend() = default;
51*6dbdd20aSAndroid Build Coastguard Worker 
52*6dbdd20aSAndroid Build Coastguard Worker }  // namespace perfetto
53