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

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
« no previous file with comments | « base/threading/worker_pool_posix.cc ('k') | base/tracked_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(TRACK_ALL_TASK_OBJECTS)
51 TimeTicks start_of_run = tracked_objects::ThreadData::Now();
52 #endif // defined(TRACK_ALL_TASK_OBJECTS)
49 pending_task->task.Run(); 53 pending_task->task.Run();
50 #if defined(TRACK_ALL_TASK_OBJECTS) 54 #if defined(TRACK_ALL_TASK_OBJECTS)
51 tracked_objects::ThreadData::TallyADeathIfActive( 55 tracked_objects::ThreadData::TallyADeathIfActive(pending_task->post_births,
52 pending_task->post_births, 56 pending_task->time_posted, TimeTicks::TimeTicks(), start_of_run);
53 TimeTicks::Now() - pending_task->time_posted);
54 #endif // defined(TRACK_ALL_TASK_OBJECTS) 57 #endif // defined(TRACK_ALL_TASK_OBJECTS)
58
55 delete pending_task; 59 delete pending_task;
56 return 0; 60 return 0;
57 } 61 }
58 62
59 // Takes ownership of |pending_task| 63 // Takes ownership of |pending_task|
60 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { 64 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) {
61 ULONG flags = 0; 65 ULONG flags = 0;
62 if (task_is_slow) 66 if (task_is_slow)
63 flags |= WT_EXECUTELONGFUNCTION; 67 flags |= WT_EXECUTELONGFUNCTION;
64 68
(...skipping 17 matching lines...) Expand all
82 return PostTaskInternal(pending_task, task_is_slow); 86 return PostTaskInternal(pending_task, task_is_slow);
83 } 87 }
84 88
85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 89 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
86 const base::Closure& task, bool task_is_slow) { 90 const base::Closure& task, bool task_is_slow) {
87 PendingTask* pending_task = new PendingTask(from_here, task); 91 PendingTask* pending_task = new PendingTask(from_here, task);
88 return PostTaskInternal(pending_task, task_is_slow); 92 return PostTaskInternal(pending_task, task_is_slow);
89 } 93 }
90 94
91 } // namespace base 95 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/worker_pool_posix.cc ('k') | base/tracked_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698