blob: 11bb9f45df451aa69830476c7cc79051186042ca [file] [log] [blame]
Vishnu Nair00b90132021-11-05 14:03:40 -07001/*
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
19#include <android-base/thread_annotations.h>
20#include <layerproto/LayerProtoHeader.h>
21#include <utils/Errors.h>
22#include <utils/StrongPointer.h>
23#include <utils/Timers.h>
24
25#include <memory>
26#include <mutex>
27
28using namespace android::surfaceflinger;
29
30namespace android {
31
32template <typename FileProto, typename EntryProto>
33class RingBuffer;
34
35class SurfaceFlinger;
36
37/*
38 * LayerTracing records layer states during surface flinging. Manages tracing state and
39 * configuration.
40 */
41class LayerTracing {
42public:
Vishnu Nair81750622023-03-08 15:02:06 -080043 LayerTracing();
Vishnu Nair00b90132021-11-05 14:03:40 -070044 ~LayerTracing();
45 bool enable();
Vishnu Naird8f5e9f2022-02-03 10:23:28 -080046 bool disable(std::string filename = FILE_NAME);
Vishnu Nair00b90132021-11-05 14:03:40 -070047 bool isEnabled() const;
48 status_t writeToFile();
Vishnu Nair81750622023-03-08 15:02:06 -080049 static LayersTraceFileProto createTraceFileProto();
50 void notify(bool visibleRegionDirty, int64_t time, int64_t vsyncId, LayersProto* layers,
51 std::string hwcDump, google::protobuf::RepeatedPtrField<DisplayProto>* displays);
Vishnu Nair00b90132021-11-05 14:03:40 -070052
53 enum : uint32_t {
54 TRACE_INPUT = 1 << 1,
55 TRACE_COMPOSITION = 1 << 2,
56 TRACE_EXTRA = 1 << 3,
57 TRACE_HWC = 1 << 4,
58 TRACE_BUFFERS = 1 << 5,
Nataniel Borges63b3c872022-11-03 16:22:24 +000059 TRACE_VIRTUAL_DISPLAYS = 1 << 6,
Vishnu Nair00b90132021-11-05 14:03:40 -070060 TRACE_ALL = TRACE_INPUT | TRACE_COMPOSITION | TRACE_EXTRA,
61 };
62 void setTraceFlags(uint32_t flags);
63 bool flagIsSet(uint32_t flags) const;
Vishnu Nair81750622023-03-08 15:02:06 -080064 uint32_t getFlags() const;
Vishnu Nair00b90132021-11-05 14:03:40 -070065 void setBufferSize(size_t bufferSizeInBytes);
66 void dump(std::string&) const;
67
68private:
69 static constexpr auto FILE_NAME = "/data/misc/wmtrace/layers_trace.winscope";
Vishnu Nair00b90132021-11-05 14:03:40 -070070 uint32_t mFlags = TRACE_INPUT;
71 mutable std::mutex mTraceLock;
72 bool mEnabled GUARDED_BY(mTraceLock) = false;
73 std::unique_ptr<RingBuffer<LayersTraceFileProto, LayersTraceProto>> mBuffer
74 GUARDED_BY(mTraceLock);
75 size_t mBufferSizeInBytes GUARDED_BY(mTraceLock) = 20 * 1024 * 1024;
76};
77
78} // namespace android