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

Side by Side Diff: content/renderer/scheduler/task_queue_manager.cc

Issue 681793003: scheduler: Add support for tracing scheduler state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/scheduler/task_queue_manager.h" 5 #include "content/renderer/scheduler/task_queue_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/debug/trace_event_argument.h"
9 #include "content/renderer/scheduler/task_queue_selector.h" 10 #include "content/renderer/scheduler/task_queue_selector.h"
10 11
11 namespace content { 12 namespace content {
12 namespace internal { 13 namespace internal {
13 14
14 class TaskQueue : public base::SingleThreadTaskRunner { 15 class TaskQueue : public base::SingleThreadTaskRunner {
15 public: 16 public:
16 TaskQueue(TaskQueueManager* task_queue_manager); 17 TaskQueue(TaskQueueManager* task_queue_manager);
17 18
18 // base::SingleThreadTaskRunner implementation. 19 // base::SingleThreadTaskRunner implementation.
(...skipping 16 matching lines...) Expand all
35 void SetAutoPump(bool auto_pump); 36 void SetAutoPump(bool auto_pump);
36 void PumpQueue(); 37 void PumpQueue();
37 38
38 bool UpdateWorkQueue(); 39 bool UpdateWorkQueue();
39 base::PendingTask TakeTaskFromWorkQueue(); 40 base::PendingTask TakeTaskFromWorkQueue();
40 41
41 void WillDeleteTaskQueueManager(); 42 void WillDeleteTaskQueueManager();
42 43
43 base::TaskQueue& work_queue() { return work_queue_; } 44 base::TaskQueue& work_queue() { return work_queue_; }
44 45
46 void AsValueInto(base::debug::TracedValue* state);
47
45 private: 48 private:
46 virtual ~TaskQueue(); 49 virtual ~TaskQueue();
47 50
48 void PumpQueueLocked(); 51 void PumpQueueLocked();
49 void EnqueueTaskLocked(const base::PendingTask& pending_task); 52 void EnqueueTaskLocked(const base::PendingTask& pending_task);
50 53
51 // This lock protects all members except the work queue. 54 // This lock protects all members except the work queue.
52 mutable base::Lock lock_; 55 mutable base::Lock lock_;
53 TaskQueueManager* task_queue_manager_; 56 TaskQueueManager* task_queue_manager_;
54 base::TaskQueue incoming_queue_; 57 base::TaskQueue incoming_queue_;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 171 }
169 if (!work_queue_.empty()) 172 if (!work_queue_.empty())
170 task_queue_manager_->PostDoWorkOnMainRunner(); 173 task_queue_manager_->PostDoWorkOnMainRunner();
171 } 174 }
172 175
173 void TaskQueue::PumpQueue() { 176 void TaskQueue::PumpQueue() {
174 base::AutoLock lock(lock_); 177 base::AutoLock lock(lock_);
175 PumpQueueLocked(); 178 PumpQueueLocked();
176 } 179 }
177 180
178 } // namespace 181 void TaskQueue::AsValueInto(base::debug::TracedValue* state) {
182 base::AutoLock lock(lock_);
183 state->BeginDictionary();
184 state->BeginArray("incoming_queue");
185 TaskQueueManager::QueueAsValueInto(incoming_queue_, state);
186 state->EndArray();
187 state->BeginArray("work_queue");
188 TaskQueueManager::QueueAsValueInto(work_queue_, state);
189 state->EndArray();
190 state->SetBoolean("auto_pump", auto_pump_);
191 state->EndDictionary();
192 }
193
194 } // namespace internal
179 195
180 TaskQueueManager::TaskQueueManager( 196 TaskQueueManager::TaskQueueManager(
181 size_t task_queue_count, 197 size_t task_queue_count,
182 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 198 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
183 TaskQueueSelector* selector) 199 TaskQueueSelector* selector)
184 : main_task_runner_(main_task_runner), 200 : main_task_runner_(main_task_runner),
185 selector_(selector), 201 selector_(selector),
186 weak_factory_(this) { 202 weak_factory_(this) {
187 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); 203 DCHECK(main_task_runner->RunsTasksOnCurrentThread());
188 204
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 301 }
286 302
287 bool TaskQueueManager::PostNonNestableDelayedTask( 303 bool TaskQueueManager::PostNonNestableDelayedTask(
288 const tracked_objects::Location& from_here, 304 const tracked_objects::Location& from_here,
289 const base::Closure& task, 305 const base::Closure& task,
290 base::TimeDelta delay) { 306 base::TimeDelta delay) {
291 // Defer non-nestable work to the main task runner. 307 // Defer non-nestable work to the main task runner.
292 return main_task_runner_->PostNonNestableDelayedTask(from_here, task, delay); 308 return main_task_runner_->PostNonNestableDelayedTask(from_here, task, delay);
293 } 309 }
294 310
311 void TaskQueueManager::AsValueInto(base::debug::TracedValue* state) const {
312 main_thread_checker_.CalledOnValidThread();
313 state->BeginArray("queues");
314 for (auto& queue : queues_)
315 queue->AsValueInto(state);
316 state->EndArray();
317 }
318
319 // static
320 void TaskQueueManager::QueueAsValueInto(const base::TaskQueue& queue,
321 base::debug::TracedValue* state) {
322 base::TaskQueue queue_copy(queue);
323 state->BeginDictionary();
324 state->BeginArray("tasks");
325 while (!queue_copy.empty()) {
326 TaskAsValueInto(queue_copy.front(), state);
327 queue_copy.pop();
328 }
329 state->EndArray();
330 state->EndDictionary();
331 }
332
333 // static
334 void TaskQueueManager::TaskAsValueInto(const base::PendingTask& task,
335 base::debug::TracedValue* state) {
336 state->BeginDictionary();
337 state->SetString("posted_from", task.posted_from.ToString());
338 state->SetInteger("sequence_num", task.sequence_num);
picksi1 2014/10/28 11:01:40 do we need the underscores in the strings here?
Sami 2014/10/28 12:57:47 As opposed to camelCase? I think underscores are c
picksi1 2014/10/28 13:38:59 As opposed to spaces! I assume this string ends in
Sami 2014/10/28 13:42:00 You could have spaces here per the json spec, but
339 state->SetBoolean("nestable", task.nestable);
340 state->SetBoolean("is_high_res", task.is_high_res);
341 state->SetDouble(
342 "time_posted",
343 (task.time_posted - base::TimeTicks()).InMicroseconds() / 1000.0L);
344 state->SetDouble(
picksi1 2014/10/28 11:01:40 ditto: InMillisecondsF?
Sami 2014/10/28 12:57:48 Done.
345 "delayed_run_time",
346 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
347 state->EndDictionary();
348 }
349
295 } // namespace content 350 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698