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

Side by Side Diff: components/tracing/child/child_trace_message_filter.cc

Issue 2833873003: WIP: The tracing service prototype
Patch Set: sync Created 3 years, 7 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
« no previous file with comments | « components/tracing/child/child_trace_message_filter.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/tracing/child/child_trace_message_filter.h" 5 #include "components/tracing/child/child_trace_message_filter.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
11 #include "base/trace_event/memory_dump_manager.h" 11 #include "base/trace_event/memory_dump_manager.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "components/tracing/common/process_metrics_memory_dump_provider.h" 13 #include "components/tracing/common/process_metrics_memory_dump_provider.h"
14 #include "components/tracing/common/tracing_messages.h" 14 #include "components/tracing/common/tracing_messages.h"
15 #include "ipc/ipc_channel.h" 15 #include "ipc/ipc_channel.h"
16 16
17 using base::trace_event::MemoryDumpManager; 17 using base::trace_event::MemoryDumpManager;
18 using base::trace_event::TraceLog; 18 using base::trace_event::TraceLog;
19 19
20 namespace tracing { 20 namespace tracing {
21 21
22 namespace { 22 namespace {
23 23
24 const int kMinTimeBetweenHistogramChangesInSeconds = 10; 24 const int kMinTimeBetweenHistogramChangesInSeconds = 10;
25 25
26 } // namespace 26 } // namespace
27 27
28 ChildTraceMessageFilter::ChildTraceMessageFilter( 28 ChildTraceMessageFilter::ChildTraceMessageFilter(
29 base::SingleThreadTaskRunner* ipc_task_runner) 29 base::SingleThreadTaskRunner* ipc_task_runner)
30 : enabled_tracing_modes_(0), 30 : sender_(NULL), ipc_task_runner_(ipc_task_runner) {}
31 sender_(NULL),
32 ipc_task_runner_(ipc_task_runner) {}
33 31
34 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { 32 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
35 sender_ = channel; 33 sender_ = channel;
36 sender_->Send(new TracingHostMsg_ChildSupportsTracing()); 34 sender_->Send(new TracingHostMsg_ChildSupportsTracing());
37 35
38 #if !defined(OS_LINUX) && !defined(OS_NACL) 36 #if !defined(OS_LINUX) && !defined(OS_NACL)
39 // On linux the browser process takes care of dumping process metrics. 37 // On linux the browser process takes care of dumping process metrics.
40 // The child process is not allowed to do so due to BPF sandbox. 38 // The child process is not allowed to do so due to BPF sandbox.
41 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( 39 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess(
42 base::kNullProcessId); 40 base::kNullProcessId);
43 #endif 41 #endif
44 } 42 }
45 43
46 void ChildTraceMessageFilter::SetSenderForTesting(IPC::Sender* sender) { 44 void ChildTraceMessageFilter::SetSenderForTesting(IPC::Sender* sender) {
47 sender_ = sender; 45 sender_ = sender;
48 } 46 }
49 47
50 void ChildTraceMessageFilter::OnFilterRemoved() { 48 void ChildTraceMessageFilter::OnFilterRemoved() {
51 sender_ = NULL; 49 sender_ = NULL;
52 } 50 }
53 51
54 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { 52 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) {
55 bool handled = true; 53 bool handled = true;
56 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) 54 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message)
57 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing)
58 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing)
59 IPC_MESSAGE_HANDLER(TracingMsg_CancelTracing, OnCancelTracing)
60 IPC_MESSAGE_HANDLER(TracingMsg_GetTraceLogStatus, OnGetTraceLogStatus)
61 IPC_MESSAGE_HANDLER(TracingMsg_SetUMACallback, OnSetUMACallback) 55 IPC_MESSAGE_HANDLER(TracingMsg_SetUMACallback, OnSetUMACallback)
62 IPC_MESSAGE_HANDLER(TracingMsg_ClearUMACallback, OnClearUMACallback) 56 IPC_MESSAGE_HANDLER(TracingMsg_ClearUMACallback, OnClearUMACallback)
63 IPC_MESSAGE_UNHANDLED(handled = false) 57 IPC_MESSAGE_UNHANDLED(handled = false)
64 IPC_END_MESSAGE_MAP() 58 IPC_END_MESSAGE_MAP()
65 return handled; 59 return handled;
66 } 60 }
67 61
68 ChildTraceMessageFilter::~ChildTraceMessageFilter() {} 62 ChildTraceMessageFilter::~ChildTraceMessageFilter() {}
69 63
70 void ChildTraceMessageFilter::OnBeginTracing(
71 const std::string& trace_config_str,
72 base::TimeTicks browser_time,
73 uint64_t tracing_process_id) {
74 #if defined(__native_client__)
75 // NaCl and system times are offset by a bit, so subtract some time from
76 // the captured timestamps. The value might be off by a bit due to messaging
77 // latency.
78 base::TimeDelta time_offset = base::TimeTicks::Now() - browser_time;
79 TraceLog::GetInstance()->SetTimeOffset(time_offset);
80 #endif
81 MemoryDumpManager::GetInstance()->set_tracing_process_id(tracing_process_id);
82 const base::trace_event::TraceConfig trace_config(trace_config_str);
83 enabled_tracing_modes_ = base::trace_event::TraceLog::RECORDING_MODE;
84 if (!trace_config.event_filters().empty())
85 enabled_tracing_modes_ |= base::trace_event::TraceLog::FILTERING_MODE;
86 TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_);
87 }
88
89 void ChildTraceMessageFilter::OnEndTracing() {
90 DCHECK(enabled_tracing_modes_);
91 TraceLog::GetInstance()->SetDisabled(enabled_tracing_modes_);
92 enabled_tracing_modes_ = 0;
93
94 // Flush will generate one or more callbacks to OnTraceDataCollected
95 // synchronously or asynchronously. EndTracingAck will be sent in the last
96 // OnTraceDataCollected. We are already on the IO thread, so the
97 // OnTraceDataCollected calls will not be deferred.
98 TraceLog::GetInstance()->Flush(
99 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this));
100
101 MemoryDumpManager::GetInstance()->set_tracing_process_id(
102 MemoryDumpManager::kInvalidTracingProcessId);
103 }
104
105 void ChildTraceMessageFilter::OnCancelTracing() {
106 TraceLog::GetInstance()->CancelTracing(
107 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this));
108 }
109
110 void ChildTraceMessageFilter::OnGetTraceLogStatus() {
111 sender_->Send(new TracingHostMsg_TraceLogStatusReply(
112 TraceLog::GetInstance()->GetStatus()));
113 }
114
115 void ChildTraceMessageFilter::OnTraceDataCollected(
116 const scoped_refptr<base::RefCountedString>& events_str_ptr,
117 bool has_more_events) {
118 if (!ipc_task_runner_->BelongsToCurrentThread()) {
119 ipc_task_runner_->PostTask(
120 FROM_HERE, base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected,
121 this, events_str_ptr, has_more_events));
122 return;
123 }
124 if (events_str_ptr->data().size()) {
125 sender_->Send(new TracingHostMsg_TraceDataCollected(
126 events_str_ptr->data()));
127 }
128 if (!has_more_events) {
129 std::vector<std::string> category_groups;
130 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups);
131 sender_->Send(new TracingHostMsg_EndTracingAck(category_groups));
132 }
133 }
134
135 void ChildTraceMessageFilter::OnHistogramChanged( 64 void ChildTraceMessageFilter::OnHistogramChanged(
136 const std::string& histogram_name, 65 const std::string& histogram_name,
137 base::Histogram::Sample reference_lower_value, 66 base::Histogram::Sample reference_lower_value,
138 base::Histogram::Sample reference_upper_value, 67 base::Histogram::Sample reference_upper_value,
139 bool repeat, 68 bool repeat,
140 base::Histogram::Sample actual_value) { 69 base::Histogram::Sample actual_value) {
141 if (actual_value < reference_lower_value || 70 if (actual_value < reference_lower_value ||
142 actual_value > reference_upper_value) { 71 actual_value > reference_upper_value) {
143 if (!repeat) { 72 if (!repeat) {
144 ipc_task_runner_->PostTask( 73 ipc_task_runner_->PostTask(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 153 }
225 } 154 }
226 155
227 void ChildTraceMessageFilter::OnClearUMACallback( 156 void ChildTraceMessageFilter::OnClearUMACallback(
228 const std::string& histogram_name) { 157 const std::string& histogram_name) {
229 histogram_last_changed_ = base::Time(); 158 histogram_last_changed_ = base::Time();
230 base::StatisticsRecorder::ClearCallback(histogram_name); 159 base::StatisticsRecorder::ClearCallback(histogram_name);
231 } 160 }
232 161
233 } // namespace tracing 162 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/child/child_trace_message_filter.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698