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..1602d881f6696f07e869a5c951d71c64259322d8 100644 |
--- a/tools/battor_agent/battor_agent_bin.cc |
+++ b/tools/battor_agent/battor_agent_bin.cc |
@@ -2,8 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+// This file provides a thin binary wrapper around the BattOr Agent |
+// library. This binary wrapper provides a means for non-C++ tracing |
+// controllers, such as Telemetry and Android Systrace, to issue high-level |
+// tracing commands to the BattOr.. |
+ |
#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,12 +20,19 @@ 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/30 16:46:44
Remove this?
charliea (OOO until 10-5)
2015/10/30 17:37:42
Ack. Sorry about that - not sure how that slipped
|
+ |
void PrintUsage() { |
cout << "Usage: battor_agent <command> <arguments>" << endl << endl |
<< "Commands:" << endl << endl |
<< " StartTracing <path>" << endl |
<< " StopTracing <path>" << endl |
- << " SupportsExplicitClockSync <path>" << endl |
+ << " SupportsExplicitClockSync" << endl |
<< " RecordClockSyncMarker <path> <marker>" << endl |
<< " IssueClockSyncMarker <path>" << endl |
<< " Help" << endl; |
@@ -36,6 +51,10 @@ bool GetArg(int argnum, int argc, char* argv[], string* value) { |
return true; |
} |
+void OnCommandComplete() { |
+ g_stop_tracing_complete_event.Signal(); |
+} |
+ |
} // namespace |
int main(int argc, char* argv[]) { |
@@ -55,10 +74,12 @@ 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; |
+ std::string trace_output; |
+ battor::BattOrAgent(path) |
+ .StopTracing(&trace_output, base::Bind(&OnCommandComplete)); |
+ g_stop_tracing_complete_event.Wait(); |
+ cout << trace_output << endl; |
} else if (cmd == "SupportsExplicitClockSync") { |
cout << "Calling SupportsExplicitClockSync" << endl; |
cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl; |
@@ -69,7 +90,11 @@ int main(int argc, char* argv[]) { |
cout << "Marker: " << marker << endl; |
cout << "Calling RecordClockSyncMarker()" << endl; |
- battor::BattOrAgent(path).RecordClockSyncMarker(marker); |
+ // TODO: Write the time to STDOUT |
+ battor::BattOrAgent(path) |
+ .RecordClockSyncMarker(marker, base::Bind(&OnCommandComplete)); |
+ g_stop_tracing_complete_event.Wait(); |
+ // TODO: Write the time to STDOUT |
} else if (cmd == "IssueClockSyncMarker") { |
string path; |
if (!GetArg(2, argc, argv, &path)) |