Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | using namespace android; |
| 27 | |
| 28 | int main(int argc, char** argv) { |
Vishnu Nair | 52c4f25 | 2023-06-14 15:25:12 -0700 | [diff] [blame^] | 29 | if (argc > 4) { |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 30 | std::cout << "Usage: " << argv[0] |
Vishnu Nair | 52c4f25 | 2023-06-14 15:25:12 -0700 | [diff] [blame^] | 31 | << " [transaction-trace-path] [output-layers-trace-path] [--last-entry-only]\n"; |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 32 | 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 Nair | 52c4f25 | 2023-06-14 15:25:12 -0700 | [diff] [blame^] | 51 | (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 Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 56 | ALOGD("Generating %s...", outputLayersTracePath); |
| 57 | std::cout << "Generating " << outputLayersTracePath << "\n"; |
Vishnu Nair | 5d60bbe | 2022-10-18 16:59:10 -0700 | [diff] [blame] | 58 | |
Vishnu Nair | 52c4f25 | 2023-06-14 15:25:12 -0700 | [diff] [blame^] | 59 | if (!LayerTraceGenerator().generate(transactionTraceFile, outputLayersTracePath, |
| 60 | generateLastEntryOnly)) { |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 61 | std::cout << "Error: Failed to generate layers trace " << outputLayersTracePath; |
| 62 | return -1; |
| 63 | } |
| 64 | return 0; |
| 65 | } |