OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 bool running_; | 127 bool running_; |
128 | 128 |
129 // Tells whether we are currently recording tick samples. | 129 // Tells whether we are currently recording tick samples. |
130 static bool paused_; | 130 static bool paused_; |
131 }; | 131 }; |
132 | 132 |
133 bool Profiler::paused_ = false; | 133 bool Profiler::paused_ = false; |
134 | 134 |
135 | 135 |
136 // | 136 // |
| 137 // StackTracer implementation |
| 138 // |
| 139 void StackTracer::Trace(TickSample* sample) { |
| 140 // Assuming that stack grows from lower addresses |
| 141 if (sample->sp < sample->fp && sample->fp < low_stack_bound_) { |
| 142 sample->InitStack(1); |
| 143 sample->stack[0] = Memory::Address_at( |
| 144 (Address)(sample->fp + StandardFrameConstants::kCallerPCOffset)); |
| 145 } else { |
| 146 // FP seems to be in some intermediate state, better discard this sample |
| 147 sample->InitStack(0); |
| 148 } |
| 149 } |
| 150 |
| 151 |
| 152 // |
137 // Ticker used to provide ticks to the profiler and the sliding state | 153 // Ticker used to provide ticks to the profiler and the sliding state |
138 // window. | 154 // window. |
139 // | 155 // |
140 class Ticker: public Sampler { | 156 class Ticker: public Sampler { |
141 public: | 157 public: |
142 explicit Ticker(int interval, unsigned int low_stack_bound): | 158 explicit Ticker(int interval, unsigned int low_stack_bound): |
143 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL), | 159 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL), |
144 low_stack_bound_(low_stack_bound) {} | 160 stack_tracer_(low_stack_bound) {} |
145 | 161 |
146 ~Ticker() { if (IsActive()) Stop(); } | 162 ~Ticker() { if (IsActive()) Stop(); } |
147 | 163 |
148 void Tick(TickSample* sample) { | 164 void Tick(TickSample* sample) { |
149 if (IsProfiling()) SampleStack(sample); | 165 if (IsProfiling()) stack_tracer_.Trace(sample); |
150 if (profiler_) profiler_->Insert(sample); | 166 if (profiler_) profiler_->Insert(sample); |
151 if (window_) window_->AddState(sample->state); | 167 if (window_) window_->AddState(sample->state); |
152 } | 168 } |
153 | 169 |
154 void SetWindow(SlidingStateWindow* window) { | 170 void SetWindow(SlidingStateWindow* window) { |
155 window_ = window; | 171 window_ = window; |
156 if (!IsActive()) Start(); | 172 if (!IsActive()) Start(); |
157 } | 173 } |
158 | 174 |
159 void ClearWindow() { | 175 void ClearWindow() { |
160 window_ = NULL; | 176 window_ = NULL; |
161 if (!profiler_ && IsActive()) Stop(); | 177 if (!profiler_ && IsActive()) Stop(); |
162 } | 178 } |
163 | 179 |
164 void SetProfiler(Profiler* profiler) { | 180 void SetProfiler(Profiler* profiler) { |
165 profiler_ = profiler; | 181 profiler_ = profiler; |
166 if (!IsActive()) Start(); | 182 if (!IsActive()) Start(); |
167 } | 183 } |
168 | 184 |
169 void ClearProfiler() { | 185 void ClearProfiler() { |
170 profiler_ = NULL; | 186 profiler_ = NULL; |
171 if (!window_ && IsActive()) Stop(); | 187 if (!window_ && IsActive()) Stop(); |
172 } | 188 } |
173 | 189 |
174 private: | 190 private: |
175 void SampleStack(TickSample* sample) { | |
176 // Assuming that stack grows from lower addresses | |
177 if (sample->sp < sample->fp && sample->fp < low_stack_bound_) { | |
178 sample->InitStack(1); | |
179 sample->stack[0] = Memory::Address_at( | |
180 (Address)(sample->fp + StandardFrameConstants::kCallerPCOffset)); | |
181 } else { | |
182 // FP seems to be in some intermediate state, better discard this sample | |
183 sample->InitStack(0); | |
184 } | |
185 } | |
186 | |
187 SlidingStateWindow* window_; | 191 SlidingStateWindow* window_; |
188 Profiler* profiler_; | 192 Profiler* profiler_; |
189 unsigned int low_stack_bound_; | 193 StackTracer stack_tracer_; |
190 }; | 194 }; |
191 | 195 |
192 | 196 |
193 // | 197 // |
194 // SlidingStateWindow implementation. | 198 // SlidingStateWindow implementation. |
195 // | 199 // |
196 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { | 200 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { |
197 for (int i = 0; i < kBufferSize; i++) { | 201 for (int i = 0; i < kBufferSize; i++) { |
198 buffer_[i] = static_cast<byte>(OTHER); | 202 buffer_[i] = static_cast<byte>(OTHER); |
199 } | 203 } |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 if (FLAG_log_state_changes) { | 1134 if (FLAG_log_state_changes) { |
1131 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); | 1135 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); |
1132 if (previous_) { | 1136 if (previous_) { |
1133 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); | 1137 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); |
1134 } | 1138 } |
1135 } | 1139 } |
1136 } | 1140 } |
1137 #endif | 1141 #endif |
1138 | 1142 |
1139 } } // namespace v8::internal | 1143 } } // namespace v8::internal |
OLD | NEW |