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

Side by Side Diff: base/threading/worker_pool_win.cc

Issue 8233037: Update task tracking to not depend on message_loop_ singleton (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
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/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/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "base/tracked_objects.h" 11 #include "base/tracked_objects.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 namespace { 15 namespace {
16 16
17 struct PendingTask { 17 struct PendingTask {
18 PendingTask( 18 PendingTask(
19 const tracked_objects::Location& posted_from, 19 const tracked_objects::Location& posted_from,
20 const base::Closure& task) 20 const base::Closure& task)
21 : posted_from(posted_from), 21 : posted_from(posted_from),
22 task(task) { 22 task(task) {
23 #if defined(TRACK_ALL_TASK_OBJECTS) 23 #if defined(TRACK_ALL_TASK_OBJECTS)
24 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); 24 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
25 time_posted = TimeTicks::Now(); 25 time_posted = tracked_objects::ThreadData::Now();
26 #endif // defined(TRACK_ALL_TASK_OBJECTS) 26 #endif // defined(TRACK_ALL_TASK_OBJECTS)
27 } 27 }
28 28
29 #if defined(TRACK_ALL_TASK_OBJECTS) 29 #if defined(TRACK_ALL_TASK_OBJECTS)
30 // Counter for location where the Closure was posted from. 30 // Counter for location where the Closure was posted from.
31 tracked_objects::Births* post_births; 31 tracked_objects::Births* post_births;
32 32
33 // Time the task was posted. 33 // Time the task was posted.
34 TimeTicks time_posted; 34 TimeTicks time_posted;
35 #endif // defined(TRACK_ALL_TASK_OBJECTS) 35 #endif // defined(TRACK_ALL_TASK_OBJECTS)
36 36
37 // The site this PendingTask was posted from. 37 // The site this PendingTask was posted from.
38 tracked_objects::Location posted_from; 38 tracked_objects::Location posted_from;
39 39
40 // The task to run. 40 // The task to run.
41 base::Closure task; 41 base::Closure task;
42 }; 42 };
43 43
44 DWORD CALLBACK WorkItemCallback(void* param) { 44 DWORD CALLBACK WorkItemCallback(void* param) {
45 PendingTask* pending_task = static_cast<PendingTask*>(param); 45 PendingTask* pending_task = static_cast<PendingTask*>(param);
46 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", 46 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run",
47 "src_file", pending_task->posted_from.file_name(), 47 "src_file", pending_task->posted_from.file_name(),
48 "src_func", pending_task->posted_from.function_name()); 48 "src_func", pending_task->posted_from.function_name());
49
50 TimeTicks start_of_run = tracked_objects::ThreadData::Now();
49 pending_task->task.Run(); 51 pending_task->task.Run();
50 #if defined(TRACK_ALL_TASK_OBJECTS) 52 tracked_objects::ThreadData::TallyADeathIfActive(pending_task->post_births,
51 tracked_objects::ThreadData::TallyADeathIfActive( 53 pending_task->time_posted,
52 pending_task->post_births, 54 start_of_run,
53 TimeTicks::Now() - pending_task->time_posted); 55 NULL);
54 #endif // defined(TRACK_ALL_TASK_OBJECTS) 56
55 delete pending_task; 57 delete pending_task;
56 return 0; 58 return 0;
57 } 59 }
58 60
59 // Takes ownership of |pending_task| 61 // Takes ownership of |pending_task|
60 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { 62 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) {
61 ULONG flags = 0; 63 ULONG flags = 0;
62 if (task_is_slow) 64 if (task_is_slow)
63 flags |= WT_EXECUTELONGFUNCTION; 65 flags |= WT_EXECUTELONGFUNCTION;
64 66
(...skipping 17 matching lines...) Expand all
82 return PostTaskInternal(pending_task, task_is_slow); 84 return PostTaskInternal(pending_task, task_is_slow);
83 } 85 }
84 86
85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 87 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
86 const base::Closure& task, bool task_is_slow) { 88 const base::Closure& task, bool task_is_slow) {
87 PendingTask* pending_task = new PendingTask(from_here, task); 89 PendingTask* pending_task = new PendingTask(from_here, task);
88 return PostTaskInternal(pending_task, task_is_slow); 90 return PostTaskInternal(pending_task, task_is_slow);
89 } 91 }
90 92
91 } // namespace base 93 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698