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

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

Issue 2724793002: Revert of memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: Created 3 years, 9 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
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"
12 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
13 #include "components/tracing/common/process_metrics_memory_dump_provider.h" 12 #include "components/tracing/child/child_memory_dump_manager_delegate_impl.h"
14 #include "components/tracing/common/tracing_messages.h" 13 #include "components/tracing/common/tracing_messages.h"
15 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
16 15
17 using base::trace_event::MemoryDumpManager;
18 using base::trace_event::TraceLog; 16 using base::trace_event::TraceLog;
19 17
20 namespace tracing { 18 namespace tracing {
21 19
22 namespace { 20 namespace {
23 21
24 const int kMinTimeBetweenHistogramChangesInSeconds = 10; 22 const int kMinTimeBetweenHistogramChangesInSeconds = 10;
25 23
26 } // namespace 24 } // namespace
27 25
28 ChildTraceMessageFilter::ChildTraceMessageFilter( 26 ChildTraceMessageFilter::ChildTraceMessageFilter(
29 base::SingleThreadTaskRunner* ipc_task_runner) 27 base::SingleThreadTaskRunner* ipc_task_runner)
30 : sender_(NULL), ipc_task_runner_(ipc_task_runner) {} 28 : sender_(NULL),
29 ipc_task_runner_(ipc_task_runner),
30 pending_memory_dump_guid_(0) {
31 }
31 32
32 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { 33 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
33 sender_ = channel; 34 sender_ = channel;
34 sender_->Send(new TracingHostMsg_ChildSupportsTracing()); 35 sender_->Send(new TracingHostMsg_ChildSupportsTracing());
35 36 ChildMemoryDumpManagerDelegateImpl::GetInstance()->SetChildTraceMessageFilter(
36 #if !defined(OS_LINUX) && !defined(OS_NACL) 37 this);
37 // On linux the browser process takes care of dumping process metrics.
38 // The child process is not allowed to do so due to BPF sandbox.
39 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess(
40 base::kNullProcessId);
41 #endif
42 } 38 }
43 39
44 void ChildTraceMessageFilter::SetSenderForTesting(IPC::Sender* sender) { 40 void ChildTraceMessageFilter::SetSenderForTesting(IPC::Sender* sender) {
45 sender_ = sender; 41 sender_ = sender;
46 } 42 }
47 43
48 void ChildTraceMessageFilter::OnFilterRemoved() { 44 void ChildTraceMessageFilter::OnFilterRemoved() {
45 ChildMemoryDumpManagerDelegateImpl::GetInstance()->SetChildTraceMessageFilter(
46 nullptr);
49 sender_ = NULL; 47 sender_ = NULL;
50 } 48 }
51 49
52 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { 50 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) {
53 bool handled = true; 51 bool handled = true;
54 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) 52 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message)
55 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing) 53 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing)
56 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing) 54 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing)
57 IPC_MESSAGE_HANDLER(TracingMsg_CancelTracing, OnCancelTracing) 55 IPC_MESSAGE_HANDLER(TracingMsg_CancelTracing, OnCancelTracing)
58 IPC_MESSAGE_HANDLER(TracingMsg_GetTraceLogStatus, OnGetTraceLogStatus) 56 IPC_MESSAGE_HANDLER(TracingMsg_GetTraceLogStatus, OnGetTraceLogStatus)
57 IPC_MESSAGE_HANDLER(TracingMsg_ProcessMemoryDumpRequest,
58 OnProcessMemoryDumpRequest)
59 IPC_MESSAGE_HANDLER(TracingMsg_GlobalMemoryDumpResponse,
60 OnGlobalMemoryDumpResponse)
59 IPC_MESSAGE_HANDLER(TracingMsg_SetUMACallback, OnSetUMACallback) 61 IPC_MESSAGE_HANDLER(TracingMsg_SetUMACallback, OnSetUMACallback)
60 IPC_MESSAGE_HANDLER(TracingMsg_ClearUMACallback, OnClearUMACallback) 62 IPC_MESSAGE_HANDLER(TracingMsg_ClearUMACallback, OnClearUMACallback)
61 IPC_MESSAGE_UNHANDLED(handled = false) 63 IPC_MESSAGE_UNHANDLED(handled = false)
62 IPC_END_MESSAGE_MAP() 64 IPC_END_MESSAGE_MAP()
63 return handled; 65 return handled;
64 } 66 }
65 67
66 ChildTraceMessageFilter::~ChildTraceMessageFilter() {} 68 ChildTraceMessageFilter::~ChildTraceMessageFilter() {}
67 69
68 void ChildTraceMessageFilter::OnBeginTracing( 70 void ChildTraceMessageFilter::OnBeginTracing(
69 const std::string& trace_config_str, 71 const std::string& trace_config_str,
70 base::TimeTicks browser_time, 72 base::TimeTicks browser_time,
71 uint64_t tracing_process_id) { 73 uint64_t tracing_process_id) {
72 #if defined(__native_client__) 74 #if defined(__native_client__)
73 // NaCl and system times are offset by a bit, so subtract some time from 75 // NaCl and system times are offset by a bit, so subtract some time from
74 // the captured timestamps. The value might be off by a bit due to messaging 76 // the captured timestamps. The value might be off by a bit due to messaging
75 // latency. 77 // latency.
76 base::TimeDelta time_offset = base::TimeTicks::Now() - browser_time; 78 base::TimeDelta time_offset = base::TimeTicks::Now() - browser_time;
77 TraceLog::GetInstance()->SetTimeOffset(time_offset); 79 TraceLog::GetInstance()->SetTimeOffset(time_offset);
78 #endif 80 #endif
79 MemoryDumpManager::GetInstance()->set_tracing_process_id(tracing_process_id); 81 ChildMemoryDumpManagerDelegateImpl::GetInstance()->set_tracing_process_id(
82 tracing_process_id);
80 TraceLog::GetInstance()->SetEnabled( 83 TraceLog::GetInstance()->SetEnabled(
81 base::trace_event::TraceConfig(trace_config_str), 84 base::trace_event::TraceConfig(trace_config_str),
82 base::trace_event::TraceLog::RECORDING_MODE); 85 base::trace_event::TraceLog::RECORDING_MODE);
83 } 86 }
84 87
85 void ChildTraceMessageFilter::OnEndTracing() { 88 void ChildTraceMessageFilter::OnEndTracing() {
86 TraceLog::GetInstance()->SetDisabled(); 89 TraceLog::GetInstance()->SetDisabled();
87 90
88 // Flush will generate one or more callbacks to OnTraceDataCollected 91 // Flush will generate one or more callbacks to OnTraceDataCollected
89 // synchronously or asynchronously. EndTracingAck will be sent in the last 92 // synchronously or asynchronously. EndTracingAck will be sent in the last
90 // OnTraceDataCollected. We are already on the IO thread, so the 93 // OnTraceDataCollected. We are already on the IO thread, so the
91 // OnTraceDataCollected calls will not be deferred. 94 // OnTraceDataCollected calls will not be deferred.
92 TraceLog::GetInstance()->Flush( 95 TraceLog::GetInstance()->Flush(
93 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this)); 96 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this));
94 97
95 MemoryDumpManager::GetInstance()->set_tracing_process_id( 98 ChildMemoryDumpManagerDelegateImpl::GetInstance()->set_tracing_process_id(
96 MemoryDumpManager::kInvalidTracingProcessId); 99 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId);
97 } 100 }
98 101
99 void ChildTraceMessageFilter::OnCancelTracing() { 102 void ChildTraceMessageFilter::OnCancelTracing() {
100 TraceLog::GetInstance()->CancelTracing( 103 TraceLog::GetInstance()->CancelTracing(
101 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this)); 104 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this));
102 } 105 }
103 106
104 void ChildTraceMessageFilter::OnGetTraceLogStatus() { 107 void ChildTraceMessageFilter::OnGetTraceLogStatus() {
105 sender_->Send(new TracingHostMsg_TraceLogStatusReply( 108 sender_->Send(new TracingHostMsg_TraceLogStatusReply(
106 TraceLog::GetInstance()->GetStatus())); 109 TraceLog::GetInstance()->GetStatus()));
(...skipping 12 matching lines...) Expand all
119 sender_->Send(new TracingHostMsg_TraceDataCollected( 122 sender_->Send(new TracingHostMsg_TraceDataCollected(
120 events_str_ptr->data())); 123 events_str_ptr->data()));
121 } 124 }
122 if (!has_more_events) { 125 if (!has_more_events) {
123 std::vector<std::string> category_groups; 126 std::vector<std::string> category_groups;
124 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups); 127 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups);
125 sender_->Send(new TracingHostMsg_EndTracingAck(category_groups)); 128 sender_->Send(new TracingHostMsg_EndTracingAck(category_groups));
126 } 129 }
127 } 130 }
128 131
132 // Sent by the Browser's MemoryDumpManager when coordinating a global dump.
133 void ChildTraceMessageFilter::OnProcessMemoryDumpRequest(
134 const base::trace_event::MemoryDumpRequestArgs& args) {
135 ChildMemoryDumpManagerDelegateImpl::GetInstance()->CreateProcessDump(
136 args,
137 base::Bind(&ChildTraceMessageFilter::OnProcessMemoryDumpDone, this));
138 }
139
140 void ChildTraceMessageFilter::OnProcessMemoryDumpDone(uint64_t dump_guid,
141 bool success) {
142 sender_->Send(
143 new TracingHostMsg_ProcessMemoryDumpResponse(dump_guid, success));
144 }
145
146 // Initiates a dump request, asking the Browser's MemoryDumpManager to
147 // coordinate a global memory dump. The Browser's MDM will answer back with a
148 // MemoryDumpResponse when all the child processes (including this one) have
149 // dumped, or with a NACK (|success| == false) if the dump failed (e.g., due to
150 // a collision with a concurrent request from another child process).
151 void ChildTraceMessageFilter::SendGlobalMemoryDumpRequest(
152 const base::trace_event::MemoryDumpRequestArgs& args,
153 const base::trace_event::MemoryDumpCallback& callback) {
154 // If there is already another dump request pending from this child process,
155 // there is no point bothering the Browser's MemoryDumpManager.
156 if (pending_memory_dump_guid_) {
157 if (!callback.is_null())
158 callback.Run(args.dump_guid, false);
159 return;
160 }
161
162 pending_memory_dump_guid_ = args.dump_guid;
163 pending_memory_dump_callback_ = callback;
164 sender_->Send(new TracingHostMsg_GlobalMemoryDumpRequest(args));
165 }
166
167 // Sent by the Browser's MemoryDumpManager in response of a dump request
168 // initiated by this child process.
169 void ChildTraceMessageFilter::OnGlobalMemoryDumpResponse(uint64_t dump_guid,
170 bool success) {
171 DCHECK_NE(0U, pending_memory_dump_guid_);
172 pending_memory_dump_guid_ = 0;
173 if (pending_memory_dump_callback_.is_null())
174 return;
175 pending_memory_dump_callback_.Run(dump_guid, success);
176 }
177
129 void ChildTraceMessageFilter::OnHistogramChanged( 178 void ChildTraceMessageFilter::OnHistogramChanged(
130 const std::string& histogram_name, 179 const std::string& histogram_name,
131 base::Histogram::Sample reference_lower_value, 180 base::Histogram::Sample reference_lower_value,
132 base::Histogram::Sample reference_upper_value, 181 base::Histogram::Sample reference_upper_value,
133 bool repeat, 182 bool repeat,
134 base::Histogram::Sample actual_value) { 183 base::Histogram::Sample actual_value) {
135 if (actual_value < reference_lower_value || 184 if (actual_value < reference_lower_value ||
136 actual_value > reference_upper_value) { 185 actual_value > reference_upper_value) {
137 if (!repeat) { 186 if (!repeat) {
138 ipc_task_runner_->PostTask( 187 ipc_task_runner_->PostTask(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 267 }
219 } 268 }
220 269
221 void ChildTraceMessageFilter::OnClearUMACallback( 270 void ChildTraceMessageFilter::OnClearUMACallback(
222 const std::string& histogram_name) { 271 const std::string& histogram_name) {
223 histogram_last_changed_ = base::Time(); 272 histogram_last_changed_ = base::Time();
224 base::StatisticsRecorder::ClearCallback(histogram_name); 273 base::StatisticsRecorder::ClearCallback(histogram_name);
225 } 274 }
226 275
227 } // namespace tracing 276 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698