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

Unified Diff: chrome/browser/memory_details.cc

Issue 159777: Add about:memory support for Linux.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/memory_details.cc
===================================================================
--- chrome/browser/memory_details.cc (revision 22256)
+++ chrome/browser/memory_details.cc (working copy)
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "chrome/browser/memory_details.h"
-#include <psapi.h>
#include "app/l10n_util.h"
#include "base/file_version_info.h"
@@ -17,12 +16,6 @@
#include "chrome/common/url_constants.h"
#include "grit/chromium_strings.h"
-class RenderViewHostDelegate;
-
-// Template of static data we use for finding browser process information.
-// These entries must match the ordering for MemoryDetails::BrowserProcess.
-static ProcessData g_process_template[MemoryDetails::MAX_BROWSERS];
-
// About threading:
//
// This operation will hit no fewer than 3 threads.
@@ -36,26 +29,6 @@
// expensive parts of this operation over on the file thread.
//
-MemoryDetails::MemoryDetails()
- : ui_loop_(NULL) {
- static const std::wstring google_browser_name =
- l10n_util::GetString(IDS_PRODUCT_NAME);
- ProcessData g_process_template[MemoryDetails::MAX_BROWSERS] = {
- { google_browser_name.c_str(), L"chrome.exe", },
- { L"IE", L"iexplore.exe", },
- { L"Firefox", L"firefox.exe", },
- { L"Opera", L"opera.exe", },
- { L"Safari", L"safari.exe", },
- { L"IE (64bit)", L"iexplore.exe", },
- { L"Konqueror", L"konqueror.exe", },
- };
-
- for (int index = 0; index < arraysize(g_process_template); ++index) {
- process_data_[index].name = g_process_template[index].name;
- process_data_[index].process_name = g_process_template[index].process_name;
- }
-}
-
void MemoryDetails::StartFetch() {
ui_loop_ = MessageLoop::current();
@@ -91,106 +64,12 @@
NewRunnableMethod(this, &MemoryDetails::CollectProcessData, child_info));
}
-void MemoryDetails::CollectProcessData(
- std::vector<ProcessMemoryInformation> child_info) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::FILE));
-
- // Clear old data.
- for (int index = 0; index < arraysize(g_process_template); index++)
- process_data_[index].processes.clear();
-
- SYSTEM_INFO system_info;
- GetNativeSystemInfo(&system_info);
- bool is_64bit_os =
- system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64;
-
- ScopedHandle snapshot(::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
- PROCESSENTRY32 process_entry = {sizeof(PROCESSENTRY32)};
- if (!snapshot.Get()) {
- LOG(ERROR) << "CreateToolhelp32Snaphot failed: " << GetLastError();
- return;
- }
- if (!::Process32First(snapshot, &process_entry)) {
- LOG(ERROR) << "Process32First failed: " << GetLastError();
- return;
- }
- do {
- int pid = process_entry.th32ProcessID;
- ScopedHandle handle(::OpenProcess(
- PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid));
- if (!handle.Get())
- continue;
- bool is_64bit_process = false;
- // IsWow64Process() returns FALSE for a 32bit process on a 32bit OS.
- // We need to check if the real OS is 64bit.
- if (is_64bit_os) {
- BOOL is_wow64 = FALSE;
- // IsWow64Process() is supported by Windows XP SP2 or later.
- IsWow64Process(handle, &is_wow64);
- is_64bit_process = !is_wow64;
- }
- for (int index2 = 0; index2 < arraysize(g_process_template); index2++) {
- if (_wcsicmp(process_data_[index2].process_name,
- process_entry.szExeFile) != 0)
- continue;
- if (index2 == IE_BROWSER && is_64bit_process)
- continue; // Should use IE_64BIT_BROWSER
- // Get Memory Information.
- ProcessMemoryInformation info;
- info.pid = pid;
- if (info.pid == GetCurrentProcessId())
- info.type = ChildProcessInfo::BROWSER_PROCESS;
- else
- info.type = ChildProcessInfo::UNKNOWN_PROCESS;
-
- scoped_ptr<base::ProcessMetrics> metrics;
- metrics.reset(base::ProcessMetrics::CreateProcessMetrics(handle));
- metrics->GetCommittedKBytes(&info.committed);
- metrics->GetWorkingSetKBytes(&info.working_set);
-
- // Get Version Information.
- TCHAR name[MAX_PATH];
- if (index2 == CHROME_BROWSER) {
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
- if (version_info != NULL)
- info.version = version_info->file_version();
- // Check if this is one of the child processes whose data we collected
- // on the IO thread, and if so copy over that data.
- for (size_t child = 0; child < child_info.size(); child++) {
- if (child_info[child].pid != info.pid)
- continue;
- info.titles = child_info[child].titles;
- info.type = child_info[child].type;
- break;
- }
- } else if (GetModuleFileNameEx(handle, NULL, name, MAX_PATH - 1)) {
- std::wstring str_name(name);
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfo(str_name));
- if (version_info != NULL) {
- info.version = version_info->product_version();
- info.product_name = version_info->product_name();
- }
- }
-
- // Add the process info to our list.
- process_data_[index2].processes.push_back(info);
- break;
- }
- } while (::Process32Next(snapshot, &process_entry));
-
- // Finally return to the browser thread.
- ui_loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread));
-}
-
void MemoryDetails::CollectChildInfoOnUIThread() {
DCHECK(MessageLoop::current() == ui_loop_);
+ ProcessData* chrome_browser = ChromeBrowser();
// Get more information about the process.
- for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size();
+ for (size_t index = 0; index < chrome_browser->processes.size();
index++) {
// Check if it's a renderer, if so get the list of page titles in it and
// check if it's a diagnostics-related process. We skip all diagnostics
@@ -201,7 +80,7 @@
RenderProcessHost::end(); ++renderer_iter) {
DCHECK(renderer_iter->second);
ProcessMemoryInformation& process =
- process_data_[CHROME_BROWSER].processes[index];
+ chrome_browser->processes[index];
if (process.pid != renderer_iter->second->process().pid())
continue;
process.type = ChildProcessInfo::RENDER_PROCESS;
@@ -259,12 +138,12 @@
}
// Get rid of other Chrome processes that are from a different profile.
- for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size();
+ for (size_t index = 0; index < chrome_browser->processes.size();
index++) {
- if (process_data_[CHROME_BROWSER].processes[index].type ==
+ if (chrome_browser->processes[index].type ==
ChildProcessInfo::UNKNOWN_PROCESS) {
- process_data_[CHROME_BROWSER].processes.erase(
- process_data_[CHROME_BROWSER].processes.begin() + index);
+ chrome_browser->processes.erase(
+ chrome_browser->processes.begin() + index);
index--;
}
}
@@ -278,7 +157,7 @@
// Reports a set of memory metrics to UMA.
// Memory is measured in units of 10KB.
- ProcessData browser = process_data_[CHROME_BROWSER];
+ const ProcessData& browser = *ChromeBrowser();
size_t aggregate_memory = 0;
int plugin_count = 0;
int worker_count = 0;
@@ -300,6 +179,8 @@
UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample);
worker_count++;
break;
+ default:
Evan Martin 2009/08/03 05:16:11 Should this have a NOTREACHED() here?
Joel Stanley (old) 2009/08/03 16:02:37 Where does the zgyote fall into this?
+ break;
}
}

Powered by Google App Engine
This is Rietveld 408576698