• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/data_source.h"
18 #include "perfetto/base/logging.h"
19 
20 namespace perfetto {
21 
22 DataSourceBase::StopArgs::~StopArgs() = default;
23 DataSourceBase::FlushArgs::~FlushArgs() = default;
24 DataSourceBase::~DataSourceBase() = default;
OnSetup(const SetupArgs &)25 void DataSourceBase::OnSetup(const SetupArgs&) {}
OnStart(const StartArgs &)26 void DataSourceBase::OnStart(const StartArgs&) {}
OnStop(const StopArgs &)27 void DataSourceBase::OnStop(const StopArgs&) {}
WillClearIncrementalState(const ClearIncrementalStateArgs &)28 void DataSourceBase::WillClearIncrementalState(
29     const ClearIncrementalStateArgs&) {}
OnFlush(const FlushArgs &)30 void DataSourceBase::OnFlush(const FlushArgs&) {}
31 
32 namespace internal {
33 
PopulateTlsInst(DataSourceInstanceThreadLocalState * tls_inst,DataSourceState * instance_state,uint32_t instance_index)34 void DataSourceType::PopulateTlsInst(
35     DataSourceInstanceThreadLocalState* tls_inst,
36     DataSourceState* instance_state,
37     uint32_t instance_index) {
38   auto* tracing_impl = TracingMuxer::Get();
39   tls_inst->muxer_id_for_testing = instance_state->muxer_id_for_testing;
40   tls_inst->backend_id = instance_state->backend_id;
41   tls_inst->backend_connection_id = instance_state->backend_connection_id;
42   tls_inst->buffer_id = instance_state->buffer_id;
43   tls_inst->startup_target_buffer_reservation =
44       instance_state->startup_target_buffer_reservation.load(
45           std::memory_order_relaxed);
46   tls_inst->data_source_instance_id = instance_state->data_source_instance_id;
47   tls_inst->is_intercepted = instance_state->interceptor_id != 0;
48   tls_inst->trace_writer = tracing_impl->CreateTraceWriter(
49       &state_, instance_index, instance_state, buffer_exhausted_policy_);
50   if (create_incremental_state_fn_) {
51     PERFETTO_DCHECK(!tls_inst->incremental_state);
52     CreateIncrementalState(tls_inst, instance_index);
53   }
54   if (create_custom_tls_fn_) {
55     tls_inst->data_source_custom_tls =
56         create_custom_tls_fn_(tls_inst, instance_index, user_arg_);
57   }
58   // Even in the case of out-of-IDs, SharedMemoryArbiterImpl returns a
59   // NullTraceWriter. The returned pointer should never be null.
60   PERFETTO_DCHECK(tls_inst->trace_writer);
61 }
62 
63 }  // namespace internal
64 }  // namespace perfetto
65