blob: fd8cb82a9ba8445944fe82f4875f4f707c922a5e [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
Chia-I Wua3e7ddc2018-09-20 11:42:46 -070023#include <memory>
Adrian Roos1e1a1282017-11-01 19:05:31 +010024#include <mutex>
25
26using namespace android::surfaceflinger;
27
28namespace android {
29
30/*
31 * SurfaceTracing records layer states during surface flinging.
32 */
33class SurfaceTracing {
34public:
35 void enable();
36 status_t disable();
Yichi Chenadc69612018-09-15 14:51:18 +080037 bool isEnabled() const;
Adrian Roos1e1a1282017-11-01 19:05:31 +010038
39 void traceLayers(const char* where, LayersProto);
Yichi Chenadc69612018-09-15 14:51:18 +080040 void dump(String8& result) const;
Adrian Roos1e1a1282017-11-01 19:05:31 +010041
42private:
Vishnu Nair36b4cdb2017-11-17 10:27:05 -080043 static constexpr auto DEFAULT_FILENAME = "/data/misc/wmtrace/layers_trace.pb";
Adrian Roos1e1a1282017-11-01 19:05:31 +010044
45 status_t writeProtoFileLocked();
46
47 bool mEnabled = false;
48 std::string mOutputFileName = DEFAULT_FILENAME;
Yichi Chenadc69612018-09-15 14:51:18 +080049 mutable std::mutex mTraceMutex;
Chia-I Wua3e7ddc2018-09-20 11:42:46 -070050 std::unique_ptr<LayersTraceFileProto> mTrace;
Adrian Roos1e1a1282017-11-01 19:05:31 +010051};
52
53} // namespace android