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

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: rebase 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
« no previous file with comments | « src/profiler/cpu-profiler.cc ('k') | src/profiler/profile-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 Address instruction_start() const { return instruction_start_; } 107 Address instruction_start() const { return instruction_start_; }
108 CodeEventListener::LogEventsAndTags tag() const { 108 CodeEventListener::LogEventsAndTags tag() const {
109 return TagField::decode(bit_field_); 109 return TagField::decode(bit_field_);
110 } 110 }
111 111
112 static const char* const kEmptyNamePrefix; 112 static const char* const kEmptyNamePrefix;
113 static const char* const kEmptyResourceName; 113 static const char* const kEmptyResourceName;
114 static const char* const kEmptyBailoutReason; 114 static const char* const kEmptyBailoutReason;
115 static const char* const kNoDeoptReason; 115 static const char* const kNoDeoptReason;
116 116
117 static const char* const kProgramEntryName;
118 static const char* const kIdleEntryName;
119 static const char* const kGarbageCollectorEntryName;
120 // Used to represent frames for which we have no reliable way to
121 // detect function.
122 static const char* const kUnresolvedFunctionName;
123
124 V8_INLINE static CodeEntry* program_entry() {
125 return kProgramEntry.Pointer();
126 }
127 V8_INLINE static CodeEntry* idle_entry() { return kIdleEntry.Pointer(); }
128 V8_INLINE static CodeEntry* gc_entry() { return kGCEntry.Pointer(); }
129 V8_INLINE static CodeEntry* unresolved_entry() {
130 return kUnresolvedEntry.Pointer();
131 }
132
117 private: 133 private:
134 struct ProgramEntryCreateTrait {
135 static CodeEntry* Create();
136 };
137 struct IdleEntryCreateTrait {
138 static CodeEntry* Create();
139 };
140 struct GCEntryCreateTrait {
141 static CodeEntry* Create();
142 };
143 struct UnresolvedEntryCreateTrait {
144 static CodeEntry* Create();
145 };
146
147 static base::LazyDynamicInstance<CodeEntry, ProgramEntryCreateTrait>::type
148 kProgramEntry;
149 static base::LazyDynamicInstance<CodeEntry, IdleEntryCreateTrait>::type
150 kIdleEntry;
151 static base::LazyDynamicInstance<CodeEntry, GCEntryCreateTrait>::type
152 kGCEntry;
153 static base::LazyDynamicInstance<CodeEntry, UnresolvedEntryCreateTrait>::type
154 kUnresolvedEntry;
155
118 class TagField : public BitField<Logger::LogEventsAndTags, 0, 8> {}; 156 class TagField : public BitField<Logger::LogEventsAndTags, 0, 8> {};
119 class BuiltinIdField : public BitField<Builtins::Name, 8, 24> {}; 157 class BuiltinIdField : public BitField<Builtins::Name, 8, 24> {};
120 158
121 uint32_t bit_field_; 159 uint32_t bit_field_;
122 const char* name_prefix_; 160 const char* name_prefix_;
123 const char* name_; 161 const char* name_;
124 const char* resource_name_; 162 const char* resource_name_;
125 int line_number_; 163 int line_number_;
126 int column_number_; 164 int column_number_;
127 int script_id_; 165 int script_id_;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 331
294 class CpuProfilesCollection { 332 class CpuProfilesCollection {
295 public: 333 public:
296 explicit CpuProfilesCollection(Isolate* isolate); 334 explicit CpuProfilesCollection(Isolate* isolate);
297 ~CpuProfilesCollection(); 335 ~CpuProfilesCollection();
298 336
299 void set_cpu_profiler(CpuProfiler* profiler) { profiler_ = profiler; } 337 void set_cpu_profiler(CpuProfiler* profiler) { profiler_ = profiler; }
300 bool StartProfiling(const char* title, bool record_samples); 338 bool StartProfiling(const char* title, bool record_samples);
301 CpuProfile* StopProfiling(const char* title); 339 CpuProfile* StopProfiling(const char* title);
302 List<CpuProfile*>* profiles() { return &finished_profiles_; } 340 List<CpuProfile*>* profiles() { return &finished_profiles_; }
303 const char* GetName(Name* name) { 341 const char* GetName(Name* name) { return resource_names_.GetName(name); }
304 return function_and_resource_names_.GetName(name);
305 }
306 const char* GetName(int args_count) {
307 return function_and_resource_names_.GetName(args_count);
308 }
309 const char* GetFunctionName(Name* name) {
310 return function_and_resource_names_.GetFunctionName(name);
311 }
312 const char* GetFunctionName(const char* name) {
313 return function_and_resource_names_.GetFunctionName(name);
314 }
315 bool IsLastProfile(const char* title); 342 bool IsLastProfile(const char* title);
316 void RemoveProfile(CpuProfile* profile); 343 void RemoveProfile(CpuProfile* profile);
317 344
318 CodeEntry* NewCodeEntry(
319 CodeEventListener::LogEventsAndTags tag, const char* name,
320 const char* name_prefix = CodeEntry::kEmptyNamePrefix,
321 const char* resource_name = CodeEntry::kEmptyResourceName,
322 int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
323 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
324 JITLineInfoTable* line_info = NULL, Address instruction_start = NULL);
325
326 // Called from profile generator thread. 345 // Called from profile generator thread.
327 void AddPathToCurrentProfiles(base::TimeTicks timestamp, 346 void AddPathToCurrentProfiles(base::TimeTicks timestamp,
328 const std::vector<CodeEntry*>& path, 347 const std::vector<CodeEntry*>& path,
329 int src_line, bool update_stats); 348 int src_line, bool update_stats);
330 349
331 // Limits the number of profiles that can be simultaneously collected. 350 // Limits the number of profiles that can be simultaneously collected.
332 static const int kMaxSimultaneousProfiles = 100; 351 static const int kMaxSimultaneousProfiles = 100;
333 352
334 private: 353 private:
335 StringsStorage function_and_resource_names_; 354 StringsStorage resource_names_;
336 List<CodeEntry*> code_entries_;
337 List<CpuProfile*> finished_profiles_; 355 List<CpuProfile*> finished_profiles_;
338 CpuProfiler* profiler_; 356 CpuProfiler* profiler_;
339 357
340 // Accessed by VM thread and profile generator thread. 358 // Accessed by VM thread and profile generator thread.
341 List<CpuProfile*> current_profiles_; 359 List<CpuProfile*> current_profiles_;
342 base::Semaphore current_profiles_semaphore_; 360 base::Semaphore current_profiles_semaphore_;
343 361
344 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection); 362 DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection);
345 }; 363 };
346 364
347 365
348 class ProfileGenerator { 366 class ProfileGenerator {
349 public: 367 public:
350 explicit ProfileGenerator(CpuProfilesCollection* profiles); 368 explicit ProfileGenerator(CpuProfilesCollection* profiles);
351 369
352 void RecordTickSample(const TickSample& sample); 370 void RecordTickSample(const TickSample& sample);
353 371
354 CodeMap* code_map() { return &code_map_; } 372 CodeMap* code_map() { return &code_map_; }
355 373
356 static const char* const kProgramEntryName;
357 static const char* const kIdleEntryName;
358 static const char* const kGarbageCollectorEntryName;
359 // Used to represent frames for which we have no reliable way to
360 // detect function.
361 static const char* const kUnresolvedFunctionName;
362
363 private: 374 private:
364 CodeEntry* EntryForVMState(StateTag tag); 375 CodeEntry* EntryForVMState(StateTag tag);
365 376
366 CpuProfilesCollection* profiles_; 377 CpuProfilesCollection* profiles_;
367 CodeMap code_map_; 378 CodeMap code_map_;
368 CodeEntry* program_entry_;
369 CodeEntry* idle_entry_;
370 CodeEntry* gc_entry_;
371 CodeEntry* unresolved_entry_;
372 379
373 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); 380 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
374 }; 381 };
375 382
376 383
377 } // namespace internal 384 } // namespace internal
378 } // namespace v8 385 } // namespace v8
379 386
380 #endif // V8_PROFILER_PROFILE_GENERATOR_H_ 387 #endif // V8_PROFILER_PROFILE_GENERATOR_H_
OLDNEW
« no previous file with comments | « src/profiler/cpu-profiler.cc ('k') | src/profiler/profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698