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

Side by Side Diff: content/renderer/categorized_worker_pool.cc

Issue 2047433004: content: Add heartbeat trace for CategorizedWorkerPool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 6 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
« no previous file with comments | « content/renderer/categorized_worker_pool.h ('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 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 "content/renderer/categorized_worker_pool.h" 5 #include "content/renderer/categorized_worker_pool.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "cc/base/math_util.h" 14 #include "cc/base/math_util.h"
15 #include "cc/raster/task_category.h" 15 #include "cc/raster/task_category.h"
16 16
17 namespace content { 17 namespace content {
18 namespace { 18 namespace {
19 19
20 constexpr int kHeartbeatIntervalInSeconds = 60; // 1 minute
21
20 // A thread which forwards to CategorizedWorkerPool::Run with the runnable 22 // A thread which forwards to CategorizedWorkerPool::Run with the runnable
21 // categories. 23 // categories.
22 class CategorizedWorkerPoolThread : public base::SimpleThread { 24 class CategorizedWorkerPoolThread : public base::SimpleThread {
23 public: 25 public:
24 CategorizedWorkerPoolThread( 26 CategorizedWorkerPoolThread(
25 const std::string& name_prefix, 27 const std::string& name_prefix,
26 const Options& options, 28 const Options& options,
27 CategorizedWorkerPool* pool, 29 CategorizedWorkerPool* pool,
28 std::vector<cc::TaskCategory> categories, 30 std::vector<cc::TaskCategory> categories,
29 base::ConditionVariable* has_ready_to_run_tasks_cv) 31 base::ConditionVariable* has_ready_to_run_tasks_cv)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!RunTaskWithLockAcquired(categories)) { 234 if (!RunTaskWithLockAcquired(categories)) {
233 // We are no longer running tasks, which may allow another category to 235 // We are no longer running tasks, which may allow another category to
234 // start running. Signal other worker threads. 236 // start running. Signal other worker threads.
235 SignalHasReadyToRunTasksWithLockAcquired(); 237 SignalHasReadyToRunTasksWithLockAcquired();
236 238
237 // Exit when shutdown is set and no more tasks are pending. 239 // Exit when shutdown is set and no more tasks are pending.
238 if (shutdown_) 240 if (shutdown_)
239 break; 241 break;
240 242
241 // Wait for more tasks. 243 // Wait for more tasks.
242 has_ready_to_run_tasks_cv->Wait(); 244 WaitForMoreTasksWithLockAcquired(has_ready_to_run_tasks_cv);
243 continue; 245 continue;
244 } 246 }
245 } 247 }
246 } 248 }
247 249
250 void CategorizedWorkerPool::WaitForMoreTasksWithLockAcquired(
251 base::ConditionVariable* has_ready_to_run_tasks_cv) {
252 const base::TimeDelta timeout =
253 base::TimeDelta::FromSeconds(kHeartbeatIntervalInSeconds);
254 while (has_ready_to_run_tasks_cv->TimedWait(timeout)) {
255 TRACE_EVENT_INSTANT0(
256 "heartbeat", "CategorizedWorkerPool::HeartbeatDuringWaitForMoreTasks",
257 TRACE_EVENT_SCOPE_THREAD);
258 }
259 }
260
248 void CategorizedWorkerPool::FlushForTesting() { 261 void CategorizedWorkerPool::FlushForTesting() {
249 base::AutoLock lock(lock_); 262 base::AutoLock lock(lock_);
250 263
251 while (!work_queue_.HasFinishedRunningTasksInAllNamespaces()) { 264 while (!work_queue_.HasFinishedRunningTasksInAllNamespaces()) {
252 has_namespaces_with_finished_running_tasks_cv_.Wait(); 265 has_namespaces_with_finished_running_tasks_cv_.Wait();
253 } 266 }
254 } 267 }
255 268
256 scoped_refptr<base::SequencedTaskRunner> 269 scoped_refptr<base::SequencedTaskRunner>
257 CategorizedWorkerPool::CreateSequencedTaskRunner() { 270 CategorizedWorkerPool::CreateSequencedTaskRunner() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 435
423 // Overridden from cc::Task: 436 // Overridden from cc::Task:
424 void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() { 437 void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() {
425 closure_.Run(); 438 closure_.Run();
426 closure_.Reset(); 439 closure_.Reset();
427 } 440 }
428 441
429 CategorizedWorkerPool::ClosureTask::~ClosureTask() {} 442 CategorizedWorkerPool::ClosureTask::~ClosureTask() {}
430 443
431 } // namespace content 444 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/categorized_worker_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698