blob: 27e2c9e696ab8731d61a7d4f67699176b648e57b [file] [log] [blame]
Adrian Roos1e1a1282017-11-01 19:05:31 +01001/*
2 * Copyright 2017 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 <layerproto/LayerProtoHeader.h>
20#include <utils/Errors.h>
Yichi Chenadc69612018-09-15 14:51:18 +080021#include <utils/String8.h>
Adrian Roos1e1a1282017-11-01 19:05:31 +010022
23#include <mutex>
24
25using namespace android::surfaceflinger;
26
27namespace android {
28
29/*
30 * SurfaceTracing records layer states during surface flinging.
31 */
32class SurfaceTracing {
33public:
34 void enable();
35 status_t disable();
Yichi Chenadc69612018-09-15 14:51:18 +080036 bool isEnabled() const;
Adrian Roos1e1a1282017-11-01 19:05:31 +010037
38 void traceLayers(const char* where, LayersProto);
Yichi Chenadc69612018-09-15 14:51:18 +080039 void dump(String8& result) const;
Adrian Roos1e1a1282017-11-01 19:05:31 +010040
41private:
Vishnu Nair36b4cdb2017-11-17 10:27:05 -080042 static constexpr auto DEFAULT_FILENAME = "/data/misc/wmtrace/layers_trace.pb";
Adrian Roos1e1a1282017-11-01 19:05:31 +010043
44 status_t writeProtoFileLocked();
45
46 bool mEnabled = false;
47 std::string mOutputFileName = DEFAULT_FILENAME;
Yichi Chenadc69612018-09-15 14:51:18 +080048 mutable std::mutex mTraceMutex;
Adrian Roos1e1a1282017-11-01 19:05:31 +010049 LayersTraceFileProto mTrace;
50};
51
52} // namespace android