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

Unified Diff: tools/battor_agent/battor_agent_bin.cc

Issue 1407033008: Makes the BattOrAgent asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Makes some commands best-effort Created 5 years, 2 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
« tools/battor_agent/battor_agent.cc ('K') | « tools/battor_agent/battor_agent.cc ('k') | 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 5980403dbb8dd93321bf0fb2b8ae10e671aed9e4..5dcc0725c9639398782d80fa7336521fd0c5fc5b 100644
--- a/tools/battor_agent/battor_agent_bin.cc
+++ b/tools/battor_agent/battor_agent_bin.cc
@@ -4,6 +4,9 @@
Zhen Wang 2015/10/29 19:40:22 Can you also add some comments here to explain why
charliea (OOO until 10-5) 2015/10/29 21:12:11 Done.
#include <iostream>
+#include "base/bind.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/waitable_event.h"
#include "tools/battor_agent/battor_agent.h"
using std::cout;
@@ -12,6 +15,13 @@ using std::string;
namespace {
+// An event used to signal that the BattOr Agent has finished executing its
+// command.
+base::WaitableEvent g_stop_tracing_complete_event(false, false);
+
+// A string that contains the trace that the BattOr has finished recording.
+scoped_ptr<std::string> g_trace_output;
Zhen Wang 2015/10/29 19:40:22 Is this only for the purpose of printing it out fo
nednguyen 2015/10/29 19:57:32 Yeah, I am not a big fan of global. Can your StopT
charliea (OOO until 10-5) 2015/10/29 21:12:11 Done. We wouldn't have needed the global variable
+
void PrintUsage() {
cout << "Usage: battor_agent <command> <arguments>" << endl << endl
<< "Commands:" << endl << endl
@@ -36,6 +46,11 @@ bool GetArg(int argnum, int argc, char* argv[], string* value) {
return true;
}
+void OnStopTracingComplete(scoped_ptr<std::string> trace_output) {
+ g_trace_output = trace_output.Pass();
+ g_stop_tracing_complete_event.Signal();
+}
+
} // namespace
int main(int argc, char* argv[]) {
@@ -55,10 +70,10 @@ int main(int argc, char* argv[]) {
if (!GetArg(2, argc, argv, &path))
return 1;
- string out_trace;
cout << "Calling StopTracing()" << endl;
- battor::BattOrAgent(path).StopTracing(&out_trace);
- cout << out_trace << endl;
+ battor::BattOrAgent(path).StopTracing(base::Bind(&OnStopTracingComplete));
+ g_stop_tracing_complete_event.Wait();
Zhen Wang 2015/10/29 19:40:22 I am fine with treating this as a blocking call ri
nednguyen 2015/10/29 19:57:32 Sorry, but I feel like this is an unnecessary opti
charliea (OOO until 10-5) 2015/10/29 21:12:11 (I think we covered this in the meeting - we'll st
+ cout << *g_trace_output.get() << endl;
} else if (cmd == "SupportsExplicitClockSync") {
cout << "Calling SupportsExplicitClockSync" << endl;
cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl;
« tools/battor_agent/battor_agent.cc ('K') | « tools/battor_agent/battor_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698