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

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: Don't duplicate the posted_from in stacktrace. Created 3 years, 10 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/message_loop/message_loop.h"
7 #include "base/tracked_objects.h" 8 #include "base/tracked_objects.h"
8 9
9 namespace base { 10 namespace base {
10 11
11 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 12 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
12 OnceClosure task) 13 OnceClosure task)
13 : base::TrackingInfo(posted_from, TimeTicks()), 14 : PendingTask(posted_from, std::move(task), TimeTicks(), true) {}
14 task(std::move(task)),
15 posted_from(posted_from),
16 sequence_num(0),
17 nestable(true),
18 is_high_res(false) {}
19 15
20 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 16 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
21 OnceClosure task, 17 OnceClosure task,
22 TimeTicks delayed_run_time, 18 TimeTicks delayed_run_time,
23 bool nestable) 19 bool nestable)
24 : base::TrackingInfo(posted_from, delayed_run_time), 20 : base::TrackingInfo(posted_from, delayed_run_time),
25 task(std::move(task)), 21 task(std::move(task)),
26 posted_from(posted_from), 22 posted_from(posted_from),
27 sequence_num(0), 23 sequence_num(0),
28 nestable(nestable), 24 nestable(nestable),
29 is_high_res(false) {} 25 is_high_res(false) {
26 const PendingTask* parent_task =
27 MessageLoop::current() ? MessageLoop::current()->current_pending_task_
28 : nullptr;
29 if (parent_task) {
30 task_backtrace[0] = parent_task->posted_from.program_counter();
31 memcpy(&task_backtrace[1], &parent_task->task_backtrace[0],
32 sizeof(task_backtrace[0]) * (arraysize(task_backtrace) - 1));
33 } else {
34 memset(&task_backtrace[0], 0, sizeof(task_backtrace));
35 }
36 }
30 37
31 PendingTask::PendingTask(PendingTask&& other) = default; 38 PendingTask::PendingTask(PendingTask&& other) = default;
32 39
33 PendingTask::~PendingTask() { 40 PendingTask::~PendingTask() {
34 } 41 }
35 42
36 PendingTask& PendingTask::operator=(PendingTask&& other) = default; 43 PendingTask& PendingTask::operator=(PendingTask&& other) = default;
37 44
38 bool PendingTask::operator<(const PendingTask& other) const { 45 bool PendingTask::operator<(const PendingTask& other) const {
39 // Since the top of a priority queue is defined as the "greatest" element, we 46 // Since the top of a priority queue is defined as the "greatest" element, we
40 // need to invert the comparison here. We want the smaller time to be at the 47 // need to invert the comparison here. We want the smaller time to be at the
41 // top of the heap. 48 // top of the heap.
42 49
43 if (delayed_run_time < other.delayed_run_time) 50 if (delayed_run_time < other.delayed_run_time)
44 return false; 51 return false;
45 52
46 if (delayed_run_time > other.delayed_run_time) 53 if (delayed_run_time > other.delayed_run_time)
47 return true; 54 return true;
48 55
49 // If the times happen to match, then we use the sequence number to decide. 56 // If the times happen to match, then we use the sequence number to decide.
50 // Compare the difference to support integer roll-over. 57 // Compare the difference to support integer roll-over.
51 return (sequence_num - other.sequence_num) > 0; 58 return (sequence_num - other.sequence_num) > 0;
52 } 59 }
53 60
54 } // namespace base 61 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698