| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 class StringsStorage { | 42 class StringsStorage { |
| 43 public: | 43 public: |
| 44 explicit StringsStorage(Heap* heap); | 44 explicit StringsStorage(Heap* heap); |
| 45 ~StringsStorage(); | 45 ~StringsStorage(); |
| 46 | 46 |
| 47 const char* GetCopy(const char* src); | 47 const char* GetCopy(const char* src); |
| 48 const char* GetFormatted(const char* format, ...); | 48 const char* GetFormatted(const char* format, ...); |
| 49 const char* GetVFormatted(const char* format, va_list args); | 49 const char* GetVFormatted(const char* format, va_list args); |
| 50 const char* GetName(Name* name); | 50 const char* GetName(Name* name); |
| 51 const char* GetName(int index); | 51 const char* GetName(int index); |
| 52 inline const char* GetFunctionName(Name* name); | 52 const char* GetFunctionName(Name* name); |
| 53 inline const char* GetFunctionName(const char* name); | 53 const char* GetFunctionName(const char* name); |
| 54 size_t GetUsedMemorySize() const; | 54 size_t GetUsedMemorySize() const; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 static const int kMaxNameSize = 1024; | 57 static const int kMaxNameSize = 1024; |
| 58 | 58 |
| 59 INLINE(static bool StringsMatch(void* key1, void* key2)) { | 59 static bool StringsMatch(void* key1, void* key2); |
| 60 return strcmp(reinterpret_cast<char*>(key1), | 60 const char* BeautifyFunctionName(const char* name); |
| 61 reinterpret_cast<char*>(key2)) == 0; | 61 const char* AddOrDisposeString(char* str, int len); |
| 62 } | 62 HashMap::Entry* GetEntry(const char* str, int len); |
| 63 const char* AddOrDisposeString(char* str, uint32_t hash); | |
| 64 | 63 |
| 65 // Mapping of strings by String::Hash to const char* strings. | |
| 66 uint32_t hash_seed_; | 64 uint32_t hash_seed_; |
| 67 HashMap names_; | 65 HashMap names_; |
| 68 | 66 |
| 69 DISALLOW_COPY_AND_ASSIGN(StringsStorage); | 67 DISALLOW_COPY_AND_ASSIGN(StringsStorage); |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 | 70 |
| 73 class CodeEntry { | 71 class CodeEntry { |
| 74 public: | 72 public: |
| 75 // CodeEntry doesn't own name strings, just references them. | 73 // CodeEntry doesn't own name strings, just references them. |
| 76 INLINE(CodeEntry(Logger::LogEventsAndTags tag, | 74 inline CodeEntry(Logger::LogEventsAndTags tag, |
| 77 const char* name, | 75 const char* name, |
| 78 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 76 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 79 const char* resource_name = CodeEntry::kEmptyResourceName, | 77 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 80 int line_number = v8::CpuProfileNode::kNoLineNumberInfo)); | 78 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 79 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); |
| 81 ~CodeEntry(); | 80 ~CodeEntry(); |
| 82 | 81 |
| 83 INLINE(bool is_js_function() const) { return is_js_function_tag(tag_); } | 82 bool is_js_function() const { return is_js_function_tag(tag_); } |
| 84 INLINE(const char* name_prefix() const) { return name_prefix_; } | 83 const char* name_prefix() const { return name_prefix_; } |
| 85 INLINE(bool has_name_prefix() const) { return name_prefix_[0] != '\0'; } | 84 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } |
| 86 INLINE(const char* name() const) { return name_; } | 85 const char* name() const { return name_; } |
| 87 INLINE(const char* resource_name() const) { return resource_name_; } | 86 const char* resource_name() const { return resource_name_; } |
| 88 INLINE(int line_number() const) { return line_number_; } | 87 int line_number() const { return line_number_; } |
| 89 INLINE(void set_shared_id(int shared_id)) { shared_id_ = shared_id; } | 88 int column_number() const { return column_number_; } |
| 90 INLINE(int script_id() const) { return script_id_; } | 89 void set_shared_id(int shared_id) { shared_id_ = shared_id; } |
| 91 INLINE(void set_script_id(int script_id)) { script_id_ = script_id; } | 90 int script_id() const { return script_id_; } |
| 92 INLINE(void set_bailout_reason(const char* bailout_reason)) { | 91 void set_script_id(int script_id) { script_id_ = script_id; } |
| 92 void set_bailout_reason(const char* bailout_reason) { |
| 93 bailout_reason_ = bailout_reason; | 93 bailout_reason_ = bailout_reason; |
| 94 } | 94 } |
| 95 INLINE(const char* bailout_reason() const) { return bailout_reason_; } | 95 const char* bailout_reason() const { return bailout_reason_; } |
| 96 | 96 |
| 97 INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag)); | 97 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
| 98 | 98 |
| 99 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 99 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
| 100 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 100 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
| 101 no_frame_ranges_ = ranges; | 101 no_frame_ranges_ = ranges; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void SetBuiltinId(Builtins::Name id); | 104 void SetBuiltinId(Builtins::Name id); |
| 105 Builtins::Name builtin_id() const { return builtin_id_; } | 105 Builtins::Name builtin_id() const { return builtin_id_; } |
| 106 | 106 |
| 107 void CopyData(const CodeEntry& source); | |
| 108 uint32_t GetCallUid() const; | 107 uint32_t GetCallUid() const; |
| 109 bool IsSameAs(CodeEntry* entry) const; | 108 bool IsSameAs(CodeEntry* entry) const; |
| 110 | 109 |
| 111 static const char* const kEmptyNamePrefix; | 110 static const char* const kEmptyNamePrefix; |
| 112 static const char* const kEmptyResourceName; | 111 static const char* const kEmptyResourceName; |
| 113 static const char* const kEmptyBailoutReason; | 112 static const char* const kEmptyBailoutReason; |
| 114 | 113 |
| 115 private: | 114 private: |
| 116 Logger::LogEventsAndTags tag_ : 8; | 115 Logger::LogEventsAndTags tag_ : 8; |
| 117 Builtins::Name builtin_id_ : 8; | 116 Builtins::Name builtin_id_ : 8; |
| 118 const char* name_prefix_; | 117 const char* name_prefix_; |
| 119 const char* name_; | 118 const char* name_; |
| 120 const char* resource_name_; | 119 const char* resource_name_; |
| 121 int line_number_; | 120 int line_number_; |
| 121 int column_number_; |
| 122 int shared_id_; | 122 int shared_id_; |
| 123 int script_id_; | 123 int script_id_; |
| 124 List<OffsetRange>* no_frame_ranges_; | 124 List<OffsetRange>* no_frame_ranges_; |
| 125 const char* bailout_reason_; | 125 const char* bailout_reason_; |
| 126 | 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 127 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 | 130 |
| 131 class ProfileTree; | 131 class ProfileTree; |
| 132 | 132 |
| 133 class ProfileNode { | 133 class ProfileNode { |
| 134 public: | 134 public: |
| 135 INLINE(ProfileNode(ProfileTree* tree, CodeEntry* entry)); | 135 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
| 136 | 136 |
| 137 ProfileNode* FindChild(CodeEntry* entry); | 137 ProfileNode* FindChild(CodeEntry* entry); |
| 138 ProfileNode* FindOrAddChild(CodeEntry* entry); | 138 ProfileNode* FindOrAddChild(CodeEntry* entry); |
| 139 INLINE(void IncrementSelfTicks()) { ++self_ticks_; } | 139 void IncrementSelfTicks() { ++self_ticks_; } |
| 140 INLINE(void IncreaseSelfTicks(unsigned amount)) { self_ticks_ += amount; } | 140 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
| 141 | 141 |
| 142 INLINE(CodeEntry* entry() const) { return entry_; } | 142 CodeEntry* entry() const { return entry_; } |
| 143 INLINE(unsigned self_ticks() const) { return self_ticks_; } | 143 unsigned self_ticks() const { return self_ticks_; } |
| 144 INLINE(const List<ProfileNode*>* children() const) { return &children_list_; } | 144 const List<ProfileNode*>* children() const { return &children_list_; } |
| 145 unsigned id() const { return id_; } | 145 unsigned id() const { return id_; } |
| 146 | 146 |
| 147 void Print(int indent); | 147 void Print(int indent); |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 INLINE(static bool CodeEntriesMatch(void* entry1, void* entry2)) { | 150 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
| 151 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( | 151 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( |
| 152 reinterpret_cast<CodeEntry*>(entry2)); | 152 reinterpret_cast<CodeEntry*>(entry2)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 INLINE(static uint32_t CodeEntryHash(CodeEntry* entry)) { | 155 static uint32_t CodeEntryHash(CodeEntry* entry) { |
| 156 return entry->GetCallUid(); | 156 return entry->GetCallUid(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 ProfileTree* tree_; | 159 ProfileTree* tree_; |
| 160 CodeEntry* entry_; | 160 CodeEntry* entry_; |
| 161 unsigned self_ticks_; | 161 unsigned self_ticks_; |
| 162 // Mapping from CodeEntry* to ProfileNode* | 162 // Mapping from CodeEntry* to ProfileNode* |
| 163 HashMap children_; | 163 HashMap children_; |
| 164 List<ProfileNode*> children_list_; | 164 List<ProfileNode*> children_list_; |
| 165 unsigned id_; | 165 unsigned id_; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return function_and_resource_names_.GetFunctionName(name); | 297 return function_and_resource_names_.GetFunctionName(name); |
| 298 } | 298 } |
| 299 bool IsLastProfile(const char* title); | 299 bool IsLastProfile(const char* title); |
| 300 void RemoveProfile(CpuProfile* profile); | 300 void RemoveProfile(CpuProfile* profile); |
| 301 | 301 |
| 302 CodeEntry* NewCodeEntry( | 302 CodeEntry* NewCodeEntry( |
| 303 Logger::LogEventsAndTags tag, | 303 Logger::LogEventsAndTags tag, |
| 304 const char* name, | 304 const char* name, |
| 305 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 305 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 306 const char* resource_name = CodeEntry::kEmptyResourceName, | 306 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 307 int line_number = v8::CpuProfileNode::kNoLineNumberInfo); | 307 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
| 308 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo); |
| 308 | 309 |
| 309 // Called from profile generator thread. | 310 // Called from profile generator thread. |
| 310 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); | 311 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); |
| 311 | 312 |
| 312 // Limits the number of profiles that can be simultaneously collected. | 313 // Limits the number of profiles that can be simultaneously collected. |
| 313 static const int kMaxSimultaneousProfiles = 100; | 314 static const int kMaxSimultaneousProfiles = 100; |
| 314 | 315 |
| 315 private: | 316 private: |
| 316 StringsStorage function_and_resource_names_; | 317 StringsStorage function_and_resource_names_; |
| 317 List<CodeEntry*> code_entries_; | 318 List<CodeEntry*> code_entries_; |
| 318 List<CpuProfile*> finished_profiles_; | 319 List<CpuProfile*> finished_profiles_; |
| 319 | 320 |
| 320 // Accessed by VM thread and profile generator thread. | 321 // Accessed by VM thread and profile generator thread. |
| 321 List<CpuProfile*> current_profiles_; | 322 List<CpuProfile*> current_profiles_; |
| 322 Semaphore current_profiles_semaphore_; | 323 Semaphore current_profiles_semaphore_; |
| 323 | 324 |
| 324 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); | 325 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); |
| 325 }; | 326 }; |
| 326 | 327 |
| 327 | 328 |
| 328 class ProfileGenerator { | 329 class ProfileGenerator { |
| 329 public: | 330 public: |
| 330 explicit ProfileGenerator(CpuProfilesCollection* profiles); | 331 explicit ProfileGenerator(CpuProfilesCollection* profiles); |
| 331 | 332 |
| 332 void RecordTickSample(const TickSample& sample); | 333 void RecordTickSample(const TickSample& sample); |
| 333 | 334 |
| 334 INLINE(CodeMap* code_map()) { return &code_map_; } | 335 CodeMap* code_map() { return &code_map_; } |
| 335 | 336 |
| 336 static const char* const kAnonymousFunctionName; | 337 static const char* const kAnonymousFunctionName; |
| 337 static const char* const kProgramEntryName; | 338 static const char* const kProgramEntryName; |
| 338 static const char* const kIdleEntryName; | 339 static const char* const kIdleEntryName; |
| 339 static const char* const kGarbageCollectorEntryName; | 340 static const char* const kGarbageCollectorEntryName; |
| 340 // Used to represent frames for which we have no reliable way to | 341 // Used to represent frames for which we have no reliable way to |
| 341 // detect function. | 342 // detect function. |
| 342 static const char* const kUnresolvedFunctionName; | 343 static const char* const kUnresolvedFunctionName; |
| 343 | 344 |
| 344 private: | 345 private: |
| 345 INLINE(CodeEntry* EntryForVMState(StateTag tag)); | 346 CodeEntry* EntryForVMState(StateTag tag); |
| 346 | 347 |
| 347 CpuProfilesCollection* profiles_; | 348 CpuProfilesCollection* profiles_; |
| 348 CodeMap code_map_; | 349 CodeMap code_map_; |
| 349 CodeEntry* program_entry_; | 350 CodeEntry* program_entry_; |
| 350 CodeEntry* idle_entry_; | 351 CodeEntry* idle_entry_; |
| 351 CodeEntry* gc_entry_; | 352 CodeEntry* gc_entry_; |
| 352 CodeEntry* unresolved_entry_; | 353 CodeEntry* unresolved_entry_; |
| 353 | 354 |
| 354 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 355 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 355 }; | 356 }; |
| 356 | 357 |
| 357 | 358 |
| 358 } } // namespace v8::internal | 359 } } // namespace v8::internal |
| 359 | 360 |
| 360 #endif // V8_PROFILE_GENERATOR_H_ | 361 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |