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

Side by Side Diff: chrome/browser/memory_details_linux.cc

Issue 159777: Add about:memory support for Linux.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 years, 4 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 "chrome/browser/memory_details.h"
6
7 #include "app/l10n_util.h"
8 #include "base/file_version_info.h"
9 #include "base/string_util.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/common/child_process_host.h"
13 #include "chrome/common/url_constants.h"
14 #include "grit/chromium_strings.h"
15
16 // Known browsers which we collect details for.
17 enum _BrowserProcess {
18 CHROME_BROWSER = 0,
19 FIREFOX_BROWSER,
20 OPERA_BROWSER,
21 KONQUEROR_BROWSER,
22 MAX_BROWSERS
23 } BrowserProcess;
24
25 // Template of static data we use for finding browser process information.
26 // These entries must match the ordering for MemoryDetails::BrowserProcess.
27 static ProcessData g_process_template[MAX_BROWSERS];
28
29 MemoryDetails::MemoryDetails()
30 : ui_loop_(NULL) {
31 static const std::wstring google_browser_name =
32 l10n_util::GetString(IDS_PRODUCT_NAME);
Evan Martin 2009/08/03 05:16:11 We avoid statics as a rule; is there a reason for
33 ProcessData g_process_template[MAX_BROWSERS] = {
Evan Martin 2009/08/03 05:16:11 Does this shadow the other definition? I am confu
34 { google_browser_name.c_str(), L"chrome", },
35 { L"Firefox", L"firefox-bin", },
Joel Stanley (old) 2009/08/03 16:02:37 Some other browsers present on my Ubuntu Karmic sy
36 { L"Opera", L"opera", },
37 { L"Konqueror", L"konqueror", },
38 };
39
40 for (unsigned int index = 0; index < arraysize(g_process_template); ++index) {
Evan Martin 2009/08/03 05:16:11 size_t
41 ProcessData process;
42 process.name = g_process_template[index].name;
43 process.process_name = g_process_template[index].process_name;
44 process_data_.push_back(process);
45 }
46 }
47
48 ProcessData* MemoryDetails::ChromeBrowser() {
49 return &process_data_[CHROME_BROWSER];
50 }
51
52 void MemoryDetails::CollectProcessData(
53 std::vector<ProcessMemoryInformation> child_info) {
54 DCHECK(MessageLoop::current() ==
55 ChromeThread::GetMessageLoop(ChromeThread::FILE));
56
57 for (unsigned int index = 0; index < arraysize(g_process_template); index++) {
Evan Martin 2009/08/03 05:16:11 size_t
58 process_data_[index].processes.clear();
59
60 base::NamedProcessIterator process_iter(process_data_[index].process_name,
61 NULL);
62
63 const ProcessEntry* entry;
64 while ((entry = process_iter.NextProcessEntry())) {
65 ProcessMemoryInformation info;
66 info.pid = entry->pid;
67
68 if (info.pid == base::GetCurrentProcId())
69 info.type = ChildProcessInfo::BROWSER_PROCESS;
70 else
71 info.type = ChildProcessInfo::UNKNOWN_PROCESS;
72
73 base::ProcessHandle handle;
74 if (!base::OpenProcessHandle(entry->pid, &handle))
75 continue;
76 scoped_ptr<base::ProcessMetrics> metrics;
77 metrics.reset(base::ProcessMetrics::CreateProcessMetrics(handle));
78 metrics->GetCommittedKBytes(&info.committed);
79 metrics->GetWorkingSetKBytes(&info.working_set);
80
81 // Get Version Information.
82 if (index == CHROME_BROWSER) {
83 scoped_ptr<FileVersionInfo> version_info(
84 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
85 if (version_info != NULL)
86 info.version = version_info->file_version();
87 // Check if this is one of the child processes whose data we collected
88 // on the IO thread, and if so copy over that data.
89 for (size_t child = 0; child < child_info.size(); child++) {
90 if (child_info[child].pid != info.pid)
91 continue;
92 info.titles = child_info[child].titles;
93 info.type = child_info[child].type;
94 break;
95 }
96 }
97
98 // Add the process info to our list.
99 process_data_[index].processes.push_back(info);
100 }
101 }
102
103 // Finally return to the browser thread.
104 ui_loop_->PostTask(FROM_HERE,
105 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread));
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698