| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file provides a thin binary wrapper around the BattOr Agent | 5 // This file provides a thin binary wrapper around the BattOr Agent |
| 6 // library. This binary wrapper provides a means for non-C++ tracing | 6 // library. This binary wrapper provides a means for non-C++ tracing |
| 7 // controllers, such as Telemetry and Android Systrace, to issue high-level | 7 // controllers, such as Telemetry and Android Systrace, to issue high-level |
| 8 // tracing commands to the BattOr through an interactive shell. | 8 // tracing commands to the BattOr through an interactive shell. |
| 9 // | 9 // |
| 10 // Example usage of how an external trace controller might use this binary: | 10 // Example usage of how an external trace controller might use this binary: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 "\n" | 67 "\n" |
| 68 "Switches: \n" | 68 "Switches: \n" |
| 69 " --battor-path=<path> Uses the specified BattOr path.\n" | 69 " --battor-path=<path> Uses the specified BattOr path.\n" |
| 70 "\n" | 70 "\n" |
| 71 "Once in the shell, you can issue the following commands:\n" | 71 "Once in the shell, you can issue the following commands:\n" |
| 72 "\n" | 72 "\n" |
| 73 " StartTracing\n" | 73 " StartTracing\n" |
| 74 " StopTracing <optional file path>\n" | 74 " StopTracing <optional file path>\n" |
| 75 " SupportsExplicitClockSync\n" | 75 " SupportsExplicitClockSync\n" |
| 76 " RecordClockSyncMarker <marker>\n" | 76 " RecordClockSyncMarker <marker>\n" |
| 77 " GetFirmwareGitHash\n" |
| 77 " Exit\n" | 78 " Exit\n" |
| 78 " Help\n" | 79 " Help\n" |
| 79 "\n"; | 80 "\n"; |
| 80 | 81 |
| 81 void PrintSupportsExplicitClockSync() { | 82 void PrintSupportsExplicitClockSync() { |
| 82 std::cout << BattOrAgent::SupportsExplicitClockSync() << endl; | 83 std::cout << BattOrAgent::SupportsExplicitClockSync() << endl; |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Logs the error and exits with an error code. | 86 // Logs the error and exits with an error code. |
| 86 void HandleError(battor::BattOrError error) { | 87 void HandleError(battor::BattOrError error) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } else if (cmd.find("RecordClockSyncMarker") != std::string::npos) { | 194 } else if (cmd.find("RecordClockSyncMarker") != std::string::npos) { |
| 194 std::vector<std::string> tokens = TokenizeString(cmd); | 195 std::vector<std::string> tokens = TokenizeString(cmd); |
| 195 if (tokens.size() != 2 || tokens[0] != "RecordClockSyncMarker") { | 196 if (tokens.size() != 2 || tokens[0] != "RecordClockSyncMarker") { |
| 196 std::cout << "Invalid RecordClockSyncMarker command." << endl; | 197 std::cout << "Invalid RecordClockSyncMarker command." << endl; |
| 197 std::cout << kUsage << endl; | 198 std::cout << kUsage << endl; |
| 198 PostRunNextCommand(); | 199 PostRunNextCommand(); |
| 199 return; | 200 return; |
| 200 } | 201 } |
| 201 | 202 |
| 202 RecordClockSyncMarker(tokens[1]); | 203 RecordClockSyncMarker(tokens[1]); |
| 204 } else if (cmd == "GetFirmwareGitHash") { |
| 205 GetFirmwareGitHash(); |
| 206 return; |
| 203 } else if (cmd == "Exit" || std::cin.eof()) { | 207 } else if (cmd == "Exit" || std::cin.eof()) { |
| 204 ui_thread_message_loop_.task_runner()->PostTask( | 208 ui_thread_message_loop_.task_runner()->PostTask( |
| 205 FROM_HERE, ui_thread_run_loop_.QuitClosure()); | 209 FROM_HERE, ui_thread_run_loop_.QuitClosure()); |
| 206 } else { | 210 } else { |
| 207 std::cout << kUsage << endl; | 211 std::cout << kUsage << endl; |
| 208 PostRunNextCommand(); | 212 PostRunNextCommand(); |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 void PostRunNextCommand() { | 216 void PostRunNextCommand() { |
| 213 ui_thread_message_loop_.task_runner()->PostTask( | 217 ui_thread_message_loop_.task_runner()->PostTask( |
| 214 FROM_HERE, | 218 FROM_HERE, |
| 215 base::Bind(&BattOrAgentBin::RunNextCommand, base::Unretained(this))); | 219 base::Bind(&BattOrAgentBin::RunNextCommand, base::Unretained(this))); |
| 216 } | 220 } |
| 217 | 221 |
| 222 void GetFirmwareGitHash() { |
| 223 io_thread_.task_runner()->PostTask( |
| 224 FROM_HERE, |
| 225 base::Bind(&BattOrAgent::GetFirmwareGitHash, |
| 226 base::Unretained(agent_.get()))); |
| 227 } |
| 228 |
| 229 void OnGetFirmwareGitHashComplete(const std::string& firmware_git_hash, |
| 230 BattOrError error) override { |
| 231 if (error == BATTOR_ERROR_NONE) |
| 232 std::cout << firmware_git_hash << endl; |
| 233 else |
| 234 HandleError(error); |
| 235 |
| 236 PostRunNextCommand(); |
| 237 } |
| 238 |
| 218 void StartTracing() { | 239 void StartTracing() { |
| 219 io_thread_.task_runner()->PostTask( | 240 io_thread_.task_runner()->PostTask( |
| 220 FROM_HERE, | 241 FROM_HERE, |
| 221 base::Bind(&BattOrAgent::StartTracing, base::Unretained(agent_.get()))); | 242 base::Bind(&BattOrAgent::StartTracing, base::Unretained(agent_.get()))); |
| 222 } | 243 } |
| 223 | 244 |
| 224 void OnStartTracingComplete(BattOrError error) override { | 245 void OnStartTracingComplete(BattOrError error) override { |
| 225 if (error == BATTOR_ERROR_NONE) | 246 if (error == BATTOR_ERROR_NONE) |
| 226 std::cout << "Done." << endl; | 247 std::cout << "Done." << endl; |
| 227 else | 248 else |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 }; | 338 }; |
| 318 | 339 |
| 319 } // namespace battor | 340 } // namespace battor |
| 320 | 341 |
| 321 int main(int argc, char* argv[]) { | 342 int main(int argc, char* argv[]) { |
| 322 base::AtExitManager exit_manager; | 343 base::AtExitManager exit_manager; |
| 323 base::CommandLine::Init(argc, argv); | 344 base::CommandLine::Init(argc, argv); |
| 324 battor::BattOrAgentBin bin; | 345 battor::BattOrAgentBin bin; |
| 325 return bin.Run(argc, argv); | 346 return bin.Run(argc, argv); |
| 326 } | 347 } |
| OLD | NEW |