OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return false; | 408 return false; |
409 | 409 |
410 PendingTask pending_task = deferred_non_nestable_work_queue_.front(); | 410 PendingTask pending_task = deferred_non_nestable_work_queue_.front(); |
411 deferred_non_nestable_work_queue_.pop(); | 411 deferred_non_nestable_work_queue_.pop(); |
412 | 412 |
413 RunTask(pending_task); | 413 RunTask(pending_task); |
414 return true; | 414 return true; |
415 } | 415 } |
416 | 416 |
417 void MessageLoop::RunTask(const PendingTask& pending_task) { | 417 void MessageLoop::RunTask(const PendingTask& pending_task) { |
418 tracked_objects::TrackedTime start_time = | 418 tracked_objects::ThreadData::PrepareForStartOfRun(pending_task.birth_tally); |
419 tracked_objects::ThreadData::NowForStartOfRun(pending_task.birth_tally); | 419 tracked_objects::TaskStopwatch stopwatch; |
420 | 420 |
421 TRACE_EVENT_FLOW_END1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), | 421 TRACE_EVENT_FLOW_END1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
422 "MessageLoop::PostTask", TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), | 422 "MessageLoop::PostTask", TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), |
423 "queue_duration", | 423 "queue_duration", |
424 (start_time - pending_task.EffectiveTimePosted()).InMilliseconds()); | 424 (stopwatch.StartTime() - pending_task.EffectiveTimePosted()). |
| 425 InMilliseconds()); |
425 // When tracing memory for posted tasks it's more valuable to attribute the | 426 // When tracing memory for posted tasks it's more valuable to attribute the |
426 // memory allocations to the source function than generically to "RunTask". | 427 // memory allocations to the source function than generically to "RunTask". |
427 TRACE_EVENT_WITH_MEMORY_TAG2( | 428 TRACE_EVENT_WITH_MEMORY_TAG2( |
428 "toplevel", "MessageLoop::RunTask", | 429 "toplevel", "MessageLoop::RunTask", |
429 pending_task.posted_from.function_name(), // Name for memory tracking. | 430 pending_task.posted_from.function_name(), // Name for memory tracking. |
430 "src_file", pending_task.posted_from.file_name(), | 431 "src_file", pending_task.posted_from.file_name(), |
431 "src_func", pending_task.posted_from.function_name()); | 432 "src_func", pending_task.posted_from.function_name()); |
432 | 433 |
433 DCHECK(nestable_tasks_allowed_); | 434 DCHECK(nestable_tasks_allowed_); |
434 // Execute the task and assume the worst: It is probably not reentrant. | 435 // Execute the task and assume the worst: It is probably not reentrant. |
435 nestable_tasks_allowed_ = false; | 436 nestable_tasks_allowed_ = false; |
436 | 437 |
437 // Before running the task, store the program counter where it was posted | 438 // Before running the task, store the program counter where it was posted |
438 // and deliberately alias it to ensure it is on the stack if the task | 439 // and deliberately alias it to ensure it is on the stack if the task |
439 // crashes. Be careful not to assume that the variable itself will have the | 440 // crashes. Be careful not to assume that the variable itself will have the |
440 // expected value when displayed by the optimizer in an optimized build. | 441 // expected value when displayed by the optimizer in an optimized build. |
441 // Look at a memory dump of the stack. | 442 // Look at a memory dump of the stack. |
442 const void* program_counter = | 443 const void* program_counter = |
443 pending_task.posted_from.program_counter(); | 444 pending_task.posted_from.program_counter(); |
444 debug::Alias(&program_counter); | 445 debug::Alias(&program_counter); |
445 | 446 |
446 HistogramEvent(kTaskRunEvent); | 447 HistogramEvent(kTaskRunEvent); |
447 | 448 |
448 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 449 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
449 WillProcessTask(pending_task)); | 450 WillProcessTask(pending_task)); |
450 pending_task.task.Run(); | 451 pending_task.task.Run(); |
451 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 452 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
452 DidProcessTask(pending_task)); | 453 DidProcessTask(pending_task)); |
453 | 454 |
454 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 455 stopwatch.Stop(); |
455 start_time, tracked_objects::ThreadData::NowForEndOfRun()); | 456 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( |
| 457 pending_task, stopwatch); |
456 | 458 |
457 nestable_tasks_allowed_ = true; | 459 nestable_tasks_allowed_ = true; |
458 } | 460 } |
459 | 461 |
460 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { | 462 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
461 if (pending_task.nestable || run_loop_->run_depth_ == 1) { | 463 if (pending_task.nestable || run_loop_->run_depth_ == 1) { |
462 RunTask(pending_task); | 464 RunTask(pending_task); |
463 // Show that we ran a task (Note: a new one might arrive as a | 465 // Show that we ran a task (Note: a new one might arrive as a |
464 // consequence!). | 466 // consequence!). |
465 return true; | 467 return true; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 persistent, | 735 persistent, |
734 mode, | 736 mode, |
735 controller, | 737 controller, |
736 delegate); | 738 delegate); |
737 } | 739 } |
738 #endif | 740 #endif |
739 | 741 |
740 #endif // !defined(OS_NACL) | 742 #endif // !defined(OS_NACL) |
741 | 743 |
742 } // namespace base | 744 } // namespace base |
OLD | NEW |