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) { } |
207 | 208 |
208 // Add pc -> ... -> main() call path to the profile. | 209 // Add pc -> ... -> main() call path to the profile. |
209 void AddPath(const Vector<CodeEntry*>& path); | 210 void AddPath(const Vector<CodeEntry*>& path); |
210 void CalculateTotalTicksAndSamplingRate(); | 211 void CalculateTotalTicks(); |
| 212 void SetActualSamplingRate(double actual_sampling_rate); |
211 | 213 |
212 INLINE(const char* title() const) { return title_; } | 214 INLINE(const char* title() const) { return title_; } |
213 INLINE(unsigned uid() const) { return uid_; } | 215 INLINE(unsigned uid() const) { return uid_; } |
214 INLINE(const ProfileTree* top_down() const) { return &top_down_; } | 216 INLINE(const ProfileTree* top_down() const) { return &top_down_; } |
215 | 217 |
216 INLINE(int samples_count() const) { return samples_.length(); } | 218 INLINE(int samples_count() const) { return samples_.length(); } |
217 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } | 219 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } |
218 | 220 |
219 void UpdateTicksScale(); | 221 void UpdateTicksScale(); |
220 | 222 |
221 void ShortPrint(); | 223 void ShortPrint(); |
222 void Print(); | 224 void Print(); |
223 | 225 |
224 private: | 226 private: |
225 const char* title_; | 227 const char* title_; |
226 unsigned uid_; | 228 unsigned uid_; |
227 bool record_samples_; | 229 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); | 289 CpuProfile* StopProfiling(const char* title, double actual_sampling_rate); |
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 |
332 class ProfileGenerator { | 370 class ProfileGenerator { |
333 public: | 371 public: |
334 explicit ProfileGenerator(CpuProfilesCollection* profiles); | 372 explicit ProfileGenerator(CpuProfilesCollection* profiles); |
335 | 373 |
336 void RecordTickSample(const TickSample& sample); | 374 void RecordTickSample(const TickSample& sample); |
337 | 375 |
338 INLINE(CodeMap* code_map()) { return &code_map_; } | 376 INLINE(CodeMap* code_map()) { return &code_map_; } |
339 | 377 |
| 378 INLINE(void Tick()) { sample_rate_calc_.Tick(); } |
| 379 INLINE(double actual_sampling_rate()) { |
| 380 return sample_rate_calc_.ticks_per_ms(); |
| 381 } |
| 382 |
340 static const char* const kAnonymousFunctionName; | 383 static const char* const kAnonymousFunctionName; |
341 static const char* const kProgramEntryName; | 384 static const char* const kProgramEntryName; |
342 static const char* const kGarbageCollectorEntryName; | 385 static const char* const kGarbageCollectorEntryName; |
343 // Used to represent frames for which we have no reliable way to | 386 // Used to represent frames for which we have no reliable way to |
344 // detect function. | 387 // detect function. |
345 static const char* const kUnresolvedFunctionName; | 388 static const char* const kUnresolvedFunctionName; |
346 | 389 |
347 private: | 390 private: |
348 INLINE(CodeEntry* EntryForVMState(StateTag tag)); | 391 INLINE(CodeEntry* EntryForVMState(StateTag tag)); |
349 | 392 |
350 CpuProfilesCollection* profiles_; | 393 CpuProfilesCollection* profiles_; |
351 CodeMap code_map_; | 394 CodeMap code_map_; |
352 CodeEntry* program_entry_; | 395 CodeEntry* program_entry_; |
353 CodeEntry* gc_entry_; | 396 CodeEntry* gc_entry_; |
354 CodeEntry* unresolved_entry_; | 397 CodeEntry* unresolved_entry_; |
| 398 SampleRateCalculator sample_rate_calc_; |
355 | 399 |
356 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 400 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
357 }; | 401 }; |
358 | 402 |
359 | 403 |
360 } } // namespace v8::internal | 404 } } // namespace v8::internal |
361 | 405 |
362 #endif // V8_PROFILE_GENERATOR_H_ | 406 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |