| 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 delete next_thread_data; // Includes all Death Records. | 866 delete next_thread_data; // Includes all Death Records. |
| 867 } | 867 } |
| 868 } | 868 } |
| 869 | 869 |
| 870 //------------------------------------------------------------------------------ | 870 //------------------------------------------------------------------------------ |
| 871 TaskStopwatch::TaskStopwatch() | 871 TaskStopwatch::TaskStopwatch() |
| 872 : wallclock_duration_ms_(0), | 872 : wallclock_duration_ms_(0), |
| 873 current_thread_data_(NULL), | 873 current_thread_data_(NULL), |
| 874 excluded_duration_ms_(0), | 874 excluded_duration_ms_(0), |
| 875 parent_(NULL) { | 875 parent_(NULL) { |
| 876 #if DCHECK_IS_ON | 876 #if !DCHECK_IS_OFF |
| 877 state_ = CREATED; | 877 state_ = CREATED; |
| 878 child_ = NULL; | 878 child_ = NULL; |
| 879 #endif | 879 #endif |
| 880 } | 880 } |
| 881 | 881 |
| 882 TaskStopwatch::~TaskStopwatch() { | 882 TaskStopwatch::~TaskStopwatch() { |
| 883 #if DCHECK_IS_ON | 883 #if !DCHECK_IS_OFF |
| 884 DCHECK(state_ != RUNNING); | 884 DCHECK(state_ != RUNNING); |
| 885 DCHECK(child_ == NULL); | 885 DCHECK(child_ == NULL); |
| 886 #endif | 886 #endif |
| 887 } | 887 } |
| 888 | 888 |
| 889 void TaskStopwatch::Start() { | 889 void TaskStopwatch::Start() { |
| 890 #if DCHECK_IS_ON | 890 #if !DCHECK_IS_OFF |
| 891 DCHECK(state_ == CREATED); | 891 DCHECK(state_ == CREATED); |
| 892 state_ = RUNNING; | 892 state_ = RUNNING; |
| 893 #endif | 893 #endif |
| 894 | 894 |
| 895 start_time_ = ThreadData::Now(); | 895 start_time_ = ThreadData::Now(); |
| 896 | 896 |
| 897 current_thread_data_ = ThreadData::Get(); | 897 current_thread_data_ = ThreadData::Get(); |
| 898 if (!current_thread_data_) | 898 if (!current_thread_data_) |
| 899 return; | 899 return; |
| 900 | 900 |
| 901 parent_ = current_thread_data_->current_stopwatch_; | 901 parent_ = current_thread_data_->current_stopwatch_; |
| 902 #if DCHECK_IS_ON | 902 #if !DCHECK_IS_OFF |
| 903 if (parent_) { | 903 if (parent_) { |
| 904 DCHECK(parent_->state_ == RUNNING); | 904 DCHECK(parent_->state_ == RUNNING); |
| 905 DCHECK(parent_->child_ == NULL); | 905 DCHECK(parent_->child_ == NULL); |
| 906 parent_->child_ = this; | 906 parent_->child_ = this; |
| 907 } | 907 } |
| 908 #endif | 908 #endif |
| 909 current_thread_data_->current_stopwatch_ = this; | 909 current_thread_data_->current_stopwatch_ = this; |
| 910 } | 910 } |
| 911 | 911 |
| 912 void TaskStopwatch::Stop() { | 912 void TaskStopwatch::Stop() { |
| 913 const TrackedTime end_time = ThreadData::Now(); | 913 const TrackedTime end_time = ThreadData::Now(); |
| 914 #if DCHECK_IS_ON | 914 #if !DCHECK_IS_OFF |
| 915 DCHECK(state_ == RUNNING); | 915 DCHECK(state_ == RUNNING); |
| 916 state_ = STOPPED; | 916 state_ = STOPPED; |
| 917 DCHECK(child_ == NULL); | 917 DCHECK(child_ == NULL); |
| 918 #endif | 918 #endif |
| 919 | 919 |
| 920 if (!start_time_.is_null() && !end_time.is_null()) { | 920 if (!start_time_.is_null() && !end_time.is_null()) { |
| 921 wallclock_duration_ms_ = (end_time - start_time_).InMilliseconds(); | 921 wallclock_duration_ms_ = (end_time - start_time_).InMilliseconds(); |
| 922 } | 922 } |
| 923 | 923 |
| 924 if (!current_thread_data_) | 924 if (!current_thread_data_) |
| 925 return; | 925 return; |
| 926 | 926 |
| 927 DCHECK(current_thread_data_->current_stopwatch_ == this); | 927 DCHECK(current_thread_data_->current_stopwatch_ == this); |
| 928 current_thread_data_->current_stopwatch_ = parent_; | 928 current_thread_data_->current_stopwatch_ = parent_; |
| 929 if (!parent_) | 929 if (!parent_) |
| 930 return; | 930 return; |
| 931 | 931 |
| 932 #if DCHECK_IS_ON | 932 #if !DCHECK_IS_OFF |
| 933 DCHECK(parent_->state_ == RUNNING); | 933 DCHECK(parent_->state_ == RUNNING); |
| 934 DCHECK(parent_->child_ == this); | 934 DCHECK(parent_->child_ == this); |
| 935 parent_->child_ = NULL; | 935 parent_->child_ = NULL; |
| 936 #endif | 936 #endif |
| 937 parent_->excluded_duration_ms_ += wallclock_duration_ms_; | 937 parent_->excluded_duration_ms_ += wallclock_duration_ms_; |
| 938 parent_ = NULL; | 938 parent_ = NULL; |
| 939 } | 939 } |
| 940 | 940 |
| 941 TrackedTime TaskStopwatch::StartTime() const { | 941 TrackedTime TaskStopwatch::StartTime() const { |
| 942 #if DCHECK_IS_ON | 942 #if !DCHECK_IS_OFF |
| 943 DCHECK(state_ != CREATED); | 943 DCHECK(state_ != CREATED); |
| 944 #endif | 944 #endif |
| 945 | 945 |
| 946 return start_time_; | 946 return start_time_; |
| 947 } | 947 } |
| 948 | 948 |
| 949 int32 TaskStopwatch::RunDurationMs() const { | 949 int32 TaskStopwatch::RunDurationMs() const { |
| 950 #if DCHECK_IS_ON | 950 #if !DCHECK_IS_OFF |
| 951 DCHECK(state_ == STOPPED); | 951 DCHECK(state_ == STOPPED); |
| 952 #endif | 952 #endif |
| 953 | 953 |
| 954 return wallclock_duration_ms_ - excluded_duration_ms_; | 954 return wallclock_duration_ms_ - excluded_duration_ms_; |
| 955 } | 955 } |
| 956 | 956 |
| 957 ThreadData* TaskStopwatch::GetThreadData() const { | 957 ThreadData* TaskStopwatch::GetThreadData() const { |
| 958 #if DCHECK_IS_ON | 958 #if !DCHECK_IS_OFF |
| 959 DCHECK(state_ != CREATED); | 959 DCHECK(state_ != CREATED); |
| 960 #endif | 960 #endif |
| 961 | 961 |
| 962 return current_thread_data_; | 962 return current_thread_data_; |
| 963 } | 963 } |
| 964 | 964 |
| 965 //------------------------------------------------------------------------------ | 965 //------------------------------------------------------------------------------ |
| 966 TaskSnapshot::TaskSnapshot() { | 966 TaskSnapshot::TaskSnapshot() { |
| 967 } | 967 } |
| 968 | 968 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 : process_id(base::GetCurrentProcId()) { | 1000 : process_id(base::GetCurrentProcId()) { |
| 1001 #else | 1001 #else |
| 1002 : process_id(0) { | 1002 : process_id(0) { |
| 1003 #endif | 1003 #endif |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 ProcessDataSnapshot::~ProcessDataSnapshot() { | 1006 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 } // namespace tracked_objects | 1009 } // namespace tracked_objects |
| OLD | NEW |