blob: 5ca87e4cb30f39cba1a008f1aed9ebb43f617700 [file] [log] [blame]
Vishnu Nair4df8eb62022-02-17 15:32:02 -08001/*
2 * Copyright (C) 2022 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 "LayerTraceGenerator"
19
20#include <fstream>
21#include <iostream>
22#include <string>
23
24#include "LayerTraceGenerator.h"
25
26using namespace android;
27
28int main(int argc, char** argv) {
Vishnu Nair52c4f252023-06-14 15:25:12 -070029 if (argc > 4) {
Vishnu Nair4df8eb62022-02-17 15:32:02 -080030 std::cout << "Usage: " << argv[0]
Vishnu Nair52c4f252023-06-14 15:25:12 -070031 << " [transaction-trace-path] [output-layers-trace-path] [--last-entry-only]\n";
Vishnu Nair4df8eb62022-02-17 15:32:02 -080032 return -1;
33 }
34
35 const char* transactionTracePath =
36 (argc > 1) ? argv[1] : "/data/misc/wmtrace/transactions_trace.winscope";
37 std::cout << "Parsing " << transactionTracePath << "\n";
38 std::fstream input(transactionTracePath, std::ios::in | std::ios::binary);
39 if (!input) {
40 std::cout << "Error: Could not open " << transactionTracePath;
41 return -1;
42 }
43
44 proto::TransactionTraceFile transactionTraceFile;
45 if (!transactionTraceFile.ParseFromIstream(&input)) {
46 std::cout << "Error: Failed to parse " << transactionTracePath;
47 return -1;
48 }
49
50 const char* outputLayersTracePath =
Vishnu Nair52c4f252023-06-14 15:25:12 -070051 (argc >= 3) ? argv[2] : "/data/misc/wmtrace/layers_trace.winscope";
52
53 const bool generateLastEntryOnly =
54 argc >= 4 && std::string_view(argv[3]) == "--last-entry-only";
55
Vishnu Nair4df8eb62022-02-17 15:32:02 -080056 ALOGD("Generating %s...", outputLayersTracePath);
57 std::cout << "Generating " << outputLayersTracePath << "\n";
Vishnu Nair5d60bbe2022-10-18 16:59:10 -070058
Vishnu Nair52c4f252023-06-14 15:25:12 -070059 if (!LayerTraceGenerator().generate(transactionTraceFile, outputLayersTracePath,
60 generateLastEntryOnly)) {
Vishnu Nair4df8eb62022-02-17 15:32:02 -080061 std::cout << "Error: Failed to generate layers trace " << outputLayersTracePath;
62 return -1;
63 }
64 return 0;
65}