Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Side by Side Diff: src/profiler/profile-generator.h

Issue 2053523003: Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, 24> {}; 155 class BuiltinIdField : public BitField<Builtins::Name, 8, 24> {};
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 }; 326 };
289 327
290 class CpuProfilesCollection { 328 class CpuProfilesCollection {
291 public: 329 public:
292 explicit CpuProfilesCollection(Heap* heap); 330 explicit CpuProfilesCollection(Heap* heap);
293 ~CpuProfilesCollection(); 331 ~CpuProfilesCollection();
294 332
295 bool StartProfiling(const char* title, bool record_samples); 333 bool StartProfiling(const char* title, bool record_samples);
296 CpuProfile* StopProfiling(const char* title); 334 CpuProfile* StopProfiling(const char* title);
297 List<CpuProfile*>* profiles() { return &finished_profiles_; } 335 List<CpuProfile*>* profiles() { return &finished_profiles_; }
298 const char* GetName(Name* name) { 336 const char* GetName(Name* name) { return resource_names_.GetName(name); }
299 return function_and_resource_names_.GetName(name);
300 }
301 const char* GetName(int args_count) {
302 return function_and_resource_names_.GetName(args_count);
303 }
304 const char* GetFunctionName(Name* name) {
305 return function_and_resource_names_.GetFunctionName(name);
306 }
307 const char* GetFunctionName(const char* name) {
308 return function_and_resource_names_.GetFunctionName(name);
309 }
310 bool IsLastProfile(const char* title); 337 bool IsLastProfile(const char* title);
311 void RemoveProfile(CpuProfile* profile); 338 void RemoveProfile(CpuProfile* profile);
312 339
313 CodeEntry* NewCodeEntry(
314 Logger::LogEventsAndTags tag, const char* name,
315 const char* name_prefix = CodeEntry::kEmptyNamePrefix,
316 const char* resource_name = CodeEntry::kEmptyResourceName,
317 int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
318 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
319 JITLineInfoTable* line_info = NULL, Address instruction_start = NULL);
320
321 // Called from profile generator thread. 340 // Called from profile generator thread.
322 void AddPathToCurrentProfiles(base::TimeTicks timestamp, 341 void AddPathToCurrentProfiles(base::TimeTicks timestamp,
323 const std::vector<CodeEntry*>& path, 342 const std::vector<CodeEntry*>& path,
324 int src_line, bool update_stats); 343 int src_line, bool update_stats);
325 344
326 // Limits the number of profiles that can be simultaneously collected. 345 // Limits the number of profiles that can be simultaneously collected.
327 static const int kMaxSimultaneousProfiles = 100; 346 static const int kMaxSimultaneousProfiles = 100;
328 347
329 private: 348 private:
330 StringsStorage function_and_resource_names_; 349 StringsStorage resource_names_;
331 List<CodeEntry*> code_entries_;
332 List<CpuProfile*> finished_profiles_; 350 List<CpuProfile*> finished_profiles_;
333 351
334 Isolate* isolate_; 352 Isolate* isolate_;
335 353
336 // Accessed by VM thread and profile generator thread. 354 // Accessed by VM thread and profile generator thread.
337 List<CpuProfile*> current_profiles_; 355 List<CpuProfile*> current_profiles_;
338 base::Semaphore current_profiles_semaphore_; 356 base::Semaphore current_profiles_semaphore_;
339 357
340 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); 358 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection);
341 }; 359 };
342 360
343 361
344 class ProfileGenerator { 362 class ProfileGenerator {
345 public: 363 public:
346 explicit ProfileGenerator(CpuProfilesCollection* profiles); 364 explicit ProfileGenerator(CpuProfilesCollection* profiles);
347 365
348 void RecordTickSample(const TickSample& sample); 366 void RecordTickSample(const TickSample& sample);
349 367
350 CodeMap* code_map() { return &code_map_; } 368 CodeMap* code_map() { return &code_map_; }
351 369
352 static const char* const kProgramEntryName;
353 static const char* const kIdleEntryName;
354 static const char* const kGarbageCollectorEntryName;
355 // Used to represent frames for which we have no reliable way to
356 // detect function.
357 static const char* const kUnresolvedFunctionName;
358
359 private: 370 private:
360 CodeEntry* EntryForVMState(StateTag tag); 371 CodeEntry* EntryForVMState(StateTag tag);
361 372
362 CpuProfilesCollection* profiles_; 373 CpuProfilesCollection* profiles_;
363 CodeMap code_map_; 374 CodeMap code_map_;
364 CodeEntry* program_entry_;
365 CodeEntry* idle_entry_;
366 CodeEntry* gc_entry_;
367 CodeEntry* unresolved_entry_;
368 375
369 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); 376 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
370 }; 377 };
371 378
372 379
373 } // namespace internal 380 } // namespace internal
374 } // namespace v8 381 } // namespace v8
375 382
376 #endif // V8_PROFILER_PROFILE_GENERATOR_H_ 383 #endif // V8_PROFILER_PROFILE_GENERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698