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

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: 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..c66cec77bbbb5739683b8e8c01e98a793c592c0b 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"
@@ -77,6 +78,8 @@ const char kUsage[] =
" Help\n"
"\n";
+const std::string* mDumpPath = nullptr;
rnephew (Reviews Here) 2016/03/18 22:21:27 I know this is named wrong, but not sure what is r
charliea (OOO until 10-5) 2016/03/21 15:19:15 What do you think about the name "trace output fil
charliea (OOO until 10-5) 2016/03/21 15:19:15 This should go down with the other member variable
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+
void PrintSupportsExplicitClockSync() {
std::cout << BattOrAgent::SupportsExplicitClockSync() << endl;
}
@@ -125,9 +128,26 @@ class BattOrAgentBin : public BattOrAgent::Listener {
if (cmd == "StartTracing") {
StartTracing();
- } else if (cmd == "StopTracing") {
- StopTracing();
+
rnephew (Reviews Here) 2016/03/18 22:21:27 Already deleted this locally.
charliea (OOO until 10-5) 2016/03/21 15:19:16 Acknowledged.
+ } else if (cmd.find("StopTracing") != std::string::npos) {
+ base::StringTokenizer tokenizer(cmd, " ");
charliea (OOO until 10-5) 2016/03/21 15:19:16 Could you abstract the splitting of the command in
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+ std::vector<std::string> tokens;
+ while (tokenizer.GetNext())
+ tokens.push_back(tokenizer.token());
+
+ 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;
+
charliea (OOO until 10-5) 2016/03/21 15:19:15 nit: remove extra line
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
} else if (cmd == "SupportsExplicitClockSync") {
PrintSupportsExplicitClockSync();
} else if (cmd.find("RecordClockSyncMarker") != std::string::npos) {
@@ -195,6 +215,11 @@ class BattOrAgentBin : public BattOrAgent::Listener {
done_.Signal();
}
+ void StopTracing(const std::string&path) {
charliea (OOO until 10-5) 2016/03/21 15:19:16 nit: should be a space between & and path. Also, i
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+ mDumpPath = &path;
+ StopTracing();
+ }
+
void StopTracing() {
io_thread_.task_runner()->PostTask(
FROM_HERE,
@@ -205,7 +230,14 @@ class BattOrAgentBin : public BattOrAgent::Listener {
void OnStopTracingComplete(const std::string& trace,
BattOrError error) override {
if (error == BATTOR_ERROR_NONE) {
- std::cout << trace;
+ if (mDumpPath) {
+ std::ofstream traceStream;
charliea (OOO until 10-5) 2016/03/21 15:19:15 nit: variable names are underscore delimited (not
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+ traceStream.open(*mDumpPath);
charliea (OOO until 10-5) 2016/03/21 15:19:15 I think that the above two lines can be written as
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+ traceStream << trace;
charliea (OOO until 10-5) 2016/03/21 15:19:16 Just about any time that you're opening and writin
rnephew (Reviews Here) 2016/03/21 16:40:27 Done.
+ traceStream.close();
+ } else {
+ std::cout << trace;
+ }
std::cout << "Done." << endl;
} else {
HandleError(error);
« 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