Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 | #undef LOG_TAG |
| 18 | #define LOG_TAG "TransactionTracing" |
| 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 20 | |
| 21 | #include <android-base/stringprintf.h> |
| 22 | #include <log/log.h> |
| 23 | #include <utils/SystemClock.h> |
| 24 | #include <utils/Trace.h> |
| 25 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 26 | #include "TransactionTracing.h" |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | TransactionTracing::TransactionTracing() { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 31 | std::scoped_lock lock(mTraceLock); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 32 | |
| 33 | mBuffer.setSize(mBufferSizeInBytes); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 34 | mStartingTimestamp = systemTime(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 35 | { |
| 36 | std::scoped_lock lock(mMainThreadLock); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 37 | mThread = std::thread(&TransactionTracing::loop, this); |
| 38 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 41 | TransactionTracing::~TransactionTracing() { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 42 | std::thread thread; |
| 43 | { |
| 44 | std::scoped_lock lock(mMainThreadLock); |
| 45 | mDone = true; |
| 46 | mTransactionsAvailableCv.notify_all(); |
| 47 | thread = std::move(mThread); |
| 48 | } |
| 49 | if (thread.joinable()) { |
| 50 | thread.join(); |
| 51 | } |
| 52 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 53 | writeToFile(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | status_t TransactionTracing::writeToFile() { |
| 57 | std::scoped_lock lock(mTraceLock); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 58 | proto::TransactionTraceFile fileProto = createTraceFileProto(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 59 | addStartingStateToProtoLocked(fileProto); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 60 | return mBuffer.writeToFile(fileProto, FILE_NAME); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void TransactionTracing::setBufferSize(size_t bufferSizeInBytes) { |
| 64 | std::scoped_lock lock(mTraceLock); |
| 65 | mBufferSizeInBytes = bufferSizeInBytes; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 66 | mBuffer.setSize(mBufferSizeInBytes); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | proto::TransactionTraceFile TransactionTracing::createTraceFileProto() const { |
| 70 | proto::TransactionTraceFile proto; |
| 71 | proto.set_magic_number(uint64_t(proto::TransactionTraceFile_MagicNumber_MAGIC_NUMBER_H) << 32 | |
| 72 | proto::TransactionTraceFile_MagicNumber_MAGIC_NUMBER_L); |
| 73 | return proto; |
| 74 | } |
| 75 | |
| 76 | void TransactionTracing::dump(std::string& result) const { |
| 77 | std::scoped_lock lock(mTraceLock); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 78 | base::StringAppendF(&result, |
| 79 | " queued transactions=%zu created layers=%zu handles=%zu states=%zu\n", |
| 80 | mQueuedTransactions.size(), mCreatedLayers.size(), mLayerHandles.size(), |
| 81 | mStartingStates.size()); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 82 | mBuffer.dump(result); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void TransactionTracing::addQueuedTransaction(const TransactionState& transaction) { |
| 86 | std::scoped_lock lock(mTraceLock); |
| 87 | ATRACE_CALL(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 88 | mQueuedTransactions[transaction.id] = |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 89 | TransactionProtoParser::toProto(transaction, |
| 90 | std::bind(&TransactionTracing::getLayerIdLocked, this, |
| 91 | std::placeholders::_1), |
| 92 | nullptr); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void TransactionTracing::addCommittedTransactions(std::vector<TransactionState>& transactions, |
| 96 | int64_t vsyncId) { |
| 97 | CommittedTransactions committedTransactions; |
| 98 | committedTransactions.vsyncId = vsyncId; |
| 99 | committedTransactions.timestamp = systemTime(); |
| 100 | committedTransactions.transactionIds.reserve(transactions.size()); |
| 101 | for (const auto& transaction : transactions) { |
| 102 | committedTransactions.transactionIds.emplace_back(transaction.id); |
| 103 | } |
| 104 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 105 | mPendingTransactions.emplace_back(committedTransactions); |
| 106 | tryPushToTracingThread(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void TransactionTracing::loop() { |
| 110 | while (true) { |
| 111 | std::vector<CommittedTransactions> committedTransactions; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 112 | std::vector<int32_t> removedLayers; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 113 | { |
| 114 | std::unique_lock<std::mutex> lock(mMainThreadLock); |
| 115 | base::ScopedLockAssertion assumeLocked(mMainThreadLock); |
| 116 | mTransactionsAvailableCv.wait(lock, [&]() REQUIRES(mMainThreadLock) { |
| 117 | return mDone || !mCommittedTransactions.empty(); |
| 118 | }); |
| 119 | if (mDone) { |
| 120 | mCommittedTransactions.clear(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 121 | mRemovedLayers.clear(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 122 | break; |
| 123 | } |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 124 | |
| 125 | removedLayers = std::move(mRemovedLayers); |
| 126 | mRemovedLayers.clear(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 127 | committedTransactions = std::move(mCommittedTransactions); |
| 128 | mCommittedTransactions.clear(); |
| 129 | } // unlock mMainThreadLock |
| 130 | |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 131 | if (!committedTransactions.empty() || !removedLayers.empty()) { |
| 132 | addEntry(committedTransactions, removedLayers); |
| 133 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 137 | void TransactionTracing::addEntry(const std::vector<CommittedTransactions>& committedTransactions, |
| 138 | const std::vector<int32_t>& removedLayers) { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 139 | ATRACE_CALL(); |
| 140 | std::scoped_lock lock(mTraceLock); |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 141 | std::vector<std::string> removedEntries; |
| 142 | proto::TransactionTraceEntry entryProto; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 143 | for (const CommittedTransactions& entry : committedTransactions) { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 144 | entryProto.set_elapsed_realtime_nanos(entry.timestamp); |
| 145 | entryProto.set_vsync_id(entry.vsyncId); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 146 | entryProto.mutable_added_layers()->Reserve(static_cast<int32_t>(mCreatedLayers.size())); |
| 147 | for (auto& newLayer : mCreatedLayers) { |
| 148 | entryProto.mutable_added_layers()->Add(std::move(newLayer)); |
| 149 | } |
| 150 | entryProto.mutable_removed_layers()->Reserve(static_cast<int32_t>(removedLayers.size())); |
| 151 | for (auto& removedLayer : removedLayers) { |
| 152 | entryProto.mutable_removed_layers()->Add(removedLayer); |
| 153 | } |
| 154 | mCreatedLayers.clear(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 155 | entryProto.mutable_transactions()->Reserve( |
| 156 | static_cast<int32_t>(entry.transactionIds.size())); |
| 157 | for (const uint64_t& id : entry.transactionIds) { |
| 158 | auto it = mQueuedTransactions.find(id); |
| 159 | if (it != mQueuedTransactions.end()) { |
| 160 | entryProto.mutable_transactions()->Add(std::move(it->second)); |
| 161 | mQueuedTransactions.erase(it); |
| 162 | } else { |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 163 | ALOGW("Could not find transaction id %" PRIu64, id); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 164 | } |
| 165 | } |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 166 | |
| 167 | std::string serializedProto; |
| 168 | entryProto.SerializeToString(&serializedProto); |
| 169 | entryProto.Clear(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 170 | std::vector<std::string> entries = mBuffer.emplace(std::move(serializedProto)); |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 171 | removedEntries.reserve(removedEntries.size() + entries.size()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 172 | removedEntries.insert(removedEntries.end(), std::make_move_iterator(entries.begin()), |
| 173 | std::make_move_iterator(entries.end())); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 174 | |
| 175 | entryProto.mutable_removed_layer_handles()->Reserve( |
| 176 | static_cast<int32_t>(mRemovedLayerHandles.size())); |
| 177 | for (auto& handle : mRemovedLayerHandles) { |
| 178 | entryProto.mutable_removed_layer_handles()->Add(handle); |
| 179 | } |
| 180 | mRemovedLayerHandles.clear(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 183 | proto::TransactionTraceEntry removedEntryProto; |
| 184 | for (const std::string& removedEntry : removedEntries) { |
| 185 | removedEntryProto.ParseFromString(removedEntry); |
| 186 | updateStartingStateLocked(removedEntryProto); |
| 187 | removedEntryProto.Clear(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 188 | } |
| 189 | mTransactionsAddedToBufferCv.notify_one(); |
| 190 | } |
| 191 | |
| 192 | void TransactionTracing::flush(int64_t vsyncId) { |
| 193 | while (!mPendingTransactions.empty() || !mPendingRemovedLayers.empty()) { |
| 194 | tryPushToTracingThread(); |
| 195 | } |
| 196 | std::unique_lock<std::mutex> lock(mTraceLock); |
| 197 | base::ScopedLockAssertion assumeLocked(mTraceLock); |
| 198 | mTransactionsAddedToBufferCv.wait(lock, [&]() REQUIRES(mTraceLock) { |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 199 | proto::TransactionTraceEntry entry; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 200 | if (mBuffer.used() > 0) { |
| 201 | entry.ParseFromString(mBuffer.back()); |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 202 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 203 | return mBuffer.used() > 0 && entry.vsync_id() >= vsyncId; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 204 | }); |
| 205 | } |
| 206 | |
| 207 | void TransactionTracing::onLayerAdded(BBinder* layerHandle, int layerId, const std::string& name, |
| 208 | uint32_t flags, int parentId) { |
| 209 | std::scoped_lock lock(mTraceLock); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 210 | TracingLayerCreationArgs args{layerId, name, flags, parentId, -1 /* mirrorFromId */}; |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 211 | if (mLayerHandles.find(layerHandle) != mLayerHandles.end()) { |
| 212 | ALOGW("Duplicate handles found. %p", layerHandle); |
| 213 | } |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 214 | mLayerHandles[layerHandle] = layerId; |
| 215 | proto::LayerCreationArgs protoArgs = TransactionProtoParser::toProto(args); |
| 216 | proto::LayerCreationArgs protoArgsCopy = protoArgs; |
| 217 | mCreatedLayers.push_back(protoArgs); |
| 218 | } |
| 219 | |
| 220 | void TransactionTracing::onMirrorLayerAdded(BBinder* layerHandle, int layerId, |
| 221 | const std::string& name, int mirrorFromId) { |
| 222 | std::scoped_lock lock(mTraceLock); |
| 223 | TracingLayerCreationArgs args{layerId, name, 0 /* flags */, -1 /* parentId */, mirrorFromId}; |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 224 | if (mLayerHandles.find(layerHandle) != mLayerHandles.end()) { |
| 225 | ALOGW("Duplicate handles found. %p", layerHandle); |
| 226 | } |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 227 | mLayerHandles[layerHandle] = layerId; |
| 228 | mCreatedLayers.emplace_back(TransactionProtoParser::toProto(args)); |
| 229 | } |
| 230 | |
| 231 | void TransactionTracing::onLayerRemoved(int32_t layerId) { |
| 232 | mPendingRemovedLayers.emplace_back(layerId); |
| 233 | tryPushToTracingThread(); |
| 234 | } |
| 235 | |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 236 | void TransactionTracing::onHandleRemoved(BBinder* layerHandle) { |
| 237 | std::scoped_lock lock(mTraceLock); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 238 | auto it = mLayerHandles.find(layerHandle); |
| 239 | if (it == mLayerHandles.end()) { |
| 240 | ALOGW("handle not found. %p", layerHandle); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | mRemovedLayerHandles.push_back(it->second); |
| 245 | mLayerHandles.erase(it); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 248 | void TransactionTracing::tryPushToTracingThread() { |
| 249 | // Try to acquire the lock from main thread. |
| 250 | if (mMainThreadLock.try_lock()) { |
| 251 | // We got the lock! Collect any pending transactions and continue. |
| 252 | mCommittedTransactions.insert(mCommittedTransactions.end(), |
| 253 | std::make_move_iterator(mPendingTransactions.begin()), |
| 254 | std::make_move_iterator(mPendingTransactions.end())); |
| 255 | mPendingTransactions.clear(); |
| 256 | mRemovedLayers.insert(mRemovedLayers.end(), mPendingRemovedLayers.begin(), |
| 257 | mPendingRemovedLayers.end()); |
| 258 | mPendingRemovedLayers.clear(); |
| 259 | mTransactionsAvailableCv.notify_one(); |
| 260 | mMainThreadLock.unlock(); |
| 261 | } else { |
| 262 | ALOGV("Couldn't get lock"); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 266 | int32_t TransactionTracing::getLayerIdLocked(const sp<IBinder>& layerHandle) { |
| 267 | if (layerHandle == nullptr) { |
| 268 | return -1; |
| 269 | } |
| 270 | auto it = mLayerHandles.find(layerHandle->localBinder()); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 271 | if (it == mLayerHandles.end()) { |
| 272 | ALOGW("Could not find layer handle %p", layerHandle->localBinder()); |
| 273 | return -1; |
| 274 | } |
| 275 | return it->second; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void TransactionTracing::updateStartingStateLocked( |
| 279 | const proto::TransactionTraceEntry& removedEntry) { |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 280 | mStartingTimestamp = removedEntry.elapsed_realtime_nanos(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 281 | // Keep track of layer starting state so we can reconstruct the layer state as we purge |
| 282 | // transactions from the buffer. |
| 283 | for (const proto::LayerCreationArgs& addedLayer : removedEntry.added_layers()) { |
| 284 | TracingLayerState& startingState = mStartingStates[addedLayer.layer_id()]; |
| 285 | startingState.layerId = addedLayer.layer_id(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 286 | TransactionProtoParser::fromProto(addedLayer, startingState.args); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // Merge layer states to starting transaction state. |
| 290 | for (const proto::TransactionState& transaction : removedEntry.transactions()) { |
| 291 | for (const proto::LayerState& layerState : transaction.layer_changes()) { |
| 292 | auto it = mStartingStates.find(layerState.layer_id()); |
| 293 | if (it == mStartingStates.end()) { |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 294 | ALOGW("Could not find layer id %d", layerState.layer_id()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 295 | continue; |
| 296 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 297 | TransactionProtoParser::mergeFromProto(layerState, nullptr, it->second); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | // Clean up stale starting states since the layer has been removed and the buffer does not |
| 302 | // contain any references to the layer. |
| 303 | for (const int32_t removedLayerId : removedEntry.removed_layers()) { |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 304 | mStartingStates.erase(removedLayerId); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | void TransactionTracing::addStartingStateToProtoLocked(proto::TransactionTraceFile& proto) { |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 309 | if (mStartingStates.size() == 0) { |
| 310 | return; |
| 311 | } |
| 312 | |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 313 | proto::TransactionTraceEntry* entryProto = proto.add_entry(); |
| 314 | entryProto->set_elapsed_realtime_nanos(mStartingTimestamp); |
| 315 | entryProto->set_vsync_id(0); |
| 316 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 317 | entryProto->mutable_added_layers()->Reserve(static_cast<int32_t>(mStartingStates.size())); |
| 318 | for (auto& [layerId, state] : mStartingStates) { |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 319 | entryProto->mutable_added_layers()->Add(TransactionProtoParser::toProto(state.args)); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | proto::TransactionState transactionProto = TransactionProtoParser::toProto(mStartingStates); |
| 323 | transactionProto.set_vsync_id(0); |
| 324 | transactionProto.set_post_time(mStartingTimestamp); |
| 325 | entryProto->mutable_transactions()->Add(std::move(transactionProto)); |
| 326 | } |
| 327 | |
| 328 | proto::TransactionTraceFile TransactionTracing::writeToProto() { |
| 329 | std::scoped_lock<std::mutex> lock(mTraceLock); |
| 330 | proto::TransactionTraceFile proto = createTraceFileProto(); |
| 331 | addStartingStateToProtoLocked(proto); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 332 | mBuffer.writeToProto(proto); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 333 | return proto; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | } // namespace android |