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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/arc/trace/arc_trace_bridge.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h"
12 #include "components/arc/arc_bridge_service.h"
13
14 namespace arc {
15
16 namespace {
17 // This class is owned by ArcServiceManager so that it is safe to use this raw
18 // pointer as the singleton reference.
19 ArcTraceBridge* g_arc_trace_bridge = nullptr;
20
21 // The prefix of the categories to be shown on the trace selection UI.
22 const std::string g_category_prefix(
Luis Héctor Chávez 2016/10/11 03:38:49 nit: constexpr char kCategoryPrefix[] = ...;
shunhsingou 2016/10/11 07:22:05 Done.
23 TRACE_DISABLED_BY_DEFAULT("android.trace."));
24
25 } // namcespace
26
27 ArcTraceBridge* ArcTraceBridge::Get() {
28 DCHECK(g_arc_trace_bridge);
29 return g_arc_trace_bridge;
30 }
31
32 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
33 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) {
34 arc_bridge_service()->trace()->AddObserver(this);
35 g_arc_trace_bridge = this;
36 }
37
38 ArcTraceBridge::~ArcTraceBridge() {
39 arc_bridge_service()->trace()->RemoveObserver(this);
40 g_arc_trace_bridge = nullptr;
41 }
42
43 void ArcTraceBridge::OnInstanceReady() {
44 auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod(
45 "QueryAvailableCategories");
46 if (!trace_instance) {
47 LOG(ERROR) << "OnTraceInstanceReady called, "
48 << "but no trace instance found";
Luis Héctor Chávez 2016/10/11 03:38:49 GetInstanceForMethod already does logging, so this
shunhsingou 2016/10/11 07:22:05 Done.
49 return;
50 }
51 QueryAvailableCategories();
52 }
53
54 void ArcTraceBridge::QueryAvailableCategories() {
55 auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod(
56 "QueryAvailableCategories");
57 if (trace_instance) {
Luis Héctor Chávez 2016/10/11 03:38:49 nit: if (!trace_instance) return;
shunhsingou 2016/10/11 07:22:05 Done.
58 trace_instance->QueryAvailableCategories(
59 base::Bind(&ArcTraceBridge::OnCategoriesReady,
60 weak_ptr_factory_.GetWeakPtr()));
61 }
62 }
63
64 void ArcTraceBridge::OnCategoriesReady(mojo::Array<mojo::String> categories) {
65 categories_ = categories;
Luis Héctor Chávez 2016/10/11 03:38:49 This needs thread-checking code, like DCHECK(threa
shunhsingou 2016/10/11 07:22:05 Done.
66 for (size_t i = 0; i < categories_.size(); ++i) {
Luis Héctor Chávez 2016/10/11 03:38:49 You can use for (const auto& category : categorie
shunhsingou 2016/10/11 07:22:05 Done.
67 std::string full_category_name =
68 g_category_prefix + std::string(categories_.at(i));
69
70 // Shows the category name in the selection UI.
71 base::trace_event::TraceLog::GetCategoryGroupEnabled(
72 full_category_name.c_str());
73 }
74 }
75
76 void ArcTraceBridge::StartTracing(
77 const base::trace_event::TraceConfig& trace_config) {
78
79 mojo::Array<mojo::String> categories;
80
81 for (size_t i = 0; i < categories_.size(); ++i) {
82 std::string category_name = categories_.at(i);
83 std::string full_category_name = g_category_prefix + category_name;
Luis Héctor Chávez 2016/10/11 03:38:49 Should you store the full name in addition to the
shunhsingou 2016/10/11 07:22:05 Done.
84 if (trace_config.IsCategoryGroupEnabled(full_category_name.c_str())) {
85 categories.push_back(category_name);
86 }
87 }
88
89 auto* trace_instance =
90 arc_bridge_service()->trace()->GetInstanceForMethod("StartTracing");
91 if (trace_instance) trace_instance->StartTracing(std::move(categories));
Luis Héctor Chávez 2016/10/11 03:38:49 This should be at the beginning of the function, u
shunhsingou 2016/10/11 07:22:05 Done.
92 }
93
94 void ArcTraceBridge::StopTracing() {
95 auto* trace_instance =
96 arc_bridge_service()->trace()->GetInstanceForMethod("StopTracing");
97 if (trace_instance) trace_instance->StopTracing();
98 }
99
100 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698