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
3 // found in the LICENSE file.
5 #include "content/browser/profiler_message_filter.h"
7 #include "base/tracked_objects.h"
8 #include "base/process_util.h"
9 #include "content/browser/profiler_controller_impl.h"
10 #include "content/browser/tcmalloc_internals_request_job.h"
11 #include "content/common/child_process_messages.h"
15 ProfilerMessageFilter::ProfilerMessageFilter(ProcessType process_type
)
16 : process_type_(process_type
) {
19 void ProfilerMessageFilter::OnChannelConnected(int32 peer_pid
) {
20 BrowserMessageFilter::OnChannelConnected(peer_pid
);
22 tracked_objects::ThreadData::Status status
=
23 tracked_objects::ThreadData::status();
24 Send(new ChildProcessMsg_SetProfilerStatus(status
));
27 bool ProfilerMessageFilter::OnMessageReceived(const IPC::Message
& message
,
28 bool* message_was_ok
) {
30 IPC_BEGIN_MESSAGE_MAP_EX(ProfilerMessageFilter
, message
, *message_was_ok
)
31 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildProfilerData
,
33 #if defined(USE_TCMALLOC)
34 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TcmallocStats
, OnTcmallocStats
)
36 IPC_MESSAGE_UNHANDLED(handled
= false)
37 IPC_END_MESSAGE_MAP_EX()
41 ProfilerMessageFilter::~ProfilerMessageFilter() {}
43 void ProfilerMessageFilter::OnChildProfilerData(
45 const tracked_objects::ProcessDataSnapshot
& profiler_data
) {
46 ProfilerControllerImpl::GetInstance()->OnProfilerDataCollected(
47 sequence_number
, profiler_data
, process_type_
);
50 #if defined(USE_TCMALLOC)
51 void ProfilerMessageFilter::OnTcmallocStats(const std::string
& output
) {
52 AboutTcmallocOutputs::GetInstance()->OnStatsForChildProcess(
53 base::GetProcId(peer_handle()), process_type_
, output
);