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