| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PROFILER_PROFILE_GENERATOR_H_ | 5 #ifndef V8_PROFILER_PROFILE_GENERATOR_H_ |
| 6 #define V8_PROFILER_PROFILE_GENERATOR_H_ | 6 #define V8_PROFILER_PROFILE_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include "include/v8-profiler.h" | 9 #include "include/v8-profiler.h" |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 bool HasDeoptInlinedFramesFor(int deopt_id) const; | 105 bool HasDeoptInlinedFramesFor(int deopt_id) const; |
| 106 | 106 |
| 107 Address instruction_start() const { return instruction_start_; } | 107 Address instruction_start() const { return instruction_start_; } |
| 108 Logger::LogEventsAndTags tag() const { return TagField::decode(bit_field_); } | 108 Logger::LogEventsAndTags tag() const { return TagField::decode(bit_field_); } |
| 109 | 109 |
| 110 static const char* const kEmptyNamePrefix; | 110 static const char* const kEmptyNamePrefix; |
| 111 static const char* const kEmptyResourceName; | 111 static const char* const kEmptyResourceName; |
| 112 static const char* const kEmptyBailoutReason; | 112 static const char* const kEmptyBailoutReason; |
| 113 static const char* const kNoDeoptReason; | 113 static const char* const kNoDeoptReason; |
| 114 | 114 |
| 115 static const char* const kProgramEntryName; |
| 116 static const char* const kIdleEntryName; |
| 117 static const char* const kGarbageCollectorEntryName; |
| 118 // Used to represent frames for which we have no reliable way to |
| 119 // detect function. |
| 120 static const char* const kUnresolvedFunctionName; |
| 121 |
| 122 V8_INLINE static CodeEntry* program_entry() { |
| 123 return kProgramEntry.Pointer(); |
| 124 } |
| 125 V8_INLINE static CodeEntry* idle_entry() { return kIdleEntry.Pointer(); } |
| 126 V8_INLINE static CodeEntry* gc_entry() { return kGCEntry.Pointer(); } |
| 127 V8_INLINE static CodeEntry* unresolved_entry() { |
| 128 return kUnresolvedEntry.Pointer(); |
| 129 } |
| 130 |
| 115 private: | 131 private: |
| 132 struct ProgramEntryCreateTrait { |
| 133 static CodeEntry* Create(); |
| 134 }; |
| 135 struct IdleEntryCreateTrait { |
| 136 static CodeEntry* Create(); |
| 137 }; |
| 138 struct GCEntryCreateTrait { |
| 139 static CodeEntry* Create(); |
| 140 }; |
| 141 struct UnresolvedEntryCreateTrait { |
| 142 static CodeEntry* Create(); |
| 143 }; |
| 144 |
| 145 static base::LazyDynamicInstance<CodeEntry, ProgramEntryCreateTrait>::type |
| 146 kProgramEntry; |
| 147 static base::LazyDynamicInstance<CodeEntry, IdleEntryCreateTrait>::type |
| 148 kIdleEntry; |
| 149 static base::LazyDynamicInstance<CodeEntry, GCEntryCreateTrait>::type |
| 150 kGCEntry; |
| 151 static base::LazyDynamicInstance<CodeEntry, UnresolvedEntryCreateTrait>::type |
| 152 kUnresolvedEntry; |
| 153 |
| 116 class TagField : public BitField<Logger::LogEventsAndTags, 0, 8> {}; | 154 class TagField : public BitField<Logger::LogEventsAndTags, 0, 8> {}; |
| 117 class BuiltinIdField : public BitField<Builtins::Name, 8, 8> {}; | 155 class BuiltinIdField : public BitField<Builtins::Name, 8, 8> {}; |
| 118 | 156 |
| 119 uint32_t bit_field_; | 157 uint32_t bit_field_; |
| 120 const char* name_prefix_; | 158 const char* name_prefix_; |
| 121 const char* name_; | 159 const char* name_; |
| 122 const char* resource_name_; | 160 const char* resource_name_; |
| 123 int line_number_; | 161 int line_number_; |
| 124 int column_number_; | 162 int column_number_; |
| 125 int script_id_; | 163 int script_id_; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 346 |
| 309 | 347 |
| 310 class CpuProfilesCollection { | 348 class CpuProfilesCollection { |
| 311 public: | 349 public: |
| 312 explicit CpuProfilesCollection(Heap* heap); | 350 explicit CpuProfilesCollection(Heap* heap); |
| 313 ~CpuProfilesCollection(); | 351 ~CpuProfilesCollection(); |
| 314 | 352 |
| 315 bool StartProfiling(const char* title, bool record_samples); | 353 bool StartProfiling(const char* title, bool record_samples); |
| 316 CpuProfile* StopProfiling(const char* title); | 354 CpuProfile* StopProfiling(const char* title); |
| 317 List<CpuProfile*>* profiles() { return &finished_profiles_; } | 355 List<CpuProfile*>* profiles() { return &finished_profiles_; } |
| 318 const char* GetName(Name* name) { | 356 const char* GetName(Name* name) { return resource_names_.GetName(name); } |
| 319 return function_and_resource_names_.GetName(name); | |
| 320 } | |
| 321 const char* GetName(int args_count) { | |
| 322 return function_and_resource_names_.GetName(args_count); | |
| 323 } | |
| 324 const char* GetFunctionName(Name* name) { | |
| 325 return function_and_resource_names_.GetFunctionName(name); | |
| 326 } | |
| 327 const char* GetFunctionName(const char* name) { | |
| 328 return function_and_resource_names_.GetFunctionName(name); | |
| 329 } | |
| 330 bool IsLastProfile(const char* title); | 357 bool IsLastProfile(const char* title); |
| 331 void RemoveProfile(CpuProfile* profile); | 358 void RemoveProfile(CpuProfile* profile); |
| 332 | 359 |
| 333 CodeEntry* NewCodeEntry( | |
| 334 Logger::LogEventsAndTags tag, const char* name, | |
| 335 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | |
| 336 const char* resource_name = CodeEntry::kEmptyResourceName, | |
| 337 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | |
| 338 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, | |
| 339 JITLineInfoTable* line_info = NULL, Address instruction_start = NULL); | |
| 340 | |
| 341 // Called from profile generator thread. | 360 // Called from profile generator thread. |
| 342 void AddPathToCurrentProfiles(base::TimeTicks timestamp, | 361 void AddPathToCurrentProfiles(base::TimeTicks timestamp, |
| 343 const std::vector<CodeEntry*>& path, | 362 const std::vector<CodeEntry*>& path, |
| 344 int src_line, bool update_stats); | 363 int src_line, bool update_stats); |
| 345 | 364 |
| 346 // Limits the number of profiles that can be simultaneously collected. | 365 // Limits the number of profiles that can be simultaneously collected. |
| 347 static const int kMaxSimultaneousProfiles = 100; | 366 static const int kMaxSimultaneousProfiles = 100; |
| 348 | 367 |
| 349 private: | 368 private: |
| 350 StringsStorage function_and_resource_names_; | 369 StringsStorage resource_names_; |
| 351 List<CodeEntry*> code_entries_; | |
| 352 List<CpuProfile*> finished_profiles_; | 370 List<CpuProfile*> finished_profiles_; |
| 353 | 371 |
| 354 Isolate* isolate_; | 372 Isolate* isolate_; |
| 355 | 373 |
| 356 // Accessed by VM thread and profile generator thread. | 374 // Accessed by VM thread and profile generator thread. |
| 357 List<CpuProfile*> current_profiles_; | 375 List<CpuProfile*> current_profiles_; |
| 358 base::Semaphore current_profiles_semaphore_; | 376 base::Semaphore current_profiles_semaphore_; |
| 359 | 377 |
| 360 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); | 378 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); |
| 361 }; | 379 }; |
| 362 | 380 |
| 363 | 381 |
| 364 class ProfileGenerator { | 382 class ProfileGenerator { |
| 365 public: | 383 public: |
| 366 explicit ProfileGenerator(CpuProfilesCollection* profiles); | 384 explicit ProfileGenerator(CpuProfilesCollection* profiles); |
| 367 | 385 |
| 368 void RecordTickSample(const TickSample& sample); | 386 void RecordTickSample(const TickSample& sample); |
| 369 | 387 |
| 370 CodeMap* code_map() { return &code_map_; } | 388 CodeMap* code_map() { return &code_map_; } |
| 371 | 389 |
| 372 static const char* const kProgramEntryName; | |
| 373 static const char* const kIdleEntryName; | |
| 374 static const char* const kGarbageCollectorEntryName; | |
| 375 // Used to represent frames for which we have no reliable way to | |
| 376 // detect function. | |
| 377 static const char* const kUnresolvedFunctionName; | |
| 378 | |
| 379 private: | 390 private: |
| 380 CodeEntry* EntryForVMState(StateTag tag); | 391 CodeEntry* EntryForVMState(StateTag tag); |
| 381 | 392 |
| 382 CpuProfilesCollection* profiles_; | 393 CpuProfilesCollection* profiles_; |
| 383 CodeMap code_map_; | 394 CodeMap code_map_; |
| 384 CodeEntry* program_entry_; | |
| 385 CodeEntry* idle_entry_; | |
| 386 CodeEntry* gc_entry_; | |
| 387 CodeEntry* unresolved_entry_; | |
| 388 | 395 |
| 389 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 396 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 390 }; | 397 }; |
| 391 | 398 |
| 392 | 399 |
| 393 } // namespace internal | 400 } // namespace internal |
| 394 } // namespace v8 | 401 } // namespace v8 |
| 395 | 402 |
| 396 #endif // V8_PROFILER_PROFILE_GENERATOR_H_ | 403 #endif // V8_PROFILER_PROFILE_GENERATOR_H_ |
| OLD | NEW |