blob: bf5da527b6c54c58896d9bc673add0298578b5ad [file] [log] [blame]
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001/*
2 * Copyright 2016 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/*
18 * Replayer - Main.cpp
19 *
20 * 1. Get flags from command line
21 * 2. Commit actions or settings based on the flags
22 * 3. Initalize a replayer object with the filename passed in
23 * 4. Replay
24 * 5. Exit successfully or print error statement
25 */
26
27#include <replayer/Replayer.h>
28
29#include <csignal>
30#include <iostream>
31#include <stdlib.h>
32#include <unistd.h>
33
34using namespace android;
35
36void printHelpMenu() {
37 std::cout << "SurfaceReplayer options:\n";
38 std::cout << "Usage: surfacereplayer [OPTIONS...] <TRACE FILE>\n";
39 std::cout << " File path must be absolute" << std::endl << std::endl;
40
41 std::cout << " -m Stops the replayer at the start of the trace and switches ";
42 "to manual replay\n";
43
44 std::cout << " -t [Number of Threads] Specifies the number of threads to be used while "
45 "replaying (default is " << android::DEFAULT_THREADS << ")\n";
46
47 std::cout << " -h Display help menu\n";
48
49 std::cout << std::endl;
50}
51
52int main(int argc, char** argv) {
53 std::string filename;
54 bool pauseBeginning = false;
55 int numThreads = DEFAULT_THREADS;
56
57 int opt = 0;
58 while ((opt = getopt(argc, argv, "pt:h?")) != -1) {
59 switch (opt) {
60 case 'm':
61 pauseBeginning = true;
62 break;
63 case 't':
64 numThreads = atoi(optarg);
65 break;
66 case 'h':
67 case '?':
68 printHelpMenu();
69 exit(0);
70 default:
71 std::cerr << "Invalid argument...exiting" << std::endl;
72 printHelpMenu();
73 exit(0);
74 }
75 }
76
77 char** input = argv + optind;
78 if (input[0] == NULL) {
79 std::cerr << "No trace file provided...exiting" << std::endl;
80 abort();
81 }
82 filename.assign(input[0]);
83
84 android::Replayer r(filename, pauseBeginning, numThreads);
85 auto status = r.replay();
86
87 if (status == NO_ERROR) {
88 std::cout << "Successfully finished replaying trace" << std::endl;
89 } else {
90 std::cerr << "Trace replayer returned error: " << status << std::endl;
91 }
92
93 return 0;
94}