OLD | NEW |
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 "content/browser/tracing/trace_message_filter.h" | 5 #include "content/browser/tracing/trace_message_filter.h" |
6 | 6 |
7 #include "components/tracing/tracing_messages.h" | 7 #include "components/tracing/tracing_messages.h" |
8 #include "content/browser/tracing/background_tracing_manager_impl.h" | 8 #include "content/browser/tracing/background_tracing_manager_impl.h" |
9 #include "content/browser/tracing/tracing_controller_impl.h" | 9 #include "content/browser/tracing/tracing_controller_impl.h" |
10 #include "content/common/child_process_host_impl.h" | 10 #include "content/common/child_process_host_impl.h" |
11 | 11 |
| 12 #if defined(OS_LINUX) |
| 13 #include <fcntl.h> |
| 14 #endif |
| 15 |
| 16 namespace { |
| 17 |
| 18 void OpenFilesForProcess(int pid, |
| 19 TracingMsg_MemoryTracingInfo& memory_tracing_info) { |
| 20 #if defined(OS_LINUX) |
| 21 std::string proc_smaps_name = base::StringPrintf("/proc/%d/smaps", pid); |
| 22 int smaps_fd = HANDLE_EINTR(open(proc_smaps_name.c_str(), O_RDONLY)); |
| 23 if (smaps_fd != -1) { |
| 24 memory_tracing_info.smaps_fd = IPC::GetFileHandleForProcess( |
| 25 smaps_fd, base::GetCurrentProcessHandle(), true); |
| 26 } |
| 27 |
| 28 std::string proc_status_name = base::StringPrintf("/proc/%d/status", pid); |
| 29 int status_fd = HANDLE_EINTR(open(proc_status_name.c_str(), O_RDONLY)); |
| 30 if (status_fd != -1) { |
| 31 memory_tracing_info.status_fd = IPC::GetFileHandleForProcess( |
| 32 status_fd, base::GetCurrentProcessHandle(), true); |
| 33 } |
| 34 #endif |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
12 namespace content { | 39 namespace content { |
13 | 40 |
14 TraceMessageFilter::TraceMessageFilter(int child_process_id) | 41 TraceMessageFilter::TraceMessageFilter(int child_process_id) |
15 : BrowserMessageFilter(TracingMsgStart), | 42 : BrowserMessageFilter(TracingMsgStart), |
16 has_child_(false), | 43 has_child_(false), |
17 tracing_process_id_( | 44 tracing_process_id_( |
18 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( | 45 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
19 child_process_id)), | 46 child_process_id)), |
20 is_awaiting_end_ack_(false), | 47 is_awaiting_end_ack_(false), |
21 is_awaiting_capture_monitoring_snapshot_ack_(false), | 48 is_awaiting_capture_monitoring_snapshot_ack_(false), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 OnProcessMemoryDumpResponse) | 89 OnProcessMemoryDumpResponse) |
63 IPC_MESSAGE_HANDLER(TracingHostMsg_TriggerBackgroundTrace, | 90 IPC_MESSAGE_HANDLER(TracingHostMsg_TriggerBackgroundTrace, |
64 OnTriggerBackgroundTrace) | 91 OnTriggerBackgroundTrace) |
65 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
66 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
67 return handled; | 94 return handled; |
68 } | 95 } |
69 | 96 |
70 void TraceMessageFilter::SendBeginTracing( | 97 void TraceMessageFilter::SendBeginTracing( |
71 const base::trace_event::TraceConfig& trace_config) { | 98 const base::trace_event::TraceConfig& trace_config) { |
72 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 TracingMsg_MemoryTracingInfo memory_tracing_info; |
| 100 if (trace_config.IsDetailedMemoryDumpEnabled()) { |
| 101 if (trace_config.IsDetailedMemoryDumpEnabled()) { |
| 102 OpenFilesForProcess(this->peer_pid(), memory_tracing_info); |
| 103 } |
| 104 memory_tracing_info.tracing_process_id = tracing_process_id_; |
| 105 } |
73 Send(new TracingMsg_BeginTracing( | 106 Send(new TracingMsg_BeginTracing( |
74 trace_config.ToString(), base::TraceTicks::Now(), tracing_process_id_)); | 107 trace_config.ToString(), base::TraceTicks::Now(), memory_tracing_info)); |
75 } | 108 } |
76 | 109 |
77 void TraceMessageFilter::SendEndTracing() { | 110 void TraceMessageFilter::SendEndTracing() { |
78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
79 DCHECK(!is_awaiting_end_ack_); | 112 DCHECK(!is_awaiting_end_ack_); |
80 is_awaiting_end_ack_ = true; | 113 is_awaiting_end_ack_ = true; |
81 Send(new TracingMsg_EndTracing); | 114 Send(new TracingMsg_EndTracing); |
82 } | 115 } |
83 | 116 |
84 void TraceMessageFilter::SendCancelTracing() { | 117 void TraceMessageFilter::SendCancelTracing() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 bool success) { | 237 bool success) { |
205 TracingControllerImpl::GetInstance()->OnProcessMemoryDumpResponse( | 238 TracingControllerImpl::GetInstance()->OnProcessMemoryDumpResponse( |
206 this, dump_guid, success); | 239 this, dump_guid, success); |
207 } | 240 } |
208 | 241 |
209 void TraceMessageFilter::OnTriggerBackgroundTrace(const std::string& name) { | 242 void TraceMessageFilter::OnTriggerBackgroundTrace(const std::string& name) { |
210 BackgroundTracingManagerImpl::GetInstance()->OnHistogramTrigger(name); | 243 BackgroundTracingManagerImpl::GetInstance()->OnHistogramTrigger(name); |
211 } | 244 } |
212 | 245 |
213 } // namespace content | 246 } // namespace content |
OLD | NEW |