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 16 matching lines...) Expand all Loading... |
90 HashMap names_; | 66 HashMap names_; |
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_prefix, | |
101 const char* name, | 76 const char* name, |
102 int security_token_id = TokenEnumerator::kNoSecurityToken, | 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 security_token_id() const) { return security_token_id_; } | 89 INLINE(int script_id() const) { return script_id_; } |
| 90 INLINE(void set_script_id(int script_id)) { script_id_ = script_id; } |
115 | 91 |
116 INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag)); | 92 INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag)); |
117 | 93 |
118 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 94 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
119 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 95 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
120 no_frame_ranges_ = ranges; | 96 no_frame_ranges_ = ranges; |
121 } | 97 } |
122 | 98 |
| 99 void SetBuiltinId(Builtins::Name id); |
| 100 Builtins::Name builtin_id() const { return builtin_id_; } |
| 101 |
123 void CopyData(const CodeEntry& source); | 102 void CopyData(const CodeEntry& source); |
124 uint32_t GetCallUid() const; | 103 uint32_t GetCallUid() const; |
125 bool IsSameAs(CodeEntry* entry) const; | 104 bool IsSameAs(CodeEntry* entry) const; |
126 | 105 |
127 static const char* const kEmptyNamePrefix; | 106 static const char* const kEmptyNamePrefix; |
128 static const char* const kEmptyResourceName; | 107 static const char* const kEmptyResourceName; |
129 | 108 |
130 private: | 109 private: |
131 Logger::LogEventsAndTags tag_; | 110 Logger::LogEventsAndTags tag_ : 8; |
| 111 Builtins::Name builtin_id_ : 8; |
132 const char* name_prefix_; | 112 const char* name_prefix_; |
133 const char* name_; | 113 const char* name_; |
134 const char* resource_name_; | 114 const char* resource_name_; |
135 int line_number_; | 115 int line_number_; |
136 int shared_id_; | 116 int shared_id_; |
137 int security_token_id_; | 117 int script_id_; |
138 List<OffsetRange>* no_frame_ranges_; | 118 List<OffsetRange>* no_frame_ranges_; |
139 | 119 |
140 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 120 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
141 }; | 121 }; |
142 | 122 |
143 | 123 |
144 class ProfileTree; | 124 class ProfileTree; |
145 | 125 |
146 class ProfileNode { | 126 class ProfileNode { |
147 public: | 127 public: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 167 |
188 | 168 |
189 class ProfileTree { | 169 class ProfileTree { |
190 public: | 170 public: |
191 ProfileTree(); | 171 ProfileTree(); |
192 ~ProfileTree(); | 172 ~ProfileTree(); |
193 | 173 |
194 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); | 174 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); |
195 void AddPathFromStart(const Vector<CodeEntry*>& path); | 175 void AddPathFromStart(const Vector<CodeEntry*>& path); |
196 void CalculateTotalTicks(); | 176 void CalculateTotalTicks(); |
197 void FilteredClone(ProfileTree* src, int security_token_id); | |
198 | 177 |
199 double TicksToMillis(unsigned ticks) const { | 178 double TicksToMillis(unsigned ticks) const { |
200 return ticks * ms_to_ticks_scale_; | 179 return ticks * ms_to_ticks_scale_; |
201 } | 180 } |
202 ProfileNode* root() const { return root_; } | 181 ProfileNode* root() const { return root_; } |
203 void SetTickRatePerMs(double ticks_per_ms); | 182 void SetTickRatePerMs(double ticks_per_ms); |
204 | 183 |
205 unsigned next_node_id() { return next_node_id_++; } | 184 unsigned next_node_id() { return next_node_id_++; } |
206 | 185 |
207 void ShortPrint(); | 186 void ShortPrint(); |
(...skipping 16 matching lines...) Expand all Loading... |
224 | 203 |
225 class CpuProfile { | 204 class CpuProfile { |
226 public: | 205 public: |
227 CpuProfile(const char* title, unsigned uid, bool record_samples) | 206 CpuProfile(const char* title, unsigned uid, bool record_samples) |
228 : title_(title), uid_(uid), record_samples_(record_samples) { } | 207 : title_(title), uid_(uid), record_samples_(record_samples) { } |
229 | 208 |
230 // Add pc -> ... -> main() call path to the profile. | 209 // Add pc -> ... -> main() call path to the profile. |
231 void AddPath(const Vector<CodeEntry*>& path); | 210 void AddPath(const Vector<CodeEntry*>& path); |
232 void CalculateTotalTicks(); | 211 void CalculateTotalTicks(); |
233 void SetActualSamplingRate(double actual_sampling_rate); | 212 void SetActualSamplingRate(double actual_sampling_rate); |
234 CpuProfile* FilteredClone(int security_token_id); | |
235 | 213 |
236 INLINE(const char* title() const) { return title_; } | 214 INLINE(const char* title() const) { return title_; } |
237 INLINE(unsigned uid() const) { return uid_; } | 215 INLINE(unsigned uid() const) { return uid_; } |
238 INLINE(const ProfileTree* top_down() const) { return &top_down_; } | 216 INLINE(const ProfileTree* top_down() const) { return &top_down_; } |
239 | 217 |
240 INLINE(int samples_count() const) { return samples_.length(); } | 218 INLINE(int samples_count() const) { return samples_.length(); } |
241 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } | 219 INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } |
242 | 220 |
243 void UpdateTicksScale(); | 221 void UpdateTicksScale(); |
244 | 222 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 DISALLOW_COPY_AND_ASSIGN(CodeMap); | 279 DISALLOW_COPY_AND_ASSIGN(CodeMap); |
302 }; | 280 }; |
303 | 281 |
304 | 282 |
305 class CpuProfilesCollection { | 283 class CpuProfilesCollection { |
306 public: | 284 public: |
307 CpuProfilesCollection(); | 285 CpuProfilesCollection(); |
308 ~CpuProfilesCollection(); | 286 ~CpuProfilesCollection(); |
309 | 287 |
310 bool StartProfiling(const char* title, unsigned uid, bool record_samples); | 288 bool StartProfiling(const char* title, unsigned uid, bool record_samples); |
311 CpuProfile* StopProfiling(int security_token_id, | 289 CpuProfile* StopProfiling(const char* title, double actual_sampling_rate); |
312 const char* title, | 290 List<CpuProfile*>* profiles() { return &finished_profiles_; } |
313 double actual_sampling_rate); | |
314 List<CpuProfile*>* Profiles(int security_token_id); | |
315 const char* GetName(Name* name) { | 291 const char* GetName(Name* name) { |
316 return function_and_resource_names_.GetName(name); | 292 return function_and_resource_names_.GetName(name); |
317 } | 293 } |
318 const char* GetName(int args_count) { | 294 const char* GetName(int args_count) { |
319 return function_and_resource_names_.GetName(args_count); | 295 return function_and_resource_names_.GetName(args_count); |
320 } | 296 } |
321 CpuProfile* GetProfile(int security_token_id, unsigned uid); | 297 const char* GetFunctionName(Name* name) { |
| 298 return function_and_resource_names_.GetFunctionName(name); |
| 299 } |
| 300 const char* GetFunctionName(const char* name) { |
| 301 return function_and_resource_names_.GetFunctionName(name); |
| 302 } |
322 bool IsLastProfile(const char* title); | 303 bool IsLastProfile(const char* title); |
323 void RemoveProfile(CpuProfile* profile); | 304 void RemoveProfile(CpuProfile* profile); |
324 bool HasDetachedProfiles() { return detached_profiles_.length() > 0; } | |
325 | 305 |
326 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, | 306 CodeEntry* NewCodeEntry( |
327 Name* name, String* resource_name, int line_number); | 307 Logger::LogEventsAndTags tag, |
328 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name); | 308 const char* name, |
329 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, | 309 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
330 const char* name_prefix, Name* name); | 310 const char* resource_name = CodeEntry::kEmptyResourceName, |
331 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, int args_count); | 311 int line_number = v8::CpuProfileNode::kNoLineNumberInfo); |
332 CodeEntry* NewCodeEntry(int security_token_id); | |
333 | 312 |
334 // Called from profile generator thread. | 313 // Called from profile generator thread. |
335 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); | 314 void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); |
336 | 315 |
337 // Limits the number of profiles that can be simultaneously collected. | 316 // Limits the number of profiles that can be simultaneously collected. |
338 static const int kMaxSimultaneousProfiles = 100; | 317 static const int kMaxSimultaneousProfiles = 100; |
339 | 318 |
340 private: | 319 private: |
341 const char* GetFunctionName(Name* name) { | |
342 return function_and_resource_names_.GetFunctionName(name); | |
343 } | |
344 const char* GetFunctionName(const char* name) { | |
345 return function_and_resource_names_.GetFunctionName(name); | |
346 } | |
347 int GetProfileIndex(unsigned uid); | |
348 List<CpuProfile*>* GetProfilesList(int security_token_id); | |
349 int TokenToIndex(int security_token_id); | |
350 | |
351 INLINE(static bool UidsMatch(void* key1, void* key2)) { | |
352 return key1 == key2; | |
353 } | |
354 | |
355 StringsStorage function_and_resource_names_; | 320 StringsStorage function_and_resource_names_; |
356 List<CodeEntry*> code_entries_; | 321 List<CodeEntry*> code_entries_; |
357 List<List<CpuProfile*>* > profiles_by_token_; | 322 List<CpuProfile*> finished_profiles_; |
358 // Mapping from profiles' uids to indexes in the second nested list | |
359 // of profiles_by_token_. | |
360 HashMap profiles_uids_; | |
361 List<CpuProfile*> detached_profiles_; | |
362 | 323 |
363 // Accessed by VM thread and profile generator thread. | 324 // Accessed by VM thread and profile generator thread. |
364 List<CpuProfile*> current_profiles_; | 325 List<CpuProfile*> current_profiles_; |
365 Semaphore* current_profiles_semaphore_; | 326 Semaphore* current_profiles_semaphore_; |
366 | 327 |
367 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); | 328 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); |
368 }; | 329 }; |
369 | 330 |
370 | 331 |
371 class SampleRateCalculator { | 332 class SampleRateCalculator { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 INLINE(CodeMap* code_map()) { return &code_map_; } | 376 INLINE(CodeMap* code_map()) { return &code_map_; } |
416 | 377 |
417 INLINE(void Tick()) { sample_rate_calc_.Tick(); } | 378 INLINE(void Tick()) { sample_rate_calc_.Tick(); } |
418 INLINE(double actual_sampling_rate()) { | 379 INLINE(double actual_sampling_rate()) { |
419 return sample_rate_calc_.ticks_per_ms(); | 380 return sample_rate_calc_.ticks_per_ms(); |
420 } | 381 } |
421 | 382 |
422 static const char* const kAnonymousFunctionName; | 383 static const char* const kAnonymousFunctionName; |
423 static const char* const kProgramEntryName; | 384 static const char* const kProgramEntryName; |
424 static const char* const kGarbageCollectorEntryName; | 385 static const char* const kGarbageCollectorEntryName; |
| 386 // Used to represent frames for which we have no reliable way to |
| 387 // detect function. |
| 388 static const char* const kUnresolvedFunctionName; |
425 | 389 |
426 private: | 390 private: |
427 INLINE(CodeEntry* EntryForVMState(StateTag tag)); | 391 INLINE(CodeEntry* EntryForVMState(StateTag tag)); |
428 | 392 |
429 CpuProfilesCollection* profiles_; | 393 CpuProfilesCollection* profiles_; |
430 CodeMap code_map_; | 394 CodeMap code_map_; |
431 CodeEntry* program_entry_; | 395 CodeEntry* program_entry_; |
432 CodeEntry* gc_entry_; | 396 CodeEntry* gc_entry_; |
| 397 CodeEntry* unresolved_entry_; |
433 SampleRateCalculator sample_rate_calc_; | 398 SampleRateCalculator sample_rate_calc_; |
434 | 399 |
435 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 400 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
436 }; | 401 }; |
437 | 402 |
438 | 403 |
439 } } // namespace v8::internal | 404 } } // namespace v8::internal |
440 | 405 |
441 #endif // V8_PROFILE_GENERATOR_H_ | 406 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |