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

Side by Side Diff: content/browser/profiler_synchronizer.cc

Issue 8588023: Collect profiler stats from browser child processes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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
Property Changes:
Added: svn:executable
+ *
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "content/public/browser/profiler_synchronizer.h"
6
7 #include "base/bind.h"
8 #include "content/browser/browser_child_process_host.h"
9 #include "content/common/child_process_info.h"
10 #include "content/common/child_process_messages.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/profiler_controller.h"
13 #include "content/public/browser/render_process_host.h"
14
15 namespace content {
16
17 // static
18 void GetProfilerDataFromChildProcesses(int sequence_number) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
20
21 int pending_processes = 0;
22 for (BrowserChildProcessHost::Iterator child_process_host;
23 !child_process_host.Done(); ++child_process_host) {
24 const std::string process_type =
25 ChildProcessInfo::GetTypeNameInEnglish(child_process_host->type());
26
27 ++pending_processes;
28 if (!child_process_host->Send(new ChildProcessMsg_GetChildProfilerData(
29 sequence_number, process_type))) {
30 --pending_processes;
31 }
32 }
33
34 BrowserThread::PostTask(
35 BrowserThread::UI,
36 FROM_HERE,
37 base::Bind(&ProfilerController::OnPendingProcesses,
jam 2011/11/28 15:17:34 nit: per other comments, all this stuff should be
ramant (doing other things) 2011/11/29 01:32:20 Done.
38 base::Unretained(content::ProfilerController::GetInstance()),
39 sequence_number,
40 pending_processes));
41 }
42
43 // static
44 int GetProfilerData(int sequence_number) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46
47 BrowserThread::PostTask(
48 BrowserThread::IO,
49 FROM_HERE,
50 base::Bind(&GetProfilerDataFromChildProcesses, sequence_number));
51
52 int pending_processes = 0;
53 const std::string render_process_type =
54 ChildProcessInfo::GetTypeNameInEnglish(ChildProcessInfo::RENDER_PROCESS);
55
56 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
57 !it.IsAtEnd(); it.Advance()) {
58 ++pending_processes;
59 if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData(
60 sequence_number, render_process_type))) {
61 --pending_processes;
62 }
63 }
64
65 content::ProfilerController::GetInstance()->OnPendingProcesses(
66 sequence_number, pending_processes);
67
68 // Returns 2 to indicate that OnPendingProcesses will be called once for
69 // renderer processes and another for browser child processes.
70 return 2;
71 }
72
73 // static
74 void SetProfilerStatusInChildProcesses(bool enable) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
76
77 for (BrowserChildProcessHost::Iterator child_process_host;
78 !child_process_host.Done(); ++child_process_host) {
79 child_process_host->Send(new ChildProcessMsg_SetProfilerStatus(enable));
80 }
81 }
82
83 // static
84 void SetProfilerStatus(bool enable) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
86
87 // Now tell subprocesses. Messages to ChildProcess-derived
88 // processes must be done on the IO thread.
89 BrowserThread::PostTask(
90 BrowserThread::IO,
91 FROM_HERE,
92 base::Bind(
93 &SetProfilerStatusInChildProcesses, enable));
94
95 // Finally, tell the renderers which don't derive from ChildProcess.
96 // Messages to the renderers must be done on the UI (main) thread.
97 for (content::RenderProcessHost::iterator it(
98 content::RenderProcessHost::AllHostsIterator());
99 !it.IsAtEnd(); it.Advance()) {
100 it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(enable));
101 }
102 }
103 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698