| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_CPU_PROFILER_H_ | 5 #ifndef V8_PROFILER_CPU_PROFILER_H_ |
| 6 #define V8_PROFILER_CPU_PROFILER_H_ | 6 #define V8_PROFILER_CPU_PROFILER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| 11 #include "src/base/platform/time.h" | 11 #include "src/base/platform/time.h" |
| 12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
| 13 #include "src/libsampler/v8-sampler.h" | 13 #include "src/libsampler/v8-sampler.h" |
| 14 #include "src/locked-queue.h" | 14 #include "src/locked-queue.h" |
| 15 #include "src/profiler/circular-queue.h" | 15 #include "src/profiler/circular-queue.h" |
| 16 #include "src/profiler/profiler-listener.h" |
| 16 #include "src/profiler/tick-sample.h" | 17 #include "src/profiler/tick-sample.h" |
| 17 | 18 |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 namespace internal { | 20 namespace internal { |
| 20 | 21 |
| 21 // Forward declarations. | 22 // Forward declarations. |
| 22 class CodeEntry; | 23 class CodeEntry; |
| 23 class CodeMap; | 24 class CodeMap; |
| 24 class CpuProfile; | 25 class CpuProfile; |
| 25 class CpuProfilesCollection; | 26 class CpuProfilesCollection; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 76 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 | 79 |
| 79 class CodeDeoptEventRecord : public CodeEventRecord { | 80 class CodeDeoptEventRecord : public CodeEventRecord { |
| 80 public: | 81 public: |
| 81 Address start; | 82 Address start; |
| 82 const char* deopt_reason; | 83 const char* deopt_reason; |
| 83 SourcePosition position; | 84 SourcePosition position; |
| 84 int deopt_id; | 85 int deopt_id; |
| 86 void* pc; |
| 87 int fp_to_sp_delta; |
| 85 | 88 |
| 86 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 89 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 | 92 |
| 90 class ReportBuiltinEventRecord : public CodeEventRecord { | 93 class ReportBuiltinEventRecord : public CodeEventRecord { |
| 91 public: | 94 public: |
| 92 Address start; | 95 Address start; |
| 93 Builtins::Name builtin_id; | 96 Builtins::Name builtin_id; |
| 94 | 97 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 185 |
| 183 #define PROFILE(IsolateGetter, Call) \ | 186 #define PROFILE(IsolateGetter, Call) \ |
| 184 do { \ | 187 do { \ |
| 185 Isolate* the_isolate = (IsolateGetter); \ | 188 Isolate* the_isolate = (IsolateGetter); \ |
| 186 v8::internal::Logger* logger = the_isolate->logger(); \ | 189 v8::internal::Logger* logger = the_isolate->logger(); \ |
| 187 if (logger->is_logging_code_events() || the_isolate->is_profiling()) { \ | 190 if (logger->is_logging_code_events() || the_isolate->is_profiling()) { \ |
| 188 logger->Call; \ | 191 logger->Call; \ |
| 189 } \ | 192 } \ |
| 190 } while (false) | 193 } while (false) |
| 191 | 194 |
| 192 class CpuProfiler : public CodeEventListener { | 195 class CpuProfiler : public CodeEventObserver { |
| 193 public: | 196 public: |
| 194 explicit CpuProfiler(Isolate* isolate); | 197 explicit CpuProfiler(Isolate* isolate); |
| 195 | 198 |
| 196 CpuProfiler(Isolate* isolate, | 199 CpuProfiler(Isolate* isolate, |
| 197 CpuProfilesCollection* test_collection, | 200 CpuProfilesCollection* test_collection, |
| 198 ProfileGenerator* test_generator, | 201 ProfileGenerator* test_generator, |
| 199 ProfilerEventsProcessor* test_processor); | 202 ProfilerEventsProcessor* test_processor); |
| 200 | 203 |
| 201 ~CpuProfiler() override; | 204 ~CpuProfiler() override; |
| 202 | 205 |
| 203 void set_sampling_interval(base::TimeDelta value); | 206 void set_sampling_interval(base::TimeDelta value); |
| 204 void CollectSample(); | 207 void CollectSample(); |
| 205 void StartProfiling(const char* title, bool record_samples = false); | 208 void StartProfiling(const char* title, bool record_samples = false); |
| 206 void StartProfiling(String* title, bool record_samples); | 209 void StartProfiling(String* title, bool record_samples); |
| 207 CpuProfile* StopProfiling(const char* title); | 210 CpuProfile* StopProfiling(const char* title); |
| 208 CpuProfile* StopProfiling(String* title); | 211 CpuProfile* StopProfiling(String* title); |
| 209 int GetProfilesCount(); | 212 int GetProfilesCount(); |
| 210 CpuProfile* GetProfile(int index); | 213 CpuProfile* GetProfile(int index); |
| 211 void DeleteAllProfiles(); | 214 void DeleteAllProfiles(); |
| 212 void DeleteProfile(CpuProfile* profile); | 215 void DeleteProfile(CpuProfile* profile); |
| 213 | 216 |
| 217 void CodeEventHandler(const CodeEventsContainer& evt_rec) override; |
| 218 |
| 214 // Invoked from stack sampler (thread or signal handler.) | 219 // Invoked from stack sampler (thread or signal handler.) |
| 215 inline TickSample* StartTickSample(); | 220 inline TickSample* StartTickSample(); |
| 216 inline void FinishTickSample(); | 221 inline void FinishTickSample(); |
| 217 | 222 |
| 218 // Must be called via PROFILE macro, otherwise will crash when | |
| 219 // profiling is not enabled. | |
| 220 void CallbackEvent(Name* name, Address entry_point) override; | |
| 221 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, | |
| 222 const char* comment) override; | |
| 223 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, | |
| 224 Name* name) override; | |
| 225 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, | |
| 226 SharedFunctionInfo* shared, Name* script_name) override; | |
| 227 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, | |
| 228 SharedFunctionInfo* shared, Name* script_name, int line, | |
| 229 int column) override; | |
| 230 void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, | |
| 231 int args_count) override; | |
| 232 void CodeMovingGCEvent() override {} | |
| 233 void CodeMoveEvent(AbstractCode* from, Address to) override; | |
| 234 void CodeDisableOptEvent(AbstractCode* code, | |
| 235 SharedFunctionInfo* shared) override; | |
| 236 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta); | |
| 237 void GetterCallbackEvent(Name* name, Address entry_point) override; | |
| 238 void RegExpCodeCreateEvent(AbstractCode* code, String* source) override; | |
| 239 void SetterCallbackEvent(Name* name, Address entry_point) override; | |
| 240 void SharedFunctionInfoMoveEvent(Address from, Address to) override {} | |
| 241 | |
| 242 bool is_profiling() const { return is_profiling_; } | 223 bool is_profiling() const { return is_profiling_; } |
| 243 | 224 |
| 244 ProfileGenerator* generator() const { return generator_; } | 225 ProfileGenerator* generator() const { return generator_; } |
| 245 ProfilerEventsProcessor* processor() const { return processor_; } | 226 ProfilerEventsProcessor* processor() const { return processor_; } |
| 246 Isolate* isolate() const { return isolate_; } | 227 Isolate* isolate() const { return isolate_; } |
| 247 | 228 |
| 248 private: | 229 private: |
| 249 void StartProcessorIfNotStarted(); | 230 void StartProcessorIfNotStarted(); |
| 250 void StopProcessorIfLastProfile(const char* title); | 231 void StopProcessorIfLastProfile(const char* title); |
| 251 void StopProcessor(); | 232 void StopProcessor(); |
| 252 void ResetProfiles(); | 233 void ResetProfiles(); |
| 253 void LogBuiltins(); | 234 void LogBuiltins(); |
| 254 void RecordInliningInfo(CodeEntry* entry, AbstractCode* abstract_code); | |
| 255 void RecordDeoptInlinedFrames(CodeEntry* entry, AbstractCode* abstract_code); | |
| 256 Name* InferScriptName(Name* name, SharedFunctionInfo* info); | |
| 257 | 235 |
| 258 Isolate* isolate_; | 236 Isolate* isolate_; |
| 259 base::TimeDelta sampling_interval_; | 237 base::TimeDelta sampling_interval_; |
| 260 CpuProfilesCollection* profiles_; | 238 CpuProfilesCollection* profiles_; |
| 261 ProfileGenerator* generator_; | 239 ProfileGenerator* generator_; |
| 262 ProfilerEventsProcessor* processor_; | 240 ProfilerEventsProcessor* processor_; |
| 263 bool saved_is_logging_; | 241 bool saved_is_logging_; |
| 264 bool is_profiling_; | 242 bool is_profiling_; |
| 265 | 243 |
| 266 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 244 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 267 }; | 245 }; |
| 268 | 246 |
| 269 } // namespace internal | 247 } // namespace internal |
| 270 } // namespace v8 | 248 } // namespace v8 |
| 271 | 249 |
| 272 | 250 |
| 273 #endif // V8_PROFILER_CPU_PROFILER_H_ | 251 #endif // V8_PROFILER_CPU_PROFILER_H_ |
| OLD | NEW |