Commit a36a5b07 authored by charliea's avatar charliea Committed by Commit bot

Makes the BattOrAgent asynchronous

I confirmed with simonhatch@ that this made sense given the way that
the Chromium TracingController works. The agent will be communicating
over a serial connection, which probably shouldn't be done
synchronously.

BUG=542837

Review URL: https://codereview.chromium.org/1407033008

Cr-Commit-Position: refs/heads/master@{#357144}
parent 7e0c3b88
......@@ -8,6 +8,7 @@ executable("battor_agent") {
]
deps = [
":battor_agent_lib",
"//base",
]
}
......
......@@ -6,30 +6,38 @@
#include <iostream>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
namespace battor {
BattOrAgent::BattOrAgent(const std::string& path) : path_(path) {
// TODO: Open up a serial connection with the BattOr.
// TODO(charliea): Open up a serial connection with the BattOr.
}
BattOrAgent::~BattOrAgent() {
// TODO: Close the serial connection with the BattOr.
// TODO(charliea): Close the serial connection with the BattOr.
}
void BattOrAgent::StartTracing() {
// TODO: Tell the BattOr to start tracing.
// TODO(charliea): Tell the BattOr to start tracing.
}
void BattOrAgent::StopTracing(std::string* out_trace) {
// TODO: Tell the BattOr to stop tracing.
void BattOrAgent::StopTracing(std::string* trace_output,
const base::Closure& callback) {
// TODO(charliea): Tell the BattOr to stop tracing.
*trace_output = "battor trace output";
callback.Run();
}
void BattOrAgent::RecordClockSyncMarker(const std::string& marker) {
// TODO: Tell the BattOr to record the specified clock sync marker.
void BattOrAgent::RecordClockSyncMarker(const std::string& marker,
const base::Closure& callback) {
// TODO(charliea): Tell the BattOr to record the specified clock sync marker.
callback.Run();
}
void BattOrAgent::IssueClockSyncMarker() {
// TODO: Tell atrace to issue a clock sync marker.
// TODO(charliea): Tell atrace to issue a clock sync marker.
}
} // namespace battor
......@@ -4,7 +4,9 @@
#include <string>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
namespace battor {
......@@ -13,17 +15,20 @@ class BattOrAgent {
explicit BattOrAgent(const std::string& path);
virtual ~BattOrAgent();
// Tells the BattOr to start tracing.
// Tells the BattOr (using a best-effort signal) to start tracing.
void StartTracing();
// Tells the BattOr to stop tracing and returns the trace contents.
void StopTracing(std::string* out_trace);
// Tells the BattOr to stop tracing and write the trace output to
// the specified location and calls the callback when complete.
void StopTracing(std::string* trace_output, const base::Closure& callback);
// Tells the BattOr to record a clock sync marker in its own trace log.
void RecordClockSyncMarker(const std::string& marker);
// Tells the BattOr to record a clock sync marker in its own trace
// log and calls the callback when complete.
void RecordClockSyncMarker(const std::string& marker,
const base::Closure& callback);
// Tells the BattOr to issue clock sync markers to all other tracing
// agents that it's connected to.
// Tells the BattOr (using a best-effort signal) to issue clock sync
// markers to all other tracing agents that it's connected to.
void IssueClockSyncMarker();
// Returns whether the BattOr is able to record clock sync markers
......
......@@ -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,16 @@ 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);
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 +48,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 +71,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 +87,11 @@ int main(int argc, char* argv[]) {
cout << "Marker: " << marker << endl;
cout << "Calling RecordClockSyncMarker()" << endl;
battor::BattOrAgent(path).RecordClockSyncMarker(marker);
// TODO(charliea): Write the time to STDOUT
battor::BattOrAgent(path)
.RecordClockSyncMarker(marker, base::Bind(&OnCommandComplete));
g_stop_tracing_complete_event.Wait();
// TODO(charliea): Write the time to STDOUT
} else if (cmd == "IssueClockSyncMarker") {
string path;
if (!GetArg(2, argc, argv, &path))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment