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

Side by Side Diff: ppapi/proxy/plugin_main_nacl.cc

Issue 11411118: Add tracing support to NaCl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use components Created 8 years 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 | Annotate | Revision Log
« content/content_components_tracing.gyp ('K') | « ppapi/proxy/DEPS ('k') | no next file » | 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 // Need to include this before most other files because it defines 9 // Need to include this before most other files because it defines
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
12 // ViewMsgLog et al. functions. 12 // ViewMsgLog et al. functions.
13 13
14 #include "base/debug/trace_event.h"
14 #include "base/message_loop.h" 15 #include "base/message_loop.h"
15 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "content/components/tracing/tracing_messages.h"
17 #include "ipc/ipc_channel_handle.h" 19 #include "ipc/ipc_channel_handle.h"
18 #include "ipc/ipc_logging.h" 20 #include "ipc/ipc_logging.h"
19 #include "ipc/ipc_message.h" 21 #include "ipc/ipc_message.h"
20 #include "native_client/src/shared/ppapi_proxy/ppruntime.h" 22 #include "native_client/src/shared/ppapi_proxy/ppruntime.h"
21 #include "native_client/src/shared/srpc/nacl_srpc.h" 23 #include "native_client/src/shared/srpc/nacl_srpc.h"
22 #include "native_client/src/untrusted/irt/irt_ppapi.h" 24 #include "native_client/src/untrusted/irt/irt_ppapi.h"
23 #include "ppapi/c/ppp.h" 25 #include "ppapi/c/ppp.h"
24 #include "ppapi/c/ppp_instance.h" 26 #include "ppapi/c/ppp_instance.h"
25 #include "ppapi/proxy/plugin_dispatcher.h" 27 #include "ppapi/proxy/plugin_dispatcher.h"
26 #include "ppapi/proxy/plugin_globals.h" 28 #include "ppapi/proxy/plugin_globals.h"
27 #include "ppapi/proxy/plugin_proxy_delegate.h" 29 #include "ppapi/proxy/plugin_proxy_delegate.h"
28 #include "ppapi/shared_impl/ppb_audio_shared.h" 30 #include "ppapi/shared_impl/ppb_audio_shared.h"
29 31
30 #if defined(IPC_MESSAGE_LOG_ENABLED) 32 #if defined(IPC_MESSAGE_LOG_ENABLED)
31 #include "base/hash_tables.h" 33 #include "base/hash_tables.h"
32 34
33 LogFunctionMap g_log_function_mapping; 35 LogFunctionMap g_log_function_mapping;
34 36
35 #define IPC_MESSAGE_MACROS_LOG_ENABLED 37 #define IPC_MESSAGE_MACROS_LOG_ENABLED
36 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ 38 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
37 g_log_function_mapping[msg_id] = logger 39 g_log_function_mapping[msg_id] = logger
38 40
39 #endif 41 #endif
40 #include "ppapi/proxy/ppapi_messages.h" 42 #include "ppapi/proxy/ppapi_messages.h"
41 43
42 // This must match up with NACL_CHROME_INITIAL_IPC_DESC, 44 // This must match up with NACL_CHROME_INITIAL_IPC_DESC,
43 // defined in sel_main_chrome.h 45 // defined in sel_main_chrome.h
44 #define NACL_IPC_FD 6 46 #define NACL_IPC_FD 6
45 47
48 using base::debug::TraceLog;
46 using ppapi::proxy::PluginDispatcher; 49 using ppapi::proxy::PluginDispatcher;
47 using ppapi::proxy::PluginGlobals; 50 using ppapi::proxy::PluginGlobals;
48 using ppapi::proxy::PluginProxyDelegate; 51 using ppapi::proxy::PluginProxyDelegate;
49 using ppapi::proxy::ProxyChannel; 52 using ppapi::proxy::ProxyChannel;
50 using ppapi::proxy::SerializedHandle; 53 using ppapi::proxy::SerializedHandle;
51 54
52 namespace { 55 namespace {
53 56
57 // This class sends and receives trace messages on child processes.
bbudge 2012/12/05 02:22:28 This file has a bunch of different things already.
58 class PpapiTraceMessageFilter : public IPC::ChannelProxy::MessageFilter {
59 public:
60 PpapiTraceMessageFilter(base::MessageLoopProxy* ipc_message_loop);
61
62 // IPC::ChannelProxy::MessageFilter implementation.
63 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
64 virtual void OnFilterRemoved() OVERRIDE;
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
66
67 protected:
68 virtual ~PpapiTraceMessageFilter();
69
70 private:
71 // Message handlers.
72 void OnBeginTracing(const std::vector<std::string>& included_categories,
73 const std::vector<std::string>& excluded_categories,
74 base::TimeTicks browser_time);
75 void OnEndTracing();
76 void OnGetTraceBufferPercentFull();
77 void OnSetWatchEvent(const std::string& category_name,
78 const std::string& event_name);
79 void OnCancelWatchEvent();
80
81 // Callback from trace subsystem.
82 void OnTraceDataCollected(
83 const scoped_refptr<base::RefCountedString>& events_str_ptr);
84 void OnTraceNotification(int notification);
85
86 IPC::Channel* channel_;
87 base::MessageLoopProxy* ipc_message_loop_;
88
89 DISALLOW_COPY_AND_ASSIGN(PpapiTraceMessageFilter);
90 };
91
92 PpapiTraceMessageFilter::PpapiTraceMessageFilter(
93 base::MessageLoopProxy* ipc_message_loop)
94 : channel_(NULL),
95 ipc_message_loop_(ipc_message_loop) {}
96
97 void PpapiTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
98 channel_ = channel;
99 TraceLog::GetInstance()->SetNotificationCallback(
100 base::Bind(&PpapiTraceMessageFilter::OnTraceNotification, this));
101 channel_->Send(new TracingHostMsg_ChildSupportsTracing());
102 }
103
104 void PpapiTraceMessageFilter::OnFilterRemoved() {
105 TraceLog::GetInstance()->SetNotificationCallback(
106 TraceLog::NotificationCallback());
107 }
108
109 bool PpapiTraceMessageFilter::OnMessageReceived(const IPC::Message& message) {
110 bool handled = true;
111 IPC_BEGIN_MESSAGE_MAP(PpapiTraceMessageFilter, message)
112 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing)
113 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing)
114 IPC_MESSAGE_HANDLER(TracingMsg_GetTraceBufferPercentFull,
115 OnGetTraceBufferPercentFull)
116 IPC_MESSAGE_HANDLER(TracingMsg_SetWatchEvent, OnSetWatchEvent)
117 IPC_MESSAGE_HANDLER(TracingMsg_CancelWatchEvent, OnCancelWatchEvent)
118 IPC_MESSAGE_UNHANDLED(handled = false)
119 IPC_END_MESSAGE_MAP()
120 return handled;
121 }
122
123 PpapiTraceMessageFilter::~PpapiTraceMessageFilter() {}
124
125 void PpapiTraceMessageFilter::OnBeginTracing(
126 const std::vector<std::string>& included_categories,
127 const std::vector<std::string>& excluded_categories,
128 base::TimeTicks browser_time) {
129 // NaCl and system times are offset by a bit, so subtract some time from
130 // the captured timestamps. The value might be off by a bit due to messaging
131 // latency.
132 base::TimeDelta time_offset = base::TimeTicks::NowFromSystemTraceTime() -
133 browser_time;
134 TraceLog::GetInstance()->SetTimeOffset(time_offset);
135 TraceLog::GetInstance()->SetEnabled(included_categories,
136 excluded_categories);
137 }
138
139 void PpapiTraceMessageFilter::OnEndTracing() {
140 TraceLog::GetInstance()->SetDisabled();
141
142 // Flush will generate one or more callbacks to OnTraceDataCollected. It's
143 // important that the last OnTraceDataCollected gets called before
144 // EndTracingAck below. We are already on the IO thread, so the
145 // OnTraceDataCollected calls will not be deferred.
146 TraceLog::GetInstance()->Flush(
147 base::Bind(&PpapiTraceMessageFilter::OnTraceDataCollected, this));
148
149 std::vector<std::string> categories;
150 TraceLog::GetInstance()->GetKnownCategories(&categories);
151 channel_->Send(new TracingHostMsg_EndTracingAck(categories));
152 }
153
154 void PpapiTraceMessageFilter::OnGetTraceBufferPercentFull() {
155 float bpf = TraceLog::GetInstance()->GetBufferPercentFull();
156
157 channel_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf));
158 }
159
160 void PpapiTraceMessageFilter::OnSetWatchEvent(const std::string& category_name,
161 const std::string& event_name) {
162 TraceLog::GetInstance()->SetWatchEvent(category_name.c_str(),
163 event_name.c_str());
164 }
165
166 void PpapiTraceMessageFilter::OnCancelWatchEvent() {
167 TraceLog::GetInstance()->CancelWatchEvent();
168 }
169
170 void PpapiTraceMessageFilter::OnTraceDataCollected(
171 const scoped_refptr<base::RefCountedString>& events_str_ptr) {
172 channel_->Send(new TracingHostMsg_TraceDataCollected(
173 events_str_ptr->data()));
174 }
175
176 void PpapiTraceMessageFilter::OnTraceNotification(int notification) {
177 if (!ipc_message_loop_->BelongsToCurrentThread()) {
178 ipc_message_loop_->PostTask(FROM_HERE,
179 base::Bind(&PpapiTraceMessageFilter::OnTraceNotification, this,
180 notification));
181 return;
182 }
183 channel_->Send(new TracingHostMsg_TraceNotification(notification));
184 }
185
54 // This class manages communication between the plugin and the browser, and 186 // This class manages communication between the plugin and the browser, and
55 // manages the PluginDispatcher instances for communication between the plugin 187 // manages the PluginDispatcher instances for communication between the plugin
56 // and the renderer. 188 // and the renderer.
57 class PpapiDispatcher : public ProxyChannel, 189 class PpapiDispatcher : public ProxyChannel,
58 public PluginDispatcher::PluginDelegate, 190 public PluginDispatcher::PluginDelegate,
59 public PluginProxyDelegate { 191 public PluginProxyDelegate {
60 public: 192 public:
61 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); 193 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop);
62 194
63 // PluginDispatcher::PluginDelegate implementation. 195 // PluginDispatcher::PluginDelegate implementation.
(...skipping 30 matching lines...) Expand all
94 base::WaitableEvent shutdown_event_; 226 base::WaitableEvent shutdown_event_;
95 }; 227 };
96 228
97 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) 229 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
98 : next_plugin_dispatcher_id_(0), 230 : next_plugin_dispatcher_id_(0),
99 message_loop_(io_loop), 231 message_loop_(io_loop),
100 shutdown_event_(true, false) { 232 shutdown_event_(true, false) {
101 IPC::ChannelHandle channel_handle( 233 IPC::ChannelHandle channel_handle(
102 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false)); 234 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false));
103 InitWithChannel(this, channel_handle, false); // Channel is server. 235 InitWithChannel(this, channel_handle, false); // Channel is server.
236 channel()->AddFilter(new PpapiTraceMessageFilter(message_loop_));
104 } 237 }
105 238
106 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { 239 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() {
107 return message_loop_.get(); 240 return message_loop_.get();
108 } 241 }
109 242
110 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { 243 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() {
111 return &shutdown_event_; 244 return &shutdown_event_;
112 } 245 }
113 246
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 389
257 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); 390 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
258 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); 391 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
259 392
260 loop.Run(); 393 loop.Run();
261 394
262 NaClSrpcModuleFini(); 395 NaClSrpcModuleFini();
263 396
264 return 0; 397 return 0;
265 } 398 }
OLDNEW
« content/content_components_tracing.gyp ('K') | « ppapi/proxy/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698