• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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 "TransactionDataSource.h"
18 #include "TransactionTracing.h"
19 
20 #undef LOG_TAG
21 #define LOG_TAG "TransactionTracing"
22 
23 #include <log/log.h>
24 
25 namespace android {
26 
Initialize(TransactionTracing & transactionTracing)27 void TransactionDataSource::Initialize(TransactionTracing& transactionTracing) {
28     mTransactionTracing.store(&transactionTracing);
29 
30     auto args = perfetto::TracingInitArgs{};
31     args.backends = perfetto::kSystemBackend;
32     perfetto::Tracing::Initialize(args);
33 
34     perfetto::DataSourceDescriptor descriptor;
35     descriptor.set_name(kName);
36     TransactionDataSource::Register(descriptor);
37 }
38 
UnregisterTransactionTracing()39 void TransactionDataSource::UnregisterTransactionTracing() {
40     mTransactionTracing.store(nullptr);
41 }
42 
OnSetup(const TransactionDataSource::SetupArgs & args)43 void TransactionDataSource::OnSetup(const TransactionDataSource::SetupArgs& args) {
44     const auto configRaw = args.config->surfaceflinger_transactions_config_raw();
45     const auto config =
46             perfetto::protos::pbzero::SurfaceFlingerTransactionsConfig::Decoder{configRaw};
47 
48     if (config.has_mode() && config.mode() != TransactionTracing::Mode::MODE_UNSPECIFIED) {
49         mMode = static_cast<TransactionTracing::Mode>(config.mode());
50     } else {
51         mMode = TransactionTracing::Mode::MODE_CONTINUOUS;
52         ALOGD("Received config with unspecified 'mode'. Using 'CONTINUOUS' as default");
53     }
54 }
55 
OnStart(const StartArgs &)56 void TransactionDataSource::OnStart(const StartArgs&) {
57     ALOGD("Received OnStart event");
58     if (auto* p = mTransactionTracing.load()) {
59         p->onStart(mMode);
60     }
61 }
62 
OnFlush(const FlushArgs &)63 void TransactionDataSource::OnFlush(const FlushArgs&) {
64     ALOGD("Received OnFlush event");
65     if (auto* p = mTransactionTracing.load()) {
66         p->onFlush(mMode);
67     }
68 }
69 
OnStop(const StopArgs &)70 void TransactionDataSource::OnStop(const StopArgs&) {
71     ALOGD("Received OnStop event");
72 }
73 
GetMode() const74 TransactionTracing::Mode TransactionDataSource::GetMode() const {
75     return mMode;
76 }
77 
78 std::atomic<TransactionTracing*> TransactionDataSource::mTransactionTracing = nullptr;
79 
80 } // namespace android
81 
82 PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(android::TransactionDataSource);
83