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

Unified Diff: components/arc/trace/arc_trace_bridge.cc

Issue 2400163003: arc: enable Android tracing in verified-boot mode (Closed)
Patch Set: arc: enable Android framework tracing in chrome://tracing Created 4 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
Index: components/arc/trace/arc_trace_bridge.cc
diff --git a/components/arc/trace/arc_trace_bridge.cc b/components/arc/trace/arc_trace_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca8eb3f60089c9f063a0b9d57a6ed41ab3109554
--- /dev/null
+++ b/components/arc/trace/arc_trace_bridge.cc
@@ -0,0 +1,109 @@
+// Copyright 2016 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 "components/arc/trace/arc_trace_bridge.h"
+
+#include <string>
+#include <utility>
+
+#include "base/logging.h"
+#include "base/trace_event/trace_event.h"
+#include "components/arc/arc_bridge_service.h"
+
+namespace arc {
+
+namespace {
+// This class is owned by ArcServiceManager so that it is safe to use this raw
+// pointer as the singleton reference.
+ArcTraceBridge* g_arc_trace_bridge = nullptr;
+
+// The prefix of the categories to be shown on the trace selection UI.
+constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
+
+} // namcespace
+
+ArcTraceBridge* ArcTraceBridge::Get() {
+ DCHECK(g_arc_trace_bridge);
+ return g_arc_trace_bridge;
+}
+
+ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) {
+ arc_bridge_service()->trace()->AddObserver(this);
+ g_arc_trace_bridge = this;
+}
+
+ArcTraceBridge::~ArcTraceBridge() {
+ arc_bridge_service()->trace()->RemoveObserver(this);
+ g_arc_trace_bridge = nullptr;
+}
+
+void ArcTraceBridge::OnInstanceReady() {
+ QueryAvailableCategories();
+}
+
+void ArcTraceBridge::QueryAvailableCategories() {
+ auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod(
+ "QueryAvailableCategories");
+ if (!trace_instance)
+ return;
+ trace_instance->QueryAvailableCategories(base::Bind(
+ &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ArcTraceBridge::OnCategoriesReady(mojo::Array<mojo::String> categories) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ for (const auto& category : categories) {
+ categories_.push_back(std::pair<std::string, std::string>(
+ category, std::string(kCategoryPrefix) + std::string(category)));
+ // Shows the category name in the selection UI.
+ base::trace_event::TraceLog::GetCategoryGroupEnabled(
+ categories_.back().second.c_str());
+ }
+}
+
+void ArcTraceBridge::StartTracing(
+ const base::trace_event::TraceConfig& trace_config) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ auto* trace_instance =
+ arc_bridge_service()->trace()->GetInstanceForMethod("StartTracing");
+ if (!trace_instance)
+ return;
+
+ mojo::Array<mojo::String> selected_categories;
+ for (const auto& category : categories_) {
+ if (trace_config.IsCategoryGroupEnabled(category.second.c_str())) {
+ selected_categories.push_back(category.first);
+ }
+ }
+
+ trace_instance->StartTracing(std::move(selected_categories),
+ base::Bind(&ArcTraceBridge::OnTraceStart,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ArcTraceBridge::StopTracing() {
+ auto* trace_instance =
+ arc_bridge_service()->trace()->GetInstanceForMethod("StopTracing");
+ if (!trace_instance)
+ return;
+ trace_instance->StopTracing(
+ base::Bind(&ArcTraceBridge::OnTraceStop, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ArcTraceBridge::OnTraceStart(bool success) {
+ if (!success) {
Luis Héctor Chávez 2016/10/11 13:13:03 nit: elide braces if both the condition and the bl
shunhsingou 2016/10/12 04:24:26 Done.
+ LOG(ERROR) << "Failed to start tracing in the container.";
+ }
+}
+
+void ArcTraceBridge::OnTraceStop(bool success) {
+ if (!success) {
+ LOG(ERROR) << "Failed to stop tracing in the container.";
+ }
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698