OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 // | 140 // |
141 // StackTracer implementation | 141 // StackTracer implementation |
142 // | 142 // |
143 void StackTracer::Trace(TickSample* sample) { | 143 void StackTracer::Trace(TickSample* sample) { |
144 if (sample->state == GC) { | 144 if (sample->state == GC) { |
145 sample->frames_count = 0; | 145 sample->frames_count = 0; |
146 return; | 146 return; |
147 } | 147 } |
148 | 148 |
| 149 const Address js_entry_sp = Top::js_entry_sp(Top::GetCurrentThread()); |
| 150 if (js_entry_sp == 0) { |
| 151 // Not executing JS now. |
| 152 sample->frames_count = 0; |
| 153 return; |
| 154 } |
| 155 |
149 SafeStackTraceFrameIterator it( | 156 SafeStackTraceFrameIterator it( |
150 reinterpret_cast<Address>(sample->fp), | 157 reinterpret_cast<Address>(sample->fp), |
151 reinterpret_cast<Address>(sample->sp), | 158 reinterpret_cast<Address>(sample->sp), |
152 reinterpret_cast<Address>(sample->sp), | 159 reinterpret_cast<Address>(sample->sp), |
153 reinterpret_cast<Address>(low_stack_bound_)); | 160 js_entry_sp); |
154 int i = 0; | 161 int i = 0; |
155 while (!it.done() && i < TickSample::kMaxFramesCount) { | 162 while (!it.done() && i < TickSample::kMaxFramesCount) { |
156 sample->stack[i++] = it.frame()->pc(); | 163 sample->stack[i++] = it.frame()->pc(); |
157 it.Advance(); | 164 it.Advance(); |
158 } | 165 } |
159 sample->frames_count = i; | 166 sample->frames_count = i; |
160 } | 167 } |
161 | 168 |
162 | 169 |
163 // | 170 // |
164 // Ticker used to provide ticks to the profiler and the sliding state | 171 // Ticker used to provide ticks to the profiler and the sliding state |
165 // window. | 172 // window. |
166 // | 173 // |
167 class Ticker: public Sampler { | 174 class Ticker: public Sampler { |
168 public: | 175 public: |
169 explicit Ticker(int interval, uintptr_t low_stack_bound): | 176 explicit Ticker(int interval): |
170 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL), | 177 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL) {} |
171 stack_tracer_(low_stack_bound) {} | |
172 | 178 |
173 ~Ticker() { if (IsActive()) Stop(); } | 179 ~Ticker() { if (IsActive()) Stop(); } |
174 | 180 |
175 void Tick(TickSample* sample) { | 181 void Tick(TickSample* sample) { |
176 if (IsProfiling()) stack_tracer_.Trace(sample); | 182 if (IsProfiling()) StackTracer::Trace(sample); |
177 if (profiler_) profiler_->Insert(sample); | 183 if (profiler_) profiler_->Insert(sample); |
178 if (window_) window_->AddState(sample->state); | 184 if (window_) window_->AddState(sample->state); |
179 } | 185 } |
180 | 186 |
181 void SetWindow(SlidingStateWindow* window) { | 187 void SetWindow(SlidingStateWindow* window) { |
182 window_ = window; | 188 window_ = window; |
183 if (!IsActive()) Start(); | 189 if (!IsActive()) Start(); |
184 } | 190 } |
185 | 191 |
186 void ClearWindow() { | 192 void ClearWindow() { |
187 window_ = NULL; | 193 window_ = NULL; |
188 if (!profiler_ && IsActive()) Stop(); | 194 if (!profiler_ && IsActive()) Stop(); |
189 } | 195 } |
190 | 196 |
191 void SetProfiler(Profiler* profiler) { | 197 void SetProfiler(Profiler* profiler) { |
192 profiler_ = profiler; | 198 profiler_ = profiler; |
193 if (!FLAG_prof_lazy && !IsActive()) Start(); | 199 if (!FLAG_prof_lazy && !IsActive()) Start(); |
194 } | 200 } |
195 | 201 |
196 void ClearProfiler() { | 202 void ClearProfiler() { |
197 profiler_ = NULL; | 203 profiler_ = NULL; |
198 if (!window_ && IsActive()) Stop(); | 204 if (!window_ && IsActive()) Stop(); |
199 } | 205 } |
200 | 206 |
201 private: | 207 private: |
202 SlidingStateWindow* window_; | 208 SlidingStateWindow* window_; |
203 Profiler* profiler_; | 209 Profiler* profiler_; |
204 StackTracer stack_tracer_; | |
205 }; | 210 }; |
206 | 211 |
207 | 212 |
208 // | 213 // |
209 // SlidingStateWindow implementation. | 214 // SlidingStateWindow implementation. |
210 // | 215 // |
211 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { | 216 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { |
212 for (int i = 0; i < kBufferSize; i++) { | 217 for (int i = 0; i < kBufferSize; i++) { |
213 buffer_[i] = static_cast<byte>(OTHER); | 218 buffer_[i] = static_cast<byte>(OTHER); |
214 } | 219 } |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 } | 1000 } |
996 SmartPointer<const char> expanded = stream.ToCString(); | 1001 SmartPointer<const char> expanded = stream.ToCString(); |
997 Log::OpenFile(*expanded); | 1002 Log::OpenFile(*expanded); |
998 } else { | 1003 } else { |
999 Log::OpenFile(FLAG_logfile); | 1004 Log::OpenFile(FLAG_logfile); |
1000 } | 1005 } |
1001 } | 1006 } |
1002 | 1007 |
1003 current_state_ = &bottom_state_; | 1008 current_state_ = &bottom_state_; |
1004 | 1009 |
1005 // as log is initialized early with V8, we can assume that JS execution | 1010 ticker_ = new Ticker(kSamplingIntervalMs); |
1006 // frames can never reach this point on stack | |
1007 int stack_var; | |
1008 ticker_ = new Ticker( | |
1009 kSamplingIntervalMs, reinterpret_cast<uintptr_t>(&stack_var)); | |
1010 | 1011 |
1011 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { | 1012 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { |
1012 sliding_state_window_ = new SlidingStateWindow(); | 1013 sliding_state_window_ = new SlidingStateWindow(); |
1013 } | 1014 } |
1014 | 1015 |
1015 if (FLAG_prof) { | 1016 if (FLAG_prof) { |
1016 profiler_ = new Profiler(); | 1017 profiler_ = new Profiler(); |
1017 if (!FLAG_prof_auto) | 1018 if (!FLAG_prof_auto) |
1018 profiler_->pause(); | 1019 profiler_->pause(); |
1019 profiler_->Engage(); | 1020 profiler_->Engage(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 } else if (previous_->state_ == EXTERNAL) { | 1146 } else if (previous_->state_ == EXTERNAL) { |
1146 // We are leaving V8. | 1147 // We are leaving V8. |
1147 Heap::Protect(); | 1148 Heap::Protect(); |
1148 } | 1149 } |
1149 } | 1150 } |
1150 #endif | 1151 #endif |
1151 } | 1152 } |
1152 #endif | 1153 #endif |
1153 | 1154 |
1154 } } // namespace v8::internal | 1155 } } // namespace v8::internal |
OLD | NEW |