OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 unsigned next_node_id_; | 196 unsigned next_node_id_; |
197 ProfileNode* root_; | 197 ProfileNode* root_; |
198 double ms_to_ticks_scale_; | 198 double ms_to_ticks_scale_; |
199 | 199 |
200 DISALLOW_COPY_AND_ASSIGN(ProfileTree); | 200 DISALLOW_COPY_AND_ASSIGN(ProfileTree); |
201 }; | 201 }; |
202 | 202 |
203 | 203 |
204 class CpuProfile { | 204 class CpuProfile { |
205 public: | 205 public: |
206 CpuProfile(const char* title, unsigned uid, bool record_samples) | 206 CpuProfile(const char* title, unsigned uid, bool record_samples); |
207 : title_(title), uid_(uid), record_samples_(record_samples) { } | |
208 | 207 |
209 // Add pc -> ... -> main() call path to the profile. | 208 // Add pc -> ... -> main() call path to the profile. |
210 void AddPath(const Vector<CodeEntry*>& path); | 209 void AddPath(const Vector<CodeEntry*>& path); |
211 void CalculateTotalTicks(); | 210 void CalculateTotalTicksAndSamplingRate(); |
212 void SetActualSamplingRate(double actual_sampling_rate); | |
213 | 211 |
214 INLINE(const char* title() const) { return title_; } | 212 INLINE(const char* title() const) { return title_; } |
215 INLINE(unsigned uid() const) { return uid_; } | 213 INLINE(unsigned uid() const) { return uid_; } |
216 INLINE(const ProfileTree* top_down() const) { return &top_down_; } | 214 INLINE(const ProfileTree* top_down() const) { return &top_down_; } |
217 | 215 |
218 INLINE(int samples_count() const) { return samples_.length(); } | 216 INLINE(int samples_count() const) { return samples_.length(); } |
219 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } | 217 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } |
220 | 218 |
221 void UpdateTicksScale(); | 219 void UpdateTicksScale(); |
222 | 220 |
223 void ShortPrint(); | 221 void ShortPrint(); |
224 void Print(); | 222 void Print(); |
225 | 223 |
226 private: | 224 private: |
227 const char* title_; | 225 const char* title_; |
228 unsigned uid_; | 226 unsigned uid_; |
229 bool record_samples_; | 227 bool record_samples_; |
| 228 double start_time_ms_; |
| 229 double end_time_ms_; |
230 List<ProfileNode*> samples_; | 230 List<ProfileNode*> samples_; |
231 ProfileTree top_down_; | 231 ProfileTree top_down_; |
232 | 232 |
233 DISALLOW_COPY_AND_ASSIGN(CpuProfile); | 233 DISALLOW_COPY_AND_ASSIGN(CpuProfile); |
234 }; | 234 }; |
235 | 235 |
236 | 236 |
237 class CodeMap { | 237 class CodeMap { |
238 public: | 238 public: |
239 CodeMap() : next_shared_id_(1) { } | 239 CodeMap() : next_shared_id_(1) { } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 DISALLOW_COPY_AND_ASSIGN(CodeMap); | 279 DISALLOW_COPY_AND_ASSIGN(CodeMap); |
280 }; | 280 }; |
281 | 281 |
282 | 282 |
283 class CpuProfilesCollection { | 283 class CpuProfilesCollection { |
284 public: | 284 public: |
285 CpuProfilesCollection(); | 285 CpuProfilesCollection(); |
286 ~CpuProfilesCollection(); | 286 ~CpuProfilesCollection(); |
287 | 287 |
288 bool StartProfiling(const char* title, unsigned uid, bool record_samples); | 288 bool StartProfiling(const char* title, unsigned uid, bool record_samples); |
289 CpuProfile* StopProfiling(const char* title, double actual_sampling_rate); | 289 CpuProfile* StopProfiling(const char* title); |
290 List<CpuProfile*>* profiles() { return &finished_profiles_; } | 290 List<CpuProfile*>* profiles() { return &finished_profiles_; } |
291 const char* GetName(Name* name) { | 291 const char* GetName(Name* name) { |
292 return function_and_resource_names_.GetName(name); | 292 return function_and_resource_names_.GetName(name); |
293 } | 293 } |
294 const char* GetName(int args_count) { | 294 const char* GetName(int args_count) { |
295 return function_and_resource_names_.GetName(args_count); | 295 return function_and_resource_names_.GetName(args_count); |
296 } | 296 } |
297 const char* GetFunctionName(Name* name) { | 297 const char* GetFunctionName(Name* name) { |
298 return function_and_resource_names_.GetFunctionName(name); | 298 return function_and_resource_names_.GetFunctionName(name); |
299 } | 299 } |
(...skipping 22 matching lines...) Expand all Loading... |
322 List<CpuProfile*> finished_profiles_; | 322 List<CpuProfile*> finished_profiles_; |
323 | 323 |
324 // Accessed by VM thread and profile generator thread. | 324 // Accessed by VM thread and profile generator thread. |
325 List<CpuProfile*> current_profiles_; | 325 List<CpuProfile*> current_profiles_; |
326 Semaphore* current_profiles_semaphore_; | 326 Semaphore* current_profiles_semaphore_; |
327 | 327 |
328 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); | 328 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); |
329 }; | 329 }; |
330 | 330 |
331 | 331 |
332 class SampleRateCalculator { | |
333 public: | |
334 SampleRateCalculator() | |
335 : result_(Logger::kSamplingIntervalMs * kResultScale), | |
336 ticks_per_ms_(Logger::kSamplingIntervalMs), | |
337 measurements_count_(0), | |
338 wall_time_query_countdown_(1) { | |
339 } | |
340 | |
341 double ticks_per_ms() { | |
342 return result_ / static_cast<double>(kResultScale); | |
343 } | |
344 void Tick(); | |
345 void UpdateMeasurements(double current_time); | |
346 | |
347 // Instead of querying current wall time each tick, | |
348 // we use this constant to control query intervals. | |
349 static const unsigned kWallTimeQueryIntervalMs = 100; | |
350 | |
351 private: | |
352 // As the result needs to be accessed from a different thread, we | |
353 // use type that guarantees atomic writes to memory. There should | |
354 // be <= 1000 ticks per second, thus storing a value of a 10 ** 5 | |
355 // order should provide enough precision while keeping away from a | |
356 // potential overflow. | |
357 static const int kResultScale = 100000; | |
358 | |
359 AtomicWord result_; | |
360 // All other fields are accessed only from the sampler thread. | |
361 double ticks_per_ms_; | |
362 unsigned measurements_count_; | |
363 unsigned wall_time_query_countdown_; | |
364 double last_wall_time_; | |
365 | |
366 DISALLOW_COPY_AND_ASSIGN(SampleRateCalculator); | |
367 }; | |
368 | |
369 | |
370 class ProfileGenerator { | 332 class ProfileGenerator { |
371 public: | 333 public: |
372 explicit ProfileGenerator(CpuProfilesCollection* profiles); | 334 explicit ProfileGenerator(CpuProfilesCollection* profiles); |
373 | 335 |
374 void RecordTickSample(const TickSample& sample); | 336 void RecordTickSample(const TickSample& sample); |
375 | 337 |
376 INLINE(CodeMap* code_map()) { return &code_map_; } | 338 INLINE(CodeMap* code_map()) { return &code_map_; } |
377 | 339 |
378 INLINE(void Tick()) { sample_rate_calc_.Tick(); } | |
379 INLINE(double actual_sampling_rate()) { | |
380 return sample_rate_calc_.ticks_per_ms(); | |
381 } | |
382 | |
383 static const char* const kAnonymousFunctionName; | 340 static const char* const kAnonymousFunctionName; |
384 static const char* const kProgramEntryName; | 341 static const char* const kProgramEntryName; |
385 static const char* const kGarbageCollectorEntryName; | 342 static const char* const kGarbageCollectorEntryName; |
386 // Used to represent frames for which we have no reliable way to | 343 // Used to represent frames for which we have no reliable way to |
387 // detect function. | 344 // detect function. |
388 static const char* const kUnresolvedFunctionName; | 345 static const char* const kUnresolvedFunctionName; |
389 | 346 |
390 private: | 347 private: |
391 INLINE(CodeEntry* EntryForVMState(StateTag tag)); | 348 INLINE(CodeEntry* EntryForVMState(StateTag tag)); |
392 | 349 |
393 CpuProfilesCollection* profiles_; | 350 CpuProfilesCollection* profiles_; |
394 CodeMap code_map_; | 351 CodeMap code_map_; |
395 CodeEntry* program_entry_; | 352 CodeEntry* program_entry_; |
396 CodeEntry* gc_entry_; | 353 CodeEntry* gc_entry_; |
397 CodeEntry* unresolved_entry_; | 354 CodeEntry* unresolved_entry_; |
398 SampleRateCalculator sample_rate_calc_; | |
399 | 355 |
400 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 356 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
401 }; | 357 }; |
402 | 358 |
403 | 359 |
404 } } // namespace v8::internal | 360 } } // namespace v8::internal |
405 | 361 |
406 #endif // V8_PROFILE_GENERATOR_H_ | 362 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |