Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/task_manager/sampling/task_group.h" | 5 #include "chrome/browser/task_manager/sampling/task_group.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/task_manager/sampling/shared_sampler.h" | 13 #include "chrome/browser/task_manager/sampling/shared_sampler.h" |
| 14 #include "chrome/browser/task_manager/task_manager_observer.h" | 14 #include "chrome/browser/task_manager/task_manager_observer.h" |
| 15 #include "components/nacl/browser/nacl_browser.h" | 15 #include "components/nacl/browser/nacl_browser.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/memory_coordinator.h" | 17 #include "content/public/browser/memory_coordinator.h" |
| 18 #include "content/public/common/content_features.h" | 18 #include "content/public/common/content_features.h" |
| 19 #include "gpu/ipc/common/memory_stats.h" | 19 #include "gpu/ipc/common/memory_stats.h" |
| 20 | 20 |
| 21 namespace task_manager { | 21 namespace task_manager { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // A mask for the refresh types that are done in the background thread. | 25 // A mask for the refresh types that are done in the background thread. |
| 26 const int kBackgroundRefreshTypesMask = | 26 const int kBackgroundRefreshTypesMask = |
| 27 REFRESH_TYPE_CPU | REFRESH_TYPE_MEMORY | REFRESH_TYPE_IDLE_WAKEUPS | | 27 REFRESH_TYPE_CPU | REFRESH_TYPE_MEMORY | REFRESH_TYPE_IDLE_WAKEUPS | |
| 28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 29 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME | | 29 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME | |
| 30 #endif // defined(OS_WIN) | 30 #endif // defined(OS_WIN) |
| 31 #if defined(OS_LINUX) | 31 #if defined(OS_LINUX) |
| 32 REFRESH_TYPE_FD_COUNT | | 32 REFRESH_TYPE_FD_COUNT | |
| 33 #endif // defined(OS_LINUX) | 33 #endif // defined(OS_LINUX) |
| 34 REFRESH_TYPE_NACL || | |
|
afakhry
2017/01/23 20:58:38
I should have caught this, sorry.
| |
| 34 REFRESH_TYPE_PRIORITY; | 35 REFRESH_TYPE_PRIORITY; |
| 35 | 36 |
| 36 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 37 // Gets the GDI and USER Handles on Windows at one shot. | 38 // Gets the GDI and USER Handles on Windows at one shot. |
| 38 void GetWindowsHandles(base::ProcessHandle handle, | 39 void GetWindowsHandles(base::ProcessHandle handle, |
| 39 int64_t* out_gdi_current, | 40 int64_t* out_gdi_current, |
| 40 int64_t* out_gdi_peak, | 41 int64_t* out_gdi_peak, |
| 41 int64_t* out_user_current, | 42 int64_t* out_user_current, |
| 42 int64_t* out_user_peak) { | 43 int64_t* out_user_peak) { |
| 43 *out_gdi_current = 0; | 44 *out_gdi_current = 0; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } | 170 } |
| 170 | 171 |
| 171 // 3- Refresh Windows handles (if enabled). | 172 // 3- Refresh Windows handles (if enabled). |
| 172 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
| 173 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, | 174 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, |
| 174 refresh_flags)) { | 175 refresh_flags)) { |
| 175 RefreshWindowsHandles(); | 176 RefreshWindowsHandles(); |
| 176 } | 177 } |
| 177 #endif // defined(OS_WIN) | 178 #endif // defined(OS_WIN) |
| 178 | 179 |
| 179 // 4- Refresh the NACL debug stub port (if enabled). | 180 // 4- Refresh the NACL debug stub port (if enabled). This calls out to |
| 181 // NaClBrowser on the browser's IO thread, completing asynchronously. | |
| 180 #if !defined(DISABLE_NACL) | 182 #if !defined(DISABLE_NACL) |
| 181 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, | 183 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, |
| 182 refresh_flags) && | 184 refresh_flags) && |
| 183 !tasks_.empty()) { | 185 !tasks_.empty()) { |
| 184 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); | 186 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); |
| 185 } | 187 } |
| 186 #endif // !defined(DISABLE_NACL) | 188 #endif // !defined(DISABLE_NACL) |
| 187 | 189 |
| 188 int64_t shared_refresh_flags = | 190 int64_t shared_refresh_flags = |
| 189 refresh_flags & shared_sampler_->GetSupportedFlags(); | 191 refresh_flags & shared_sampler_->GetSupportedFlags(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 void TaskGroup::RefreshWindowsHandles() { | 250 void TaskGroup::RefreshWindowsHandles() { |
| 249 #if defined(OS_WIN) | 251 #if defined(OS_WIN) |
| 250 GetWindowsHandles(process_handle_, | 252 GetWindowsHandles(process_handle_, |
| 251 &gdi_current_handles_, | 253 &gdi_current_handles_, |
| 252 &gdi_peak_handles_, | 254 &gdi_peak_handles_, |
| 253 &user_current_handles_, | 255 &user_current_handles_, |
| 254 &user_peak_handles_); | 256 &user_peak_handles_); |
| 255 #endif // defined(OS_WIN) | 257 #endif // defined(OS_WIN) |
| 256 } | 258 } |
| 257 | 259 |
| 260 #if !defined(DISABLE_NACL) | |
| 258 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { | 261 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { |
| 259 #if !defined(DISABLE_NACL) | |
| 260 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 262 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| 261 nacl_debug_stub_port_ = | 263 content::BrowserThread::PostTaskAndReplyWithResult( |
| 262 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); | 264 content::BrowserThread::IO, FROM_HERE, |
| 265 base::Bind(&nacl::NaClBrowser::GetProcessGdbDebugStubPort, | |
| 266 base::Unretained(nacl_browser), child_process_unique_id), | |
| 267 base::Bind(&TaskGroup::OnRefreshNaClDebugStubPortDone, | |
| 268 weak_ptr_factory_.GetWeakPtr())); | |
| 269 } | |
| 270 | |
| 271 void TaskGroup::OnRefreshNaClDebugStubPortDone(int nacl_debug_stub_port) { | |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 273 | |
| 274 nacl_debug_stub_port_ = nacl_debug_stub_port; | |
| 275 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_NACL); | |
| 276 } | |
| 263 #endif // !defined(DISABLE_NACL) | 277 #endif // !defined(DISABLE_NACL) |
| 264 } | |
| 265 | 278 |
| 266 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { | 279 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { |
| 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 268 | 281 |
| 269 cpu_usage_ = cpu_usage; | 282 cpu_usage_ = cpu_usage; |
| 270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); | 283 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); |
| 271 } | 284 } |
| 272 | 285 |
| 273 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { | 286 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { |
| 274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 344 |
| 332 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 345 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 346 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 334 | 347 |
| 335 current_on_bg_done_flags_ |= finished_refresh_type; | 348 current_on_bg_done_flags_ |= finished_refresh_type; |
| 336 if (AreBackgroundCalculationsDone()) | 349 if (AreBackgroundCalculationsDone()) |
| 337 on_background_calculations_done_.Run(); | 350 on_background_calculations_done_.Run(); |
| 338 } | 351 } |
| 339 | 352 |
| 340 } // namespace task_manager | 353 } // namespace task_manager |
| OLD | NEW |