Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [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 | #pragma once |
| 18 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 19 | #include <android-base/thread_annotations.h> |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 20 | #include <layerproto/LayerProtoHeader.h> |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 21 | #include <utils/Errors.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | #include <utils/Timers.h> |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 24 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 25 | #include <memory> |
| 26 | #include <mutex> |
| 27 | |
| 28 | using namespace android::surfaceflinger; |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 32 | template <typename FileProto, typename EntryProto> |
| 33 | class TransactionRingBuffer; |
| 34 | |
| 35 | class SurfaceFlinger; |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * LayerTracing records layer states during surface flinging. Manages tracing state and |
| 39 | * configuration. |
| 40 | */ |
| 41 | class LayerTracing { |
| 42 | public: |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 43 | LayerTracing(); |
| 44 | ~LayerTracing(); |
| 45 | bool enable(); |
| 46 | bool disable(std::string filename = FILE_NAME, bool writeToFile = true); |
| 47 | void appendToStream(std::ofstream& out); |
| 48 | bool isEnabled() const; |
| 49 | status_t writeToFile(std::string filename = FILE_NAME); |
| 50 | static LayersTraceFileProto createTraceFileProto(); |
| 51 | void notify(bool visibleRegionDirty, int64_t time, int64_t vsyncId, LayersProto* layers, |
| 52 | std::string hwcDump, google::protobuf::RepeatedPtrField<DisplayProto>* displays); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 53 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 54 | enum : uint32_t { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 55 | TRACE_INPUT = 1 << 1, |
| 56 | TRACE_COMPOSITION = 1 << 2, |
| 57 | TRACE_EXTRA = 1 << 3, |
| 58 | TRACE_HWC = 1 << 4, |
| 59 | TRACE_BUFFERS = 1 << 5, |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 60 | TRACE_VIRTUAL_DISPLAYS = 1 << 6, |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 61 | TRACE_ALL = TRACE_INPUT | TRACE_COMPOSITION | TRACE_EXTRA, |
| 62 | }; |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 63 | void setTraceFlags(uint32_t flags); |
| 64 | bool flagIsSet(uint32_t flags) const; |
| 65 | uint32_t getFlags() const; |
| 66 | void setBufferSize(size_t bufferSizeInBytes); |
| 67 | void dump(std::string&) const; |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 70 | static constexpr auto FILE_NAME = "/data/misc/wmtrace/layers_trace.winscope"; |
| 71 | uint32_t mFlags = TRACE_INPUT; |
| 72 | mutable std::mutex mTraceLock; |
| 73 | bool mEnabled GUARDED_BY(mTraceLock) = false; |
| 74 | std::unique_ptr<TransactionRingBuffer<LayersTraceFileProto, LayersTraceProto>> mBuffer |
| 75 | GUARDED_BY(mTraceLock); |
| 76 | size_t mBufferSizeInBytes GUARDED_BY(mTraceLock) = 20 * 1024 * 1024; |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace android |