Chromium Code Reviews| 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 #ifndef BASE_TRACKED_OBJECTS_H_ | 5 #ifndef BASE_TRACKED_OBJECTS_H_ |
| 6 #define BASE_TRACKED_OBJECTS_H_ | 6 #define BASE_TRACKED_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 | 615 |
| 616 // Record the end of execution in region, generally corresponding to a scope | 616 // Record the end of execution in region, generally corresponding to a scope |
| 617 // being exited. | 617 // being exited. |
| 618 static void TallyRunInAScopedRegionIfTracking(const Births* births, | 618 static void TallyRunInAScopedRegionIfTracking(const Births* births, |
| 619 const TaskStopwatch& stopwatch); | 619 const TaskStopwatch& stopwatch); |
| 620 | 620 |
| 621 const std::string& sanitized_thread_name() const { | 621 const std::string& sanitized_thread_name() const { |
| 622 return sanitized_thread_name_; | 622 return sanitized_thread_name_; |
| 623 } | 623 } |
| 624 | 624 |
| 625 void EnableTaskDurationRecordingForUMA(); | |
| 626 // Whether this thread records task lengths for UMA. | |
| 627 bool task_length_recording_enabled_for_uma() const { | |
| 628 return task_length_recording_enabled_for_uma_; | |
| 629 }; | |
| 630 | |
| 625 // Initializes all statics if needed (this initialization call should be made | 631 // Initializes all statics if needed (this initialization call should be made |
| 626 // while we are single threaded). | 632 // while we are single threaded). |
| 627 static void EnsureTlsInitialization(); | 633 static void EnsureTlsInitialization(); |
| 628 | 634 |
| 629 // Sets internal status_. | 635 // Sets internal status_. |
| 630 // If |status| is false, then status_ is set to DEACTIVATED. | 636 // If |status| is false, then status_ is set to DEACTIVATED. |
| 631 // If |status| is true, then status_ is set to PROFILING_ACTIVE. | 637 // If |status| is true, then status_ is set to PROFILING_ACTIVE. |
| 632 static void InitializeAndSetTrackingStatus(Status status); | 638 static void InitializeAndSetTrackingStatus(Status status); |
| 633 | 639 |
| 634 static Status status(); | 640 static Status status(); |
| 635 | 641 |
| 636 // Indicate if any sort of profiling is being done (i.e., we are more than | 642 // Indicate if any sort of profiling is being done (i.e., we are more than |
| 637 // DEACTIVATED). | 643 // DEACTIVATED). |
| 638 static bool TrackingStatus(); | 644 static bool TrackingStatus(); |
| 639 | 645 |
| 640 // Enables profiler timing. | 646 // Enables profiler timing. |
| 641 static void EnableProfilerTiming(); | 647 static void EnableProfilerTiming(); |
| 642 | 648 |
| 643 // Provide a time function that does nothing (runs fast) when we don't have | 649 // Provide a time function that does nothing (runs fast) when we don't have |
| 644 // the profiler enabled. It will generally be optimized away when it is | 650 // the profiler enabled. It will generally be optimized away when it is |
| 645 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of | 651 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of |
| 646 // the code). | 652 // the code). |
| 647 static base::TimeTicks Now(); | 653 static base::TimeTicks Now(); |
| 648 | 654 |
| 655 // If the provided thread is enabled for task duration tracking, returns the | |
|
Sami
2017/07/26 20:36:38
nit: "UMA task duration tracking" (I had to re-rea
| |
| 656 // current time. Otherwise, this is equivalent to Now(). | |
| 657 static base::TimeTicks Now(const ThreadData* thread_data); | |
| 658 | |
| 649 // This function can be called at process termination to validate that thread | 659 // This function can be called at process termination to validate that thread |
| 650 // cleanup routines have been called for at least some number of named | 660 // cleanup routines have been called for at least some number of named |
| 651 // threads. | 661 // threads. |
| 652 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); | 662 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); |
| 653 | 663 |
| 654 private: | 664 private: |
| 655 friend class TaskStopwatch; | 665 friend class TaskStopwatch; |
| 656 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it | 666 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it |
| 657 // in production code. | 667 // in production code. |
| 658 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a | 668 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 // Record of what the incarnation_counter_ was when this instance was created. | 826 // Record of what the incarnation_counter_ was when this instance was created. |
| 817 // If the incarnation_counter_ has changed, then we avoid pushing into the | 827 // If the incarnation_counter_ has changed, then we avoid pushing into the |
| 818 // pool (this is only critical in tests which go through multiple | 828 // pool (this is only critical in tests which go through multiple |
| 819 // incarnations). | 829 // incarnations). |
| 820 int incarnation_count_for_pool_; | 830 int incarnation_count_for_pool_; |
| 821 | 831 |
| 822 // Most recently started (i.e. most nested) stopwatch on the current thread, | 832 // Most recently started (i.e. most nested) stopwatch on the current thread, |
| 823 // if it exists; NULL otherwise. | 833 // if it exists; NULL otherwise. |
| 824 TaskStopwatch* current_stopwatch_; | 834 TaskStopwatch* current_stopwatch_; |
| 825 | 835 |
| 836 bool task_length_recording_enabled_for_uma_; | |
| 837 | |
| 826 DISALLOW_COPY_AND_ASSIGN(ThreadData); | 838 DISALLOW_COPY_AND_ASSIGN(ThreadData); |
| 827 }; | 839 }; |
| 828 | 840 |
| 829 //------------------------------------------------------------------------------ | 841 //------------------------------------------------------------------------------ |
| 830 // Stopwatch to measure task run time or simply create a time interval that will | 842 // Stopwatch to measure task run time or simply create a time interval that will |
| 831 // be subtracted from the current most nested task's run time. Stopwatches | 843 // be subtracted from the current most nested task's run time. Stopwatches |
| 832 // coordinate with the stopwatches in which they are nested to avoid | 844 // coordinate with the stopwatches in which they are nested to avoid |
| 833 // double-counting nested tasks run times. | 845 // double-counting nested tasks run times. |
| 834 | 846 |
| 835 class BASE_EXPORT TaskStopwatch { | 847 class BASE_EXPORT TaskStopwatch { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 ProcessDataSnapshot(const ProcessDataSnapshot& other); | 933 ProcessDataSnapshot(const ProcessDataSnapshot& other); |
| 922 ~ProcessDataSnapshot(); | 934 ~ProcessDataSnapshot(); |
| 923 | 935 |
| 924 PhasedProcessDataSnapshotMap phased_snapshots; | 936 PhasedProcessDataSnapshotMap phased_snapshots; |
| 925 base::ProcessId process_id; | 937 base::ProcessId process_id; |
| 926 }; | 938 }; |
| 927 | 939 |
| 928 } // namespace tracked_objects | 940 } // namespace tracked_objects |
| 929 | 941 |
| 930 #endif // BASE_TRACKED_OBJECTS_H_ | 942 #endif // BASE_TRACKED_OBJECTS_H_ |
| OLD | NEW |