Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: tools/battor_agent/battor_agent_bin.cc

Issue 1819573002: [Battor] Add ability to dump trace log to file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review part 2: the re-reviewing Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_agent_bin.cc
diff --git a/tools/battor_agent/battor_agent_bin.cc b/tools/battor_agent/battor_agent_bin.cc
index 1c00b470169916a9a2d6d7b3a01f3d7d2abc99cd..5d4e955263f4a1befa6bcd43201b9e7cc7998946 100644
--- a/tools/battor_agent/battor_agent_bin.cc
+++ b/tools/battor_agent/battor_agent_bin.cc
@@ -33,6 +33,7 @@
#include <stdint.h>
+#include <fstream>
#include <iostream>
#include "base/at_exit.h"
@@ -70,7 +71,7 @@ const char kUsage[] =
"Once in the shell, you can issue the following commands:\n"
"\n"
" StartTracing\n"
- " StopTracing\n"
+ " StopTracing <optional file path>\n"
" SupportsExplicitClockSync\n"
" RecordClockSyncMarker <marker>\n"
" Exit\n"
@@ -93,6 +94,14 @@ void ExitFromThreadStartFailure(const std::string& thread_name) {
LOG(FATAL) << "Failed to start " << thread_name;
}
+std::vector<std::string> TokenizeCommand(std::string cmd) {
alexandermont 2016/03/23 22:56:53 The name of this function could be more general, l
rnephew (Reviews Here) 2016/03/24 00:11:26 This will only ever be used to tokenize command in
charliea (OOO until 10-5) 2016/03/24 15:05:21 I don't have any strong opinion here. I'm fine wit
rnephew (Reviews Here) 2016/03/24 15:15:47 Switched to String
+ base::StringTokenizer tokenizer(cmd, " ");
+ std::vector<std::string> tokens;
+ while (tokenizer.GetNext())
+ tokens.push_back(tokenizer.token());
+ return tokens;
+}
+
} // namespace
// Wrapper class containing all state necessary for an independent binary to
@@ -125,18 +134,24 @@ class BattOrAgentBin : public BattOrAgent::Listener {
if (cmd == "StartTracing") {
StartTracing();
- } else if (cmd == "StopTracing") {
- StopTracing();
+ } else if (cmd.find("StopTracing") != std::string::npos) {
alexandermont 2016/03/23 22:56:53 This just tests if "StopTracing" is in the string
rnephew (Reviews Here) 2016/03/24 00:11:26 Later it does make sure the first word is STopTrac
+ std::vector<std::string> tokens = TokenizeCommand(cmd);
+ if (tokens.size() == 1 && tokens[0] == "StopTracing") {
+ // No path given.
+ StopTracing();
+ } else if (tokens.size() == 2 && tokens[0] == "StopTracing") {
+ // Path given.
+ StopTracing(tokens[1]);
+ } else {
+ std::cout << "Invalid StopTracing command." << endl;
+ std::cout << kUsage << endl;
+ continue;
+ }
break;
} else if (cmd == "SupportsExplicitClockSync") {
PrintSupportsExplicitClockSync();
} else if (cmd.find("RecordClockSyncMarker") != std::string::npos) {
alexandermont 2016/03/23 22:56:53 Same here; this just tests if "RecordClockSyncMark
rnephew (Reviews Here) 2016/03/24 00:11:26 Same as above.
- base::StringTokenizer tokenizer(cmd, " ");
-
- std::vector<std::string> tokens;
- while (tokenizer.GetNext())
- tokens.push_back(tokenizer.token());
-
+ std::vector<std::string> tokens = TokenizeCommand(cmd);
if (tokens.size() != 2 || tokens[0] != "RecordClockSyncMarker") {
std::cout << "Invalid RecordClockSyncMarker command." << endl;
std::cout << kUsage << endl;
@@ -195,7 +210,8 @@ class BattOrAgentBin : public BattOrAgent::Listener {
done_.Signal();
}
- void StopTracing() {
+ void StopTracing(const std::string& path = "") {
+ trace_output_file_ = path;
io_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&BattOrAgent::StopTracing, base::Unretained(agent_.get())));
@@ -205,7 +221,18 @@ class BattOrAgentBin : public BattOrAgent::Listener {
void OnStopTracingComplete(const std::string& trace,
BattOrError error) override {
if (error == BATTOR_ERROR_NONE) {
- std::cout << trace;
+ if (trace_output_file_.empty()) {
+ std::cout << trace;
+ }
+ else {
+ std::ofstream trace_stream(trace_output_file_);
+ if (!trace_stream.is_open()) {
+ std::cout << "Tracing output file could not be opened." << endl;
+ exit(1);
+ }
+ trace_stream << trace;
+ trace_stream.close();
+ }
std::cout << "Done." << endl;
} else {
HandleError(error);
@@ -276,6 +303,9 @@ class BattOrAgentBin : public BattOrAgent::Listener {
// The agent capable of asynchronously communicating with the BattOr.
scoped_ptr<BattOrAgent> agent_;
+
+ std::string trace_output_file_;
+
};
} // namespace battor
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698