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

Side by Side Diff: base/pending_task.cc

Issue 1044413002: Record async "task backtraces" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/pending_task.h" 5 #include "base/pending_task.h"
6 6
7 #include "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 11 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
12 const PendingTask* parent_task,
12 const base::Closure& task) 13 const base::Closure& task)
13 : base::TrackingInfo(posted_from, TimeTicks()), 14 : base::TrackingInfo(posted_from, TimeTicks()),
14 task(task), 15 task(task),
15 posted_from(posted_from), 16 posted_from(posted_from),
16 sequence_num(0), 17 sequence_num(0),
17 nestable(true), 18 nestable(true),
18 is_high_res(false) { 19 is_high_res(false) {
20 task_backtrace[0] = posted_from.program_counter();
21 if (parent_task) {
22 memcpy(&task_backtrace[1], &parent_task->task_backtrace[0],
23 sizeof(task_backtrace[0]) * ARRAYSIZE_UNSAFE(task_backtrace) - 1);
24 }
19 } 25 }
20 26
21 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 27 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
28 const PendingTask* parent_task,
22 const base::Closure& task, 29 const base::Closure& task,
23 TimeTicks delayed_run_time, 30 TimeTicks delayed_run_time,
24 bool nestable) 31 bool nestable)
25 : base::TrackingInfo(posted_from, delayed_run_time), 32 : base::TrackingInfo(posted_from, delayed_run_time),
26 task(task), 33 task(task),
27 posted_from(posted_from), 34 posted_from(posted_from),
28 sequence_num(0), 35 sequence_num(0),
29 nestable(nestable), 36 nestable(nestable),
30 is_high_res(false) { 37 is_high_res(false) {
38 task_backtrace[0] = posted_from.program_counter();
39 if (parent_task) {
40 memcpy(&task_backtrace[1], &parent_task->task_backtrace[0],
41 sizeof(task_backtrace[0]) * ARRAYSIZE_UNSAFE(task_backtrace) - 1);
42 }
31 } 43 }
32 44
33 PendingTask::~PendingTask() { 45 PendingTask::~PendingTask() {
34 } 46 }
35 47
36 bool PendingTask::operator<(const PendingTask& other) const { 48 bool PendingTask::operator<(const PendingTask& other) const {
37 // Since the top of a priority queue is defined as the "greatest" element, we 49 // Since the top of a priority queue is defined as the "greatest" element, we
38 // need to invert the comparison here. We want the smaller time to be at the 50 // need to invert the comparison here. We want the smaller time to be at the
39 // top of the heap. 51 // top of the heap.
40 52
41 if (delayed_run_time < other.delayed_run_time) 53 if (delayed_run_time < other.delayed_run_time)
42 return false; 54 return false;
43 55
44 if (delayed_run_time > other.delayed_run_time) 56 if (delayed_run_time > other.delayed_run_time)
45 return true; 57 return true;
46 58
47 // If the times happen to match, then we use the sequence number to decide. 59 // If the times happen to match, then we use the sequence number to decide.
48 // Compare the difference to support integer roll-over. 60 // Compare the difference to support integer roll-over.
49 return (sequence_num - other.sequence_num) > 0; 61 return (sequence_num - other.sequence_num) > 0;
50 } 62 }
51 63
52 void TaskQueue::Swap(TaskQueue* queue) { 64 void TaskQueue::Swap(TaskQueue* queue) {
53 c.swap(queue->c); // Calls std::deque::swap. 65 c.swap(queue->c); // Calls std::deque::swap.
54 } 66 }
55 67
56 } // namespace base 68 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698