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

Unified Diff: apps/benchmark/trace_collector_client.cc

Issue 1305193002: Trace-based benchmarking via a mojo app. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Further address Etienne's comments. Created 5 years, 4 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 | « apps/benchmark/trace_collector_client.h ('k') | mojo/devtools/common/mojo_benchmark » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/benchmark/trace_collector_client.cc
diff --git a/apps/benchmark/trace_collector_client.cc b/apps/benchmark/trace_collector_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1d1483db2887f4832302331845fd5824691d74f3
--- /dev/null
+++ b/apps/benchmark/trace_collector_client.cc
@@ -0,0 +1,42 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/benchmark/trace_collector_client.h"
+
+TraceCollectorClient::TraceCollectorClient(Receiver* receiver,
+ tracing::TraceCollectorPtr collector)
+ : receiver_(receiver),
+ collector_(collector.Pass()),
+ currently_tracing_(false) {}
+
+TraceCollectorClient::~TraceCollectorClient() {}
+
+void TraceCollectorClient::Start(const std::string& categories) {
+ DCHECK(!currently_tracing_);
+ currently_tracing_ = true;
+ mojo::DataPipe data_pipe;
+ collector_->Start(data_pipe.producer_handle.Pass(), categories);
+ drainer_.reset(new mojo::common::DataPipeDrainer(
+ this, data_pipe.consumer_handle.Pass()));
+ trace_data_.clear();
+ trace_data_ += "[";
+}
+
+void TraceCollectorClient::Stop() {
+ DCHECK(currently_tracing_);
+ currently_tracing_ = false;
+ collector_->StopAndFlush();
+}
+
+void TraceCollectorClient::OnDataAvailable(const void* data, size_t num_bytes) {
+ const char* chars = static_cast<const char*>(data);
+ trace_data_.append(chars, num_bytes);
+}
+
+void TraceCollectorClient::OnDataComplete() {
+ drainer_.reset();
+ collector_.reset();
+ trace_data_ += "]";
+ receiver_->OnTraceCollected(trace_data_);
+}
« no previous file with comments | « apps/benchmark/trace_collector_client.h ('k') | mojo/devtools/common/mojo_benchmark » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698