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