OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | 177 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); |
178 | 178 |
179 ProfileGenerator* generator_; | 179 ProfileGenerator* generator_; |
180 bool running_; | 180 bool running_; |
181 UnboundQueue<CodeEventsContainer> events_buffer_; | 181 UnboundQueue<CodeEventsContainer> events_buffer_; |
182 SamplingCircularQueue ticks_buffer_; | 182 SamplingCircularQueue ticks_buffer_; |
183 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 183 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
184 unsigned enqueue_order_; | 184 unsigned enqueue_order_; |
185 }; | 185 }; |
186 | 186 |
187 } } // namespace v8::internal | |
188 | 187 |
189 | 188 #define PROFILE(IsolateGetter, Call) \ |
190 #define PROFILE(isolate, Call) \ | 189 do { \ |
191 LOG_CODE_EVENT(isolate, Call); \ | 190 Isolate* cpu_profiler_isolate = (IsolateGetter); \ |
192 do { \ | 191 LOG_CODE_EVENT(cpu_profiler_isolate, Call); \ |
193 if (v8::internal::CpuProfiler::is_profiling(isolate)) { \ | 192 CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \ |
194 v8::internal::CpuProfiler::Call; \ | 193 if (cpu_profiler->is_profiling()) { \ |
195 } \ | 194 cpu_profiler->Call; \ |
| 195 } \ |
196 } while (false) | 196 } while (false) |
197 | 197 |
198 | 198 |
199 namespace v8 { | |
200 namespace internal { | |
201 | |
202 | |
203 // TODO(isolates): isolatify this class. | |
204 class CpuProfiler { | 199 class CpuProfiler { |
205 public: | 200 public: |
206 static void SetUp(); | 201 explicit CpuProfiler(Isolate* isolate); |
207 static void TearDown(); | 202 ~CpuProfiler(); |
208 | 203 |
209 static void StartProfiling(const char* title); | 204 void StartProfiling(const char* title, bool record_samples = false); |
210 static void StartProfiling(String* title, bool record_samples); | 205 void StartProfiling(String* title, bool record_samples); |
211 static CpuProfile* StopProfiling(const char* title); | 206 CpuProfile* StopProfiling(const char* title); |
212 static CpuProfile* StopProfiling(Object* security_token, String* title); | 207 CpuProfile* StopProfiling(Object* security_token, String* title); |
213 static int GetProfilesCount(); | 208 int GetProfilesCount(); |
214 static CpuProfile* GetProfile(Object* security_token, int index); | 209 CpuProfile* GetProfile(Object* security_token, int index); |
215 static CpuProfile* FindProfile(Object* security_token, unsigned uid); | 210 CpuProfile* FindProfile(Object* security_token, unsigned uid); |
216 static void DeleteAllProfiles(); | 211 void DeleteAllProfiles(); |
217 static void DeleteProfile(CpuProfile* profile); | 212 void DeleteProfile(CpuProfile* profile); |
218 static bool HasDetachedProfiles(); | 213 bool HasDetachedProfiles(); |
219 | 214 |
220 // Invoked from stack sampler (thread or signal handler.) | 215 // Invoked from stack sampler (thread or signal handler.) |
221 static TickSample* TickSampleEvent(Isolate* isolate); | 216 TickSample* TickSampleEvent(); |
222 | 217 |
223 // Must be called via PROFILE macro, otherwise will crash when | 218 // Must be called via PROFILE macro, otherwise will crash when |
224 // profiling is not enabled. | 219 // profiling is not enabled. |
225 static void CallbackEvent(Name* name, Address entry_point); | 220 void CallbackEvent(Name* name, Address entry_point); |
226 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 221 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
227 Code* code, const char* comment); | 222 Code* code, const char* comment); |
228 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 223 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
229 Code* code, Name* name); | 224 Code* code, Name* name); |
230 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 225 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
231 Code* code, | 226 Code* code, |
232 SharedFunctionInfo* shared, | 227 SharedFunctionInfo* shared, |
233 Name* name); | 228 Name* name); |
234 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 229 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
235 Code* code, | 230 Code* code, |
236 SharedFunctionInfo* shared, | 231 SharedFunctionInfo* shared, |
237 String* source, int line); | 232 String* source, int line); |
238 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 233 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
239 Code* code, int args_count); | 234 Code* code, int args_count); |
240 static void CodeMovingGCEvent() {} | 235 void CodeMovingGCEvent() {} |
241 static void CodeMoveEvent(Address from, Address to); | 236 void CodeMoveEvent(Address from, Address to); |
242 static void CodeDeleteEvent(Address from); | 237 void CodeDeleteEvent(Address from); |
243 static void GetterCallbackEvent(Name* name, Address entry_point); | 238 void GetterCallbackEvent(Name* name, Address entry_point); |
244 static void RegExpCodeCreateEvent(Code* code, String* source); | 239 void RegExpCodeCreateEvent(Code* code, String* source); |
245 static void SetterCallbackEvent(Name* name, Address entry_point); | 240 void SetterCallbackEvent(Name* name, Address entry_point); |
246 static void SharedFunctionInfoMoveEvent(Address from, Address to); | 241 void SharedFunctionInfoMoveEvent(Address from, Address to); |
247 | 242 |
248 static INLINE(bool is_profiling(Isolate* isolate)) { | 243 INLINE(bool is_profiling() const) { return is_profiling_; } |
249 CpuProfiler* profiler = isolate->cpu_profiler(); | |
250 return profiler != NULL && profiler->is_profiling_; | |
251 } | |
252 | 244 |
253 private: | 245 private: |
254 CpuProfiler(); | |
255 ~CpuProfiler(); | |
256 void StartCollectingProfile(const char* title, bool record_samples); | |
257 void StartCollectingProfile(String* title, bool record_samples); | |
258 void StartProcessorIfNotStarted(); | 246 void StartProcessorIfNotStarted(); |
259 CpuProfile* StopCollectingProfile(const char* title); | |
260 CpuProfile* StopCollectingProfile(Object* security_token, String* title); | |
261 void StopProcessorIfLastProfile(const char* title); | 247 void StopProcessorIfLastProfile(const char* title); |
262 void StopProcessor(); | 248 void StopProcessor(); |
263 void ResetProfiles(); | 249 void ResetProfiles(); |
264 | 250 |
| 251 Isolate* isolate_; |
265 CpuProfilesCollection* profiles_; | 252 CpuProfilesCollection* profiles_; |
266 unsigned next_profile_uid_; | 253 unsigned next_profile_uid_; |
267 TokenEnumerator* token_enumerator_; | 254 TokenEnumerator* token_enumerator_; |
268 ProfileGenerator* generator_; | 255 ProfileGenerator* generator_; |
269 ProfilerEventsProcessor* processor_; | 256 ProfilerEventsProcessor* processor_; |
270 int saved_logging_nesting_; | 257 int saved_logging_nesting_; |
271 bool need_to_stop_sampler_; | 258 bool need_to_stop_sampler_; |
272 bool is_profiling_; | 259 bool is_profiling_; |
273 | 260 |
274 private: | 261 private: |
275 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 262 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
276 }; | 263 }; |
277 | 264 |
278 } } // namespace v8::internal | 265 } } // namespace v8::internal |
279 | 266 |
280 | 267 |
281 #endif // V8_CPU_PROFILER_H_ | 268 #endif // V8_CPU_PROFILER_H_ |
OLD | NEW |