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/common/child_trace_message_filter.h" | 5 #include "content/common/child_trace_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "content/common/child_process.h" | 10 #include "content/common/child_process.h" |
11 #include "content/common/child_process_messages.h" | 11 #include "content/common/child_process_messages.h" |
12 | 12 |
| 13 using base::debug::TraceLog; |
13 | 14 |
14 ChildTraceMessageFilter::ChildTraceMessageFilter() : channel_(NULL) {} | 15 ChildTraceMessageFilter::ChildTraceMessageFilter() : channel_(NULL) {} |
15 | 16 |
16 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 17 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { |
17 channel_ = channel; | 18 channel_ = channel; |
18 base::debug::TraceLog::GetInstance()->SetOutputCallback( | 19 TraceLog::GetInstance()->SetNotificationCallback( |
19 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this)); | 20 base::Bind(&ChildTraceMessageFilter::OnTraceNotification, this)); |
20 base::debug::TraceLog::GetInstance()->SetBufferFullCallback( | |
21 base::Bind(&ChildTraceMessageFilter::OnTraceBufferFull, this)); | |
22 channel_->Send(new ChildProcessHostMsg_ChildSupportsTracing()); | 21 channel_->Send(new ChildProcessHostMsg_ChildSupportsTracing()); |
23 } | 22 } |
24 | 23 |
25 void ChildTraceMessageFilter::OnFilterRemoved() { | 24 void ChildTraceMessageFilter::OnFilterRemoved() { |
26 base::debug::TraceLog::GetInstance()->SetOutputCallback( | 25 TraceLog::GetInstance()->SetNotificationCallback( |
27 base::debug::TraceLog::OutputCallback()); | 26 TraceLog::NotificationCallback()); |
28 base::debug::TraceLog::GetInstance()->SetBufferFullCallback( | |
29 base::debug::TraceLog::BufferFullCallback()); | |
30 } | 27 } |
31 | 28 |
32 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { | 29 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { |
33 bool handled = true; | 30 bool handled = true; |
34 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) | 31 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) |
35 IPC_MESSAGE_HANDLER(ChildProcessMsg_BeginTracing, OnBeginTracing) | 32 IPC_MESSAGE_HANDLER(ChildProcessMsg_BeginTracing, OnBeginTracing) |
36 IPC_MESSAGE_HANDLER(ChildProcessMsg_EndTracing, OnEndTracing) | 33 IPC_MESSAGE_HANDLER(ChildProcessMsg_EndTracing, OnEndTracing) |
37 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTraceBufferPercentFull, | 34 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTraceBufferPercentFull, |
38 OnGetTraceBufferPercentFull) | 35 OnGetTraceBufferPercentFull) |
| 36 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetWatchEvent, OnSetWatchEvent) |
| 37 IPC_MESSAGE_HANDLER(ChildProcessMsg_CancelWatchEvent, OnCancelWatchEvent) |
39 IPC_MESSAGE_UNHANDLED(handled = false) | 38 IPC_MESSAGE_UNHANDLED(handled = false) |
40 IPC_END_MESSAGE_MAP() | 39 IPC_END_MESSAGE_MAP() |
41 return handled; | 40 return handled; |
42 } | 41 } |
43 | 42 |
44 ChildTraceMessageFilter::~ChildTraceMessageFilter() {} | 43 ChildTraceMessageFilter::~ChildTraceMessageFilter() {} |
45 | 44 |
46 void ChildTraceMessageFilter::OnBeginTracing( | 45 void ChildTraceMessageFilter::OnBeginTracing( |
47 const std::vector<std::string>& included_categories, | 46 const std::vector<std::string>& included_categories, |
48 const std::vector<std::string>& excluded_categories) { | 47 const std::vector<std::string>& excluded_categories) { |
49 base::debug::TraceLog::GetInstance()->SetEnabled(included_categories, | 48 TraceLog::GetInstance()->SetEnabled(included_categories, |
50 excluded_categories); | 49 excluded_categories); |
51 } | 50 } |
52 | 51 |
53 void ChildTraceMessageFilter::OnEndTracing() { | 52 void ChildTraceMessageFilter::OnEndTracing() { |
54 // SetDisabled may generate a callback to OnTraceDataCollected. | 53 TraceLog::GetInstance()->SetDisabled(); |
55 // It's important that the last OnTraceDataCollected gets called before | 54 |
56 // EndTracingAck below. | 55 // Flush will generate one or more callbacks to OnTraceDataCollected. It's |
57 // We are already on the IO thread, so it is guaranteed that | 56 // important that the last OnTraceDataCollected gets called before |
58 // OnTraceDataCollected is not deferred. | 57 // EndTracingAck below. We are already on the IO thread, so the |
59 base::debug::TraceLog::GetInstance()->SetDisabled(); | 58 // OnTraceDataCollected calls will not be deferred. |
| 59 TraceLog::GetInstance()->Flush( |
| 60 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this)); |
60 | 61 |
61 std::vector<std::string> categories; | 62 std::vector<std::string> categories; |
62 base::debug::TraceLog::GetInstance()->GetKnownCategories(&categories); | 63 TraceLog::GetInstance()->GetKnownCategories(&categories); |
63 channel_->Send(new ChildProcessHostMsg_EndTracingAck(categories)); | 64 channel_->Send(new ChildProcessHostMsg_EndTracingAck(categories)); |
64 } | 65 } |
65 | 66 |
66 void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { | 67 void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { |
67 float bpf = base::debug::TraceLog::GetInstance()->GetBufferPercentFull(); | 68 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
68 | 69 |
69 channel_->Send(new ChildProcessHostMsg_TraceBufferPercentFullReply(bpf)); | 70 channel_->Send(new ChildProcessHostMsg_TraceBufferPercentFullReply(bpf)); |
70 } | 71 } |
71 | 72 |
| 73 void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, |
| 74 const std::string& event_name) { |
| 75 TraceLog::GetInstance()->SetWatchEvent(category_name.c_str(), |
| 76 event_name.c_str()); |
| 77 } |
| 78 |
| 79 void ChildTraceMessageFilter::OnCancelWatchEvent() { |
| 80 TraceLog::GetInstance()->CancelWatchEvent(); |
| 81 } |
| 82 |
72 void ChildTraceMessageFilter::OnTraceDataCollected( | 83 void ChildTraceMessageFilter::OnTraceDataCollected( |
73 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 84 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
74 if (MessageLoop::current() != ChildProcess::current()->io_message_loop()) { | 85 if (MessageLoop::current() != ChildProcess::current()->io_message_loop()) { |
75 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, | 86 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, |
76 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this, | 87 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this, |
77 events_str_ptr)); | 88 events_str_ptr)); |
78 return; | 89 return; |
79 } | 90 } |
80 | 91 |
81 channel_->Send(new ChildProcessHostMsg_TraceDataCollected( | 92 channel_->Send(new ChildProcessHostMsg_TraceDataCollected( |
82 events_str_ptr->data())); | 93 events_str_ptr->data())); |
83 } | 94 } |
84 | 95 |
85 void ChildTraceMessageFilter::OnTraceBufferFull() { | 96 void ChildTraceMessageFilter::OnTraceNotification(int notification) { |
86 if (MessageLoop::current() != ChildProcess::current()->io_message_loop()) { | 97 if (MessageLoop::current() != ChildProcess::current()->io_message_loop()) { |
87 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, | 98 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, |
88 base::Bind(&ChildTraceMessageFilter::OnTraceBufferFull, this)); | 99 base::Bind(&ChildTraceMessageFilter::OnTraceNotification, this, |
| 100 notification)); |
89 return; | 101 return; |
90 } | 102 } |
91 | 103 |
92 channel_->Send(new ChildProcessHostMsg_TraceBufferFull()); | 104 channel_->Send(new ChildProcessHostMsg_TraceNotification(notification)); |
93 } | 105 } |
94 | |
OLD | NEW |