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 #include "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 | 847 |
848 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); | 848 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); |
849 next_thread_data->birth_map_.end() != it; ++it) | 849 next_thread_data->birth_map_.end() != it; ++it) |
850 delete it->second; // Delete the Birth Records. | 850 delete it->second; // Delete the Birth Records. |
851 delete next_thread_data; // Includes all Death Records. | 851 delete next_thread_data; // Includes all Death Records. |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 //------------------------------------------------------------------------------ | 855 //------------------------------------------------------------------------------ |
856 TaskStopwatch::TaskStopwatch() | 856 TaskStopwatch::TaskStopwatch() |
857 : start_time_(ThreadData::Now()), | 857 : wallclock_duration_ms_(0), |
858 current_thread_data_(ThreadData::Get()), | 858 current_thread_data_(NULL), |
859 excluded_duration_ms_(0), | 859 excluded_duration_ms_(0), |
860 parent_(NULL) { | 860 parent_(NULL) { |
861 #if DCHECK_IS_ON | 861 #if DCHECK_IS_ON |
862 state_ = RUNNING; | 862 state_ = CREATED; |
863 child_ = NULL; | 863 child_ = NULL; |
864 #endif | 864 #endif |
| 865 } |
865 | 866 |
866 wallclock_duration_ms_ = 0; | 867 TaskStopwatch::~TaskStopwatch() { |
| 868 #if DCHECK_IS_ON |
| 869 DCHECK(state_ != RUNNING); |
| 870 DCHECK(child_ == NULL); |
| 871 #endif |
| 872 } |
| 873 |
| 874 void TaskStopwatch::Start() { |
| 875 #if DCHECK_IS_ON |
| 876 DCHECK(state_ == CREATED); |
| 877 state_ = RUNNING; |
| 878 #endif |
| 879 |
| 880 start_time_ = ThreadData::Now(); |
| 881 |
| 882 current_thread_data_ = ThreadData::Get(); |
867 if (!current_thread_data_) | 883 if (!current_thread_data_) |
868 return; | 884 return; |
869 | 885 |
870 parent_ = current_thread_data_->current_stopwatch_; | 886 parent_ = current_thread_data_->current_stopwatch_; |
871 #if DCHECK_IS_ON | 887 #if DCHECK_IS_ON |
872 if (parent_) { | 888 if (parent_) { |
873 DCHECK(parent_->state_ == RUNNING); | 889 DCHECK(parent_->state_ == RUNNING); |
874 DCHECK(parent_->child_ == NULL); | 890 DCHECK(parent_->child_ == NULL); |
875 parent_->child_ = this; | 891 parent_->child_ = this; |
876 } | 892 } |
877 #endif | 893 #endif |
878 current_thread_data_->current_stopwatch_ = this; | 894 current_thread_data_->current_stopwatch_ = this; |
879 } | 895 } |
880 | 896 |
881 TaskStopwatch::~TaskStopwatch() { | |
882 #if DCHECK_IS_ON | |
883 DCHECK(state_ != RUNNING); | |
884 DCHECK(child_ == NULL); | |
885 #endif | |
886 } | |
887 | |
888 void TaskStopwatch::Stop() { | 897 void TaskStopwatch::Stop() { |
889 const TrackedTime end_time = ThreadData::Now(); | 898 const TrackedTime end_time = ThreadData::Now(); |
890 #if DCHECK_IS_ON | 899 #if DCHECK_IS_ON |
891 DCHECK(state_ == RUNNING); | 900 DCHECK(state_ == RUNNING); |
892 state_ = STOPPED; | 901 state_ = STOPPED; |
893 DCHECK(child_ == NULL); | 902 DCHECK(child_ == NULL); |
894 #endif | 903 #endif |
895 | 904 |
896 if (!start_time_.is_null() && !end_time.is_null()) { | 905 if (!start_time_.is_null() && !end_time.is_null()) { |
897 wallclock_duration_ms_ = (end_time - start_time_).InMilliseconds(); | 906 wallclock_duration_ms_ = (end_time - start_time_).InMilliseconds(); |
898 } | 907 } |
899 | 908 |
900 if (!current_thread_data_) | 909 if (!current_thread_data_) |
901 return; | 910 return; |
902 | 911 |
903 DCHECK(current_thread_data_->current_stopwatch_ == this); | 912 DCHECK(current_thread_data_->current_stopwatch_ == this); |
904 current_thread_data_->current_stopwatch_ = parent_; | 913 current_thread_data_->current_stopwatch_ = parent_; |
905 if (!parent_) | 914 if (!parent_) |
906 return; | 915 return; |
907 | 916 |
908 #if DCHECK_IS_ON | 917 #if DCHECK_IS_ON |
909 DCHECK(parent_->state_ == RUNNING); | 918 DCHECK(parent_->state_ == RUNNING); |
910 DCHECK(parent_->child_ == this); | 919 DCHECK(parent_->child_ == this); |
911 parent_->child_ = NULL; | 920 parent_->child_ = NULL; |
912 #endif | 921 #endif |
913 parent_->excluded_duration_ms_ += | 922 parent_->excluded_duration_ms_ += wallclock_duration_ms_; |
914 wallclock_duration_ms_; | |
915 parent_ = NULL; | 923 parent_ = NULL; |
916 } | 924 } |
917 | 925 |
918 TrackedTime TaskStopwatch::StartTime() const { | 926 TrackedTime TaskStopwatch::StartTime() const { |
| 927 #if DCHECK_IS_ON |
| 928 DCHECK(state_ != CREATED); |
| 929 #endif |
| 930 |
919 return start_time_; | 931 return start_time_; |
920 } | 932 } |
921 | 933 |
922 int32 TaskStopwatch::RunDurationMs() const { | 934 int32 TaskStopwatch::RunDurationMs() const { |
923 #if DCHECK_IS_ON | 935 #if DCHECK_IS_ON |
924 DCHECK(state_ == STOPPED); | 936 DCHECK(state_ == STOPPED); |
925 #endif | 937 #endif |
926 | 938 |
927 return wallclock_duration_ms_ - excluded_duration_ms_; | 939 return wallclock_duration_ms_ - excluded_duration_ms_; |
928 } | 940 } |
929 | 941 |
930 ThreadData* TaskStopwatch::GetThreadData() const { | 942 ThreadData* TaskStopwatch::GetThreadData() const { |
| 943 #if DCHECK_IS_ON |
| 944 DCHECK(state_ != CREATED); |
| 945 #endif |
| 946 |
931 return current_thread_data_; | 947 return current_thread_data_; |
932 } | 948 } |
933 | 949 |
934 //------------------------------------------------------------------------------ | 950 //------------------------------------------------------------------------------ |
935 TaskSnapshot::TaskSnapshot() { | 951 TaskSnapshot::TaskSnapshot() { |
936 } | 952 } |
937 | 953 |
938 TaskSnapshot::TaskSnapshot(const BirthOnThread& birth, | 954 TaskSnapshot::TaskSnapshot(const BirthOnThread& birth, |
939 const DeathData& death_data, | 955 const DeathData& death_data, |
940 const std::string& death_thread_name) | 956 const std::string& death_thread_name) |
(...skipping 28 matching lines...) Expand all Loading... |
969 : process_id(base::GetCurrentProcId()) { | 985 : process_id(base::GetCurrentProcId()) { |
970 #else | 986 #else |
971 : process_id(0) { | 987 : process_id(0) { |
972 #endif | 988 #endif |
973 } | 989 } |
974 | 990 |
975 ProcessDataSnapshot::~ProcessDataSnapshot() { | 991 ProcessDataSnapshot::~ProcessDataSnapshot() { |
976 } | 992 } |
977 | 993 |
978 } // namespace tracked_objects | 994 } // namespace tracked_objects |
OLD | NEW |