OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines a WatchDog thread that monitors the responsiveness of other | 5 // This file defines a WatchDog thread that monitors the responsiveness of other |
6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines | 6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines |
7 // ThreadWatcher class which performs health check on threads that would like to | 7 // ThreadWatcher class which performs health check on threads that would like to |
8 // be watched. This file also defines ThreadWatcherList class that has list of | 8 // be watched. This file also defines ThreadWatcherList class that has list of |
9 // all active ThreadWatcher objects. | 9 // all active ThreadWatcher objects. |
10 // | 10 // |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "base/memory/weak_ptr.h" | 55 #include "base/memory/weak_ptr.h" |
56 #include "base/message_loop/message_loop.h" | 56 #include "base/message_loop/message_loop.h" |
57 #include "base/metrics/histogram.h" | 57 #include "base/metrics/histogram.h" |
58 #include "base/profiler/stack_sampling_profiler.h" | 58 #include "base/profiler/stack_sampling_profiler.h" |
59 #include "base/single_thread_task_runner.h" | 59 #include "base/single_thread_task_runner.h" |
60 #include "base/synchronization/lock.h" | 60 #include "base/synchronization/lock.h" |
61 #include "base/threading/platform_thread.h" | 61 #include "base/threading/platform_thread.h" |
62 #include "base/threading/thread.h" | 62 #include "base/threading/thread.h" |
63 #include "base/threading/watchdog.h" | 63 #include "base/threading/watchdog.h" |
64 #include "base/time/time.h" | 64 #include "base/time/time.h" |
| 65 #include "components/metrics/call_stack_profile_params.h" |
65 #include "components/omnibox/browser/omnibox_event_global_tracker.h" | 66 #include "components/omnibox/browser/omnibox_event_global_tracker.h" |
66 #include "content/public/browser/browser_thread.h" | 67 #include "content/public/browser/browser_thread.h" |
67 #include "content/public/browser/notification_observer.h" | 68 #include "content/public/browser/notification_observer.h" |
68 #include "content/public/browser/notification_registrar.h" | 69 #include "content/public/browser/notification_registrar.h" |
69 | 70 |
70 class CustomThreadWatcher; | 71 class CustomThreadWatcher; |
71 class StartupTimeBomb; | 72 class StartupTimeBomb; |
72 class ThreadWatcherList; | 73 class ThreadWatcherList; |
73 class ThreadWatcherObserver; | 74 class ThreadWatcherObserver; |
74 | 75 |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 const base::PlatformThreadId thread_id_; | 640 const base::PlatformThreadId thread_id_; |
640 | 641 |
641 DISALLOW_COPY_AND_ASSIGN(StartupTimeBomb); | 642 DISALLOW_COPY_AND_ASSIGN(StartupTimeBomb); |
642 }; | 643 }; |
643 | 644 |
644 // This is a wrapper class for metrics logging of the stack of a janky method. | 645 // This is a wrapper class for metrics logging of the stack of a janky method. |
645 class JankTimeBomb { | 646 class JankTimeBomb { |
646 public: | 647 public: |
647 // This is instantiated when the jank needs to be detected in a method. Posts | 648 // This is instantiated when the jank needs to be detected in a method. Posts |
648 // an Alarm callback task on WatchDogThread with |duration| as the delay. This | 649 // an Alarm callback task on WatchDogThread with |duration| as the delay. This |
649 // can be called on any thread. | 650 // can be called on any thread, but the thread's identity should be provided |
650 explicit JankTimeBomb(base::TimeDelta duration); | 651 // in |thread|. |
| 652 JankTimeBomb(base::TimeDelta duration, |
| 653 metrics::CallStackProfileParams::Thread thread); |
651 virtual ~JankTimeBomb(); | 654 virtual ~JankTimeBomb(); |
652 | 655 |
653 // Returns true if JankTimeBomb is enabled. | 656 // Returns true if JankTimeBomb is enabled. |
654 bool IsEnabled() const; | 657 bool IsEnabled() const; |
655 | 658 |
656 protected: | 659 protected: |
657 // Logs the call stack of given thread_id's janky method. This runs on | 660 // Logs the call stack of given thread_id's janky method. This runs on |
658 // WatchDogThread. This is overridden in tests to prevent the metrics logging. | 661 // WatchDogThread. This is overridden in tests to prevent the metrics logging. |
659 virtual void Alarm(base::PlatformThreadId thread_id); | 662 virtual void Alarm(base::PlatformThreadId thread_id); |
660 | 663 |
661 private: | 664 private: |
| 665 // The thread that instantiated this object. |
| 666 const metrics::CallStackProfileParams::Thread thread_; |
| 667 |
662 // A profiler that periodically samples stack traces. Used to sample jank | 668 // A profiler that periodically samples stack traces. Used to sample jank |
663 // behavior. | 669 // behavior. |
664 std::unique_ptr<base::StackSamplingProfiler> sampling_profiler_; | 670 std::unique_ptr<base::StackSamplingProfiler> sampling_profiler_; |
665 | 671 |
666 // We use this factory during creation and starting timer. | 672 // We use this factory during creation and starting timer. |
667 base::WeakPtrFactory<JankTimeBomb> weak_ptr_factory_; | 673 base::WeakPtrFactory<JankTimeBomb> weak_ptr_factory_; |
668 | 674 |
669 DISALLOW_COPY_AND_ASSIGN(JankTimeBomb); | 675 DISALLOW_COPY_AND_ASSIGN(JankTimeBomb); |
670 }; | 676 }; |
671 | 677 |
(...skipping 14 matching lines...) Expand all Loading... |
686 // shutdown_watchdog_ watches for hangs during shutdown. | 692 // shutdown_watchdog_ watches for hangs during shutdown. |
687 base::Watchdog* shutdown_watchdog_; | 693 base::Watchdog* shutdown_watchdog_; |
688 | 694 |
689 // The |thread_id_| on which this object is constructed. | 695 // The |thread_id_| on which this object is constructed. |
690 const base::PlatformThreadId thread_id_; | 696 const base::PlatformThreadId thread_id_; |
691 | 697 |
692 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 698 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
693 }; | 699 }; |
694 | 700 |
695 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 701 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
OLD | NEW |