blob: 6c9ed301ff59aea3eb5e62bbe3f15e286be91c77 [file] [log] [blame]
Kean Mariotti3e68a202023-04-19 13:41:55 +00001/*
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
25namespace android {
26
27void 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
39void TransactionDataSource::UnregisterTransactionTracing() {
40 mTransactionTracing.store(nullptr);
41}
42
43void 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;
Kean Mariotti8c5abc82023-09-20 09:28:07 +000052 ALOGD("Received config with unspecified 'mode'. Using 'CONTINUOUS' as default");
Kean Mariotti3e68a202023-04-19 13:41:55 +000053 }
54}
55
56void TransactionDataSource::OnStart(const StartArgs&) {
Kean Mariotti8c5abc82023-09-20 09:28:07 +000057 ALOGD("Received OnStart event");
Kean Mariotti3e68a202023-04-19 13:41:55 +000058 if (auto* p = mTransactionTracing.load()) {
59 p->onStart(mMode);
60 }
61}
62
63void TransactionDataSource::OnFlush(const FlushArgs&) {
Kean Mariotti8c5abc82023-09-20 09:28:07 +000064 ALOGD("Received OnFlush event");
Kean Mariotti3e68a202023-04-19 13:41:55 +000065 if (auto* p = mTransactionTracing.load()) {
66 p->onFlush(mMode);
67 }
68}
69
70void TransactionDataSource::OnStop(const StopArgs&) {
Kean Mariotti8c5abc82023-09-20 09:28:07 +000071 ALOGD("Received OnStop event");
Kean Mariotti3e68a202023-04-19 13:41:55 +000072}
73
74TransactionTracing::Mode TransactionDataSource::GetMode() const {
75 return mMode;
76}
77
78std::atomic<TransactionTracing*> TransactionDataSource::mTransactionTracing = nullptr;
79
80} // namespace android
81
82PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(android::TransactionDataSource);