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

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

Issue 7778033: Add trace code to track all posted tasks in message_loop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trace_event.h formatting fix 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.h ('k') | base/threading/worker_pool_win.cc » ('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_posix.h" 5 #include "base/threading/worker_pool_posix.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "base/task.h" 13 #include "base/task.h"
13 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
14 #include "base/threading/worker_pool.h" 15 #include "base/threading/worker_pool.h"
15 #include "base/tracked_objects.h" 16 #include "base/tracked_objects.h"
16 17
17 namespace base { 18 namespace base {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 void WorkerThread::ThreadMain() { 78 void WorkerThread::ThreadMain() {
78 const std::string name = base::StringPrintf( 79 const std::string name = base::StringPrintf(
79 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId()); 80 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId());
80 PlatformThread::SetName(name.c_str()); 81 PlatformThread::SetName(name.c_str());
81 82
82 for (;;) { 83 for (;;) {
83 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask(); 84 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask();
84 if (pending_task.task.is_null()) 85 if (pending_task.task.is_null())
85 break; 86 break;
87 UNSHIPPED_TRACE_EVENT2("task", "WorkerThread::ThreadMain::Run",
88 "src_file", pending_task.posted_from.file_name(),
89 "src_func", pending_task.posted_from.function_name());
86 pending_task.task.Run(); 90 pending_task.task.Run();
87 } 91 }
88 92
89 // The WorkerThread is non-joinable, so it deletes itself. 93 // The WorkerThread is non-joinable, so it deletes itself.
90 delete this; 94 delete this;
91 } 95 }
92 96
93 } // namespace 97 } // namespace
94 98
95 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 99 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
96 Task* task, bool task_is_slow) { 100 Task* task, bool task_is_slow) {
97 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); 101 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow);
98 return true; 102 return true;
99 } 103 }
100 104
101 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 105 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
102 const base::Closure& task, bool task_is_slow) { 106 const base::Closure& task, bool task_is_slow) {
103 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); 107 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow);
104 return true; 108 return true;
105 } 109 }
106 110
107 PosixDynamicThreadPool::PendingTask::PendingTask( 111 PosixDynamicThreadPool::PendingTask::PendingTask(
108 const tracked_objects::Location& posted_from, 112 const tracked_objects::Location& posted_from,
109 const base::Closure& task) 113 const base::Closure& task)
110 : task(task) { 114 : posted_from(posted_from),
115 task(task) {
111 } 116 }
112 117
113 PosixDynamicThreadPool::PendingTask::~PendingTask() { 118 PosixDynamicThreadPool::PendingTask::~PendingTask() {
114 } 119 }
115 120
116 PosixDynamicThreadPool::PosixDynamicThreadPool( 121 PosixDynamicThreadPool::PosixDynamicThreadPool(
117 const std::string& name_prefix, 122 const std::string& name_prefix,
118 int idle_seconds_before_exit) 123 int idle_seconds_before_exit)
119 : name_prefix_(name_prefix), 124 : name_prefix_(name_prefix),
120 idle_seconds_before_exit_(idle_seconds_before_exit), 125 idle_seconds_before_exit_(idle_seconds_before_exit),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return PendingTask(FROM_HERE, base::Closure()); 207 return PendingTask(FROM_HERE, base::Closure());
203 } 208 }
204 } 209 }
205 210
206 PendingTask pending_task = pending_tasks_.front(); 211 PendingTask pending_task = pending_tasks_.front();
207 pending_tasks_.pop(); 212 pending_tasks_.pop();
208 return pending_task; 213 return pending_task;
209 } 214 }
210 215
211 } // namespace base 216 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/worker_pool_posix.h ('k') | base/threading/worker_pool_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698