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

Side by Side Diff: base/message_loop/message_loop.cc

Issue 2398263002: Measure how many tasks are cancelled in MessageLoop.
Patch Set: Created 4 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
« no previous file with comments | « base/debug/task_annotator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_pump_default.h" 15 #include "base/message_loop/message_pump_default.h"
16 #include "base/metrics/histogram_macros.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
18 #include "base/threading/thread_id_name_manager.h" 19 #include "base/threading/thread_id_name_manager.h"
19 #include "base/threading/thread_local.h" 20 #include "base/threading/thread_local.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
22 23
23 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
24 #include "base/message_loop/message_pump_mac.h" 25 #include "base/message_loop/message_pump_mac.h"
25 #endif 26 #endif
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // queue that are ready to run. To increase efficiency when we fall behind, 531 // queue that are ready to run. To increase efficiency when we fall behind,
531 // we will only call Time::Now() intermittently, and then process all tasks 532 // we will only call Time::Now() intermittently, and then process all tasks
532 // that are ready to run before calling it again. As a result, the more we 533 // that are ready to run before calling it again. As a result, the more we
533 // fall behind (and have a lot of ready-to-run delayed tasks), the more 534 // fall behind (and have a lot of ready-to-run delayed tasks), the more
534 // efficient we'll be at handling the tasks. 535 // efficient we'll be at handling the tasks.
535 536
536 TimeTicks next_run_time = delayed_work_queue_.top().delayed_run_time; 537 TimeTicks next_run_time = delayed_work_queue_.top().delayed_run_time;
537 if (next_run_time > recent_time_) { 538 if (next_run_time > recent_time_) {
538 recent_time_ = TimeTicks::Now(); // Get a better view of Now(); 539 recent_time_ = TimeTicks::Now(); // Get a better view of Now();
539 if (next_run_time > recent_time_) { 540 if (next_run_time > recent_time_) {
541 UMA_HISTOGRAM_BOOLEAN("TaskRunner.WokeUpTooSoonTaskIsCancelled",
542 delayed_work_queue_.top().task.IsCancelled());
540 *next_delayed_work_time = next_run_time; 543 *next_delayed_work_time = next_run_time;
541 return false; 544 return false;
542 } 545 }
543 } 546 }
544 547
545 PendingTask pending_task = 548 PendingTask pending_task =
546 std::move(const_cast<PendingTask&>(delayed_work_queue_.top())); 549 std::move(const_cast<PendingTask&>(delayed_work_queue_.top()));
547 delayed_work_queue_.pop(); 550 delayed_work_queue_.pop();
548 551
549 if (!delayed_work_queue_.empty()) 552 UMA_HISTOGRAM_BOOLEAN("TaskRunner.ExecutingDelayedTaskIsCancelled",
553 pending_task.task.IsCancelled());
554
555 if (!delayed_work_queue_.empty()) {
556 UMA_HISTOGRAM_BOOLEAN("TaskRunner.ScheduledTaskIsCancelled",
557 delayed_work_queue_.top().task.IsCancelled());
550 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; 558 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time;
559 }
551 560
552 return DeferOrRunPendingTask(std::move(pending_task)); 561 return DeferOrRunPendingTask(std::move(pending_task));
553 } 562 }
554 563
555 bool MessageLoop::DoIdleWork() { 564 bool MessageLoop::DoIdleWork() {
556 if (ProcessNextDelayedNonNestableTask()) 565 if (ProcessNextDelayedNonNestableTask())
557 return true; 566 return true;
558 567
559 if (run_loop_->quit_when_idle_received_) 568 if (run_loop_->quit_when_idle_received_)
560 pump_->Quit(); 569 pump_->Quit();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 persistent, 661 persistent,
653 mode, 662 mode,
654 controller, 663 controller,
655 delegate); 664 delegate);
656 } 665 }
657 #endif 666 #endif
658 667
659 #endif // !defined(OS_NACL_SFI) 668 #endif // !defined(OS_NACL_SFI)
660 669
661 } // namespace base 670 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/task_annotator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698