| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "hashmap.h" | 32 #include "hashmap.h" |
| 33 #include "../include/v8-profiler.h" | 33 #include "../include/v8-profiler.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 struct OffsetRange; | 38 struct OffsetRange; |
| 39 | 39 |
| 40 class TokenEnumerator { | |
| 41 public: | |
| 42 TokenEnumerator(); | |
| 43 ~TokenEnumerator(); | |
| 44 int GetTokenId(Object* token); | |
| 45 | |
| 46 static const int kNoSecurityToken = -1; | |
| 47 static const int kInheritsSecurityToken = -2; | |
| 48 | |
| 49 private: | |
| 50 static void TokenRemovedCallback(v8::Isolate* isolate, | |
| 51 v8::Persistent<v8::Value>* handle, | |
| 52 void* parameter); | |
| 53 void TokenRemoved(Object** token_location); | |
| 54 | |
| 55 List<Object**> token_locations_; | |
| 56 List<bool> token_removed_; | |
| 57 | |
| 58 friend class TokenEnumeratorTester; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(TokenEnumerator); | |
| 61 }; | |
| 62 | |
| 63 | |
| 64 // Provides a storage of strings allocated in C++ heap, to hold them | 40 // Provides a storage of strings allocated in C++ heap, to hold them |
| 65 // forever, even if they disappear from JS heap or external storage. | 41 // forever, even if they disappear from JS heap or external storage. |
| 66 class StringsStorage { | 42 class StringsStorage { |
| 67 public: | 43 public: |
| 68 StringsStorage(); | 44 StringsStorage(); |
| 69 ~StringsStorage(); | 45 ~StringsStorage(); |
| 70 | 46 |
| 71 const char* GetCopy(const char* src); | 47 const char* GetCopy(const char* src); |
| 72 const char* GetFormatted(const char* format, ...); | 48 const char* GetFormatted(const char* format, ...); |
| 73 const char* GetVFormatted(const char* format, va_list args); | 49 const char* GetVFormatted(const char* format, va_list args); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 | 67 |
| 92 DISALLOW_COPY_AND_ASSIGN(StringsStorage); | 68 DISALLOW_COPY_AND_ASSIGN(StringsStorage); |
| 93 }; | 69 }; |
| 94 | 70 |
| 95 | 71 |
| 96 class CodeEntry { | 72 class CodeEntry { |
| 97 public: | 73 public: |
| 98 // CodeEntry doesn't own name strings, just references them. | 74 // CodeEntry doesn't own name strings, just references them. |
| 99 INLINE(CodeEntry(Logger::LogEventsAndTags tag, | 75 INLINE(CodeEntry(Logger::LogEventsAndTags tag, |
| 100 const char* name, | 76 const char* name, |
| 101 int security_token_id = TokenEnumerator::kNoSecurityToken, | |
| 102 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 77 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 103 const char* resource_name = CodeEntry::kEmptyResourceName, | 78 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 104 int line_number = v8::CpuProfileNode::kNoLineNumberInfo)); | 79 int line_number = v8::CpuProfileNode::kNoLineNumberInfo)); |
| 105 ~CodeEntry(); | 80 ~CodeEntry(); |
| 106 | 81 |
| 107 INLINE(bool is_js_function() const) { return is_js_function_tag(tag_); } | 82 INLINE(bool is_js_function() const) { return is_js_function_tag(tag_); } |
| 108 INLINE(const char* name_prefix() const) { return name_prefix_; } | 83 INLINE(const char* name_prefix() const) { return name_prefix_; } |
| 109 INLINE(bool has_name_prefix() const) { return name_prefix_[0] != '\0'; } | 84 INLINE(bool has_name_prefix() const) { return name_prefix_[0] != '\0'; } |
| 110 INLINE(const char* name() const) { return name_; } | 85 INLINE(const char* name() const) { return name_; } |
| 111 INLINE(const char* resource_name() const) { return resource_name_; } | 86 INLINE(const char* resource_name() const) { return resource_name_; } |
| 112 INLINE(int line_number() const) { return line_number_; } | 87 INLINE(int line_number() const) { return line_number_; } |
| 113 INLINE(void set_shared_id(int shared_id)) { shared_id_ = shared_id; } | 88 INLINE(void set_shared_id(int shared_id)) { shared_id_ = shared_id; } |
| 114 INLINE(int script_id() const) { return script_id_; } | 89 INLINE(int script_id() const) { return script_id_; } |
| 115 INLINE(void set_script_id(int script_id)) { script_id_ = script_id; } | 90 INLINE(void set_script_id(int script_id)) { script_id_ = script_id; } |
| 116 INLINE(int security_token_id() const) { return security_token_id_; } | |
| 117 | 91 |
| 118 INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag)); | 92 INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag)); |
| 119 | 93 |
| 120 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 94 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
| 121 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 95 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
| 122 no_frame_ranges_ = ranges; | 96 no_frame_ranges_ = ranges; |
| 123 } | 97 } |
| 124 | 98 |
| 125 void SetBuiltinId(Builtins::Name id); | 99 void SetBuiltinId(Builtins::Name id); |
| 126 Builtins::Name builtin_id() const { return builtin_id_; } | 100 Builtins::Name builtin_id() const { return builtin_id_; } |
| 127 | 101 |
| 128 void CopyData(const CodeEntry& source); | 102 void CopyData(const CodeEntry& source); |
| 129 uint32_t GetCallUid() const; | 103 uint32_t GetCallUid() const; |
| 130 bool IsSameAs(CodeEntry* entry) const; | 104 bool IsSameAs(CodeEntry* entry) const; |
| 131 | 105 |
| 132 static const char* const kEmptyNamePrefix; | 106 static const char* const kEmptyNamePrefix; |
| 133 static const char* const kEmptyResourceName; | 107 static const char* const kEmptyResourceName; |
| 134 | 108 |
| 135 private: | 109 private: |
| 136 Logger::LogEventsAndTags tag_ : 8; | 110 Logger::LogEventsAndTags tag_ : 8; |
| 137 Builtins::Name builtin_id_ : 8; | 111 Builtins::Name builtin_id_ : 8; |
| 138 const char* name_prefix_; | 112 const char* name_prefix_; |
| 139 const char* name_; | 113 const char* name_; |
| 140 const char* resource_name_; | 114 const char* resource_name_; |
| 141 int line_number_; | 115 int line_number_; |
| 142 int shared_id_; | 116 int shared_id_; |
| 143 int script_id_; | 117 int script_id_; |
| 144 int security_token_id_; | |
| 145 List<OffsetRange>* no_frame_ranges_; | 118 List<OffsetRange>* no_frame_ranges_; |
| 146 | 119 |
| 147 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 120 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
| 148 }; | 121 }; |
| 149 | 122 |
| 150 | 123 |
| 151 class ProfileTree; | 124 class ProfileTree; |
| 152 | 125 |
| 153 class ProfileNode { | 126 class ProfileNode { |
| 154 public: | 127 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 167 |
| 195 | 168 |
| 196 class ProfileTree { | 169 class ProfileTree { |
| 197 public: | 170 public: |
| 198 ProfileTree(); | 171 ProfileTree(); |
| 199 ~ProfileTree(); | 172 ~ProfileTree(); |
| 200 | 173 |
| 201 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); | 174 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); |
| 202 void AddPathFromStart(const Vector<CodeEntry*>& path); | 175 void AddPathFromStart(const Vector<CodeEntry*>& path); |
| 203 void CalculateTotalTicks(); | 176 void CalculateTotalTicks(); |
| 204 void FilteredClone(ProfileTree* src, int security_token_id); | |
| 205 | 177 |
| 206 double TicksToMillis(unsigned ticks) const { | 178 double TicksToMillis(unsigned ticks) const { |
| 207 return ticks * ms_to_ticks_scale_; | 179 return ticks * ms_to_ticks_scale_; |
| 208 } | 180 } |
| 209 ProfileNode* root() const { return root_; } | 181 ProfileNode* root() const { return root_; } |
| 210 void SetTickRatePerMs(double ticks_per_ms); | 182 void SetTickRatePerMs(double ticks_per_ms); |
| 211 | 183 |
| 212 unsigned next_node_id() { return next_node_id_++; } | 184 unsigned next_node_id() { return next_node_id_++; } |
| 213 | 185 |
| 214 void ShortPrint(); | 186 void ShortPrint(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 | 203 |
| 232 class CpuProfile { | 204 class CpuProfile { |
| 233 public: | 205 public: |
| 234 CpuProfile(const char* title, unsigned uid, bool record_samples) | 206 CpuProfile(const char* title, unsigned uid, bool record_samples) |
| 235 : title_(title), uid_(uid), record_samples_(record_samples) { } | 207 : title_(title), uid_(uid), record_samples_(record_samples) { } |
| 236 | 208 |
| 237 // Add pc -> ... -> main() call path to the profile. | 209 // Add pc -> ... -> main() call path to the profile. |
| 238 void AddPath(const Vector<CodeEntry*>& path); | 210 void AddPath(const Vector<CodeEntry*>& path); |
| 239 void CalculateTotalTicks(); | 211 void CalculateTotalTicks(); |
| 240 void SetActualSamplingRate(double actual_sampling_rate); | 212 void SetActualSamplingRate(double actual_sampling_rate); |
| 241 CpuProfile* FilteredClone(int security_token_id); | |
| 242 | 213 |
| 243 INLINE(const char* title() const) { return title_; } | 214 INLINE(const char* title() const) { return title_; } |
| 244 INLINE(unsigned uid() const) { return uid_; } | 215 INLINE(unsigned uid() const) { return uid_; } |
| 245 INLINE(const ProfileTree* top_down() const) { return &top_down_; } | 216 INLINE(const ProfileTree* top_down() const) { return &top_down_; } |
| 246 | 217 |
| 247 INLINE(int samples_count() const) { return samples_.length(); } | 218 INLINE(int samples_count() const) { return samples_.length(); } |
| 248 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } | 219 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } |
| 249 | 220 |
| 250 void UpdateTicksScale(); | 221 void UpdateTicksScale(); |
| 251 | 222 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 DISALLOW_COPY_AND_ASSIGN(CodeMap); | 279 DISALLOW_COPY_AND_ASSIGN(CodeMap); |
| 309 }; | 280 }; |
| 310 | 281 |
| 311 | 282 |
| 312 class CpuProfilesCollection { | 283 class CpuProfilesCollection { |
| 313 public: | 284 public: |
| 314 CpuProfilesCollection(); | 285 CpuProfilesCollection(); |
| 315 ~CpuProfilesCollection(); | 286 ~CpuProfilesCollection(); |
| 316 | 287 |
| 317 bool StartProfiling(const char* title, unsigned uid, bool record_samples); | 288 bool StartProfiling(const char* title, unsigned uid, bool record_samples); |
| 318 CpuProfile* StopProfiling(int security_token_id, | 289 CpuProfile* StopProfiling(const char* title, double actual_sampling_rate); |
| 319 const char* title, | 290 List<CpuProfile*>* profiles() { return &finished_profiles_; } |
| 320 double actual_sampling_rate); | |
| 321 List<CpuProfile*>* Profiles(int security_token_id); | |
| 322 const char* GetName(Name* name) { | 291 const char* GetName(Name* name) { |
| 323 return function_and_resource_names_.GetName(name); | 292 return function_and_resource_names_.GetName(name); |
| 324 } | 293 } |
| 325 const char* GetName(int args_count) { | 294 const char* GetName(int args_count) { |
| 326 return function_and_resource_names_.GetName(args_count); | 295 return function_and_resource_names_.GetName(args_count); |
| 327 } | 296 } |
| 328 const char* GetFunctionName(Name* name) { | 297 const char* GetFunctionName(Name* name) { |
| 329 return function_and_resource_names_.GetFunctionName(name); | 298 return function_and_resource_names_.GetFunctionName(name); |
| 330 } | 299 } |
| 331 const char* GetFunctionName(const char* name) { | 300 const char* GetFunctionName(const char* name) { |
| 332 return function_and_resource_names_.GetFunctionName(name); | 301 return function_and_resource_names_.GetFunctionName(name); |
| 333 } | 302 } |
| 334 CpuProfile* GetProfile(int security_token_id, unsigned uid); | |
| 335 bool IsLastProfile(const char* title); | 303 bool IsLastProfile(const char* title); |
| 336 void RemoveProfile(CpuProfile* profile); | 304 void RemoveProfile(CpuProfile* profile); |
| 337 bool HasDetachedProfiles() { return detached_profiles_.length() > 0; } | |
| 338 | 305 |
| 339 CodeEntry* NewCodeEntry( | 306 CodeEntry* NewCodeEntry( |
| 340 Logger::LogEventsAndTags tag, | 307 Logger::LogEventsAndTags tag, |
| 341 const char* name, | 308 const char* name, |
| 342 int security_token_id = TokenEnumerator::kNoSecurityToken, | |
| 343 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 309 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
| 344 const char* resource_name = CodeEntry::kEmptyResourceName, | 310 const char* resource_name = CodeEntry::kEmptyResourceName, |
| 345 int line_number = v8::CpuProfileNode::kNoLineNumberInfo); | 311 int line_number = v8::CpuProfileNode::kNoLineNumberInfo); |
| 346 | 312 |
| 347 // Called from profile generator thread. | 313 // Called from profile generator thread. |
| 348 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); | 314 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); |
| 349 | 315 |
| 350 // Limits the number of profiles that can be simultaneously collected. | 316 // Limits the number of profiles that can be simultaneously collected. |
| 351 static const int kMaxSimultaneousProfiles = 100; | 317 static const int kMaxSimultaneousProfiles = 100; |
| 352 | 318 |
| 353 private: | 319 private: |
| 354 int GetProfileIndex(unsigned uid); | |
| 355 List<CpuProfile*>* GetProfilesList(int security_token_id); | |
| 356 int TokenToIndex(int security_token_id); | |
| 357 | |
| 358 INLINE(static bool UidsMatch(void* key1, void* key2)) { | |
| 359 return key1 == key2; | |
| 360 } | |
| 361 | |
| 362 StringsStorage function_and_resource_names_; | 320 StringsStorage function_and_resource_names_; |
| 363 List<CodeEntry*> code_entries_; | 321 List<CodeEntry*> code_entries_; |
| 364 List<List<CpuProfile*>* > profiles_by_token_; | 322 List<CpuProfile*> finished_profiles_; |
| 365 // Mapping from profiles' uids to indexes in the second nested list | |
| 366 // of profiles_by_token_. | |
| 367 HashMap profiles_uids_; | |
| 368 List<CpuProfile*> detached_profiles_; | |
| 369 | 323 |
| 370 // Accessed by VM thread and profile generator thread. | 324 // Accessed by VM thread and profile generator thread. |
| 371 List<CpuProfile*> current_profiles_; | 325 List<CpuProfile*> current_profiles_; |
| 372 Semaphore* current_profiles_semaphore_; | 326 Semaphore* current_profiles_semaphore_; |
| 373 | 327 |
| 374 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); | 328 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); |
| 375 }; | 329 }; |
| 376 | 330 |
| 377 | 331 |
| 378 class SampleRateCalculator { | 332 class SampleRateCalculator { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 CodeEntry* unresolved_entry_; | 397 CodeEntry* unresolved_entry_; |
| 444 SampleRateCalculator sample_rate_calc_; | 398 SampleRateCalculator sample_rate_calc_; |
| 445 | 399 |
| 446 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 400 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
| 447 }; | 401 }; |
| 448 | 402 |
| 449 | 403 |
| 450 } } // namespace v8::internal | 404 } } // namespace v8::internal |
| 451 | 405 |
| 452 #endif // V8_PROFILE_GENERATOR_H_ | 406 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |