OLD | NEW |
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/threading/worker_pool.h" | 5 #include "base/threading/worker_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/task.h" | 10 #include "base/task.h" |
10 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 struct PendingTask { | 17 struct PendingTask { |
17 PendingTask( | 18 PendingTask( |
18 const tracked_objects::Location& posted_from, | 19 const tracked_objects::Location& posted_from, |
19 const base::Closure& task) | 20 const base::Closure& task) |
20 : task(task) { | 21 : posted_from(posted_from), |
| 22 task(task) { |
21 #if defined(TRACK_ALL_TASK_OBJECTS) | 23 #if defined(TRACK_ALL_TASK_OBJECTS) |
22 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | 24 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); |
23 time_posted = TimeTicks::Now(); | 25 time_posted = TimeTicks::Now(); |
24 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 26 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
25 } | 27 } |
26 | 28 |
27 #if defined(TRACK_ALL_TASK_OBJECTS) | 29 #if defined(TRACK_ALL_TASK_OBJECTS) |
28 // Counter for location where the Closure was posted from. | 30 // Counter for location where the Closure was posted from. |
29 tracked_objects::Births* post_births; | 31 tracked_objects::Births* post_births; |
30 | 32 |
31 // Time the task was posted. | 33 // Time the task was posted. |
32 TimeTicks time_posted; | 34 TimeTicks time_posted; |
33 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 35 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
34 | 36 |
| 37 // The site this PendingTask was posted from. |
| 38 tracked_objects::Location posted_from; |
| 39 |
35 // The task to run. | 40 // The task to run. |
36 base::Closure task; | 41 base::Closure task; |
37 }; | 42 }; |
38 | 43 |
39 DWORD CALLBACK WorkItemCallback(void* param) { | 44 DWORD CALLBACK WorkItemCallback(void* param) { |
40 PendingTask* pending_task = static_cast<PendingTask*>(param); | 45 PendingTask* pending_task = static_cast<PendingTask*>(param); |
| 46 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", |
| 47 "src_file", pending_task->posted_from.file_name(), |
| 48 "src_func", pending_task->posted_from.function_name()); |
41 pending_task->task.Run(); | 49 pending_task->task.Run(); |
42 #if defined(TRACK_ALL_TASK_OBJECTS) | 50 #if defined(TRACK_ALL_TASK_OBJECTS) |
43 tracked_objects::ThreadData::TallyADeathIfActive( | 51 tracked_objects::ThreadData::TallyADeathIfActive( |
44 pending_task->post_births, | 52 pending_task->post_births, |
45 TimeTicks::Now() - pending_task->time_posted); | 53 TimeTicks::Now() - pending_task->time_posted); |
46 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 54 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
47 delete pending_task; | 55 delete pending_task; |
48 return 0; | 56 return 0; |
49 } | 57 } |
50 | 58 |
(...skipping 23 matching lines...) Expand all Loading... |
74 return PostTaskInternal(pending_task, task_is_slow); | 82 return PostTaskInternal(pending_task, task_is_slow); |
75 } | 83 } |
76 | 84 |
77 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
78 const base::Closure& task, bool task_is_slow) { | 86 const base::Closure& task, bool task_is_slow) { |
79 PendingTask* pending_task = new PendingTask(from_here, task); | 87 PendingTask* pending_task = new PendingTask(from_here, task); |
80 return PostTaskInternal(pending_task, task_is_slow); | 88 return PostTaskInternal(pending_task, task_is_slow); |
81 } | 89 } |
82 | 90 |
83 } // namespace base | 91 } // namespace base |
OLD | NEW |