1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_PROFILER_PROFILER_LISTENER_H_ 6 #define V8_PROFILER_PROFILER_LISTENER_H_ 7 8 #include <memory> 9 #include <vector> 10 11 #include "include/v8-profiler.h" 12 #include "src/logging/code-events.h" 13 #include "src/profiler/profile-generator.h" 14 15 namespace v8 { 16 namespace internal { 17 18 class CodeEventsContainer; 19 class CodeDeoptEventRecord; 20 21 class CodeEventObserver { 22 public: 23 virtual void CodeEventHandler(const CodeEventsContainer& evt_rec) = 0; 24 virtual ~CodeEventObserver() = default; 25 }; 26 27 class V8_EXPORT_PRIVATE ProfilerListener : public CodeEventListener { 28 public: 29 ProfilerListener(Isolate*, CodeEventObserver*, 30 CpuProfilingNamingMode mode = kDebugNaming); 31 ~ProfilerListener() override; 32 33 void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code, 34 const char* name) override; 35 void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code, 36 Handle<Name> name) override; 37 void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code, 38 Handle<SharedFunctionInfo> shared, 39 Handle<Name> script_name) override; 40 void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code, 41 Handle<SharedFunctionInfo> shared, 42 Handle<Name> script_name, int line, int column) override; 43 void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code, 44 wasm::WasmName name) override; 45 46 void CallbackEvent(Handle<Name> name, Address entry_point) override; 47 void GetterCallbackEvent(Handle<Name> name, Address entry_point) override; 48 void SetterCallbackEvent(Handle<Name> name, Address entry_point) override; 49 void RegExpCodeCreateEvent(Handle<AbstractCode> code, 50 Handle<String> source) override; 51 void CodeMoveEvent(AbstractCode from, AbstractCode to) override; SharedFunctionInfoMoveEvent(Address from,Address to)52 void SharedFunctionInfoMoveEvent(Address from, Address to) override {} CodeMovingGCEvent()53 void CodeMovingGCEvent() override {} 54 void CodeDisableOptEvent(Handle<AbstractCode> code, 55 Handle<SharedFunctionInfo> shared) override; 56 void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc, 57 int fp_to_sp_delta, bool reuse_code) override; CodeDependencyChangeEvent(Handle<Code> code,Handle<SharedFunctionInfo> sfi,const char * reason)58 void CodeDependencyChangeEvent(Handle<Code> code, 59 Handle<SharedFunctionInfo> sfi, 60 const char* reason) override {} 61 GetName(Name name)62 const char* GetName(Name name) { 63 return function_and_resource_names_.GetName(name); 64 } GetName(int args_count)65 const char* GetName(int args_count) { 66 return function_and_resource_names_.GetName(args_count); 67 } GetName(const char * name)68 const char* GetName(const char* name) { 69 return function_and_resource_names_.GetCopy(name); 70 } 71 const char* GetName(Vector<const char> name); GetConsName(const char * prefix,Name name)72 const char* GetConsName(const char* prefix, Name name) { 73 return function_and_resource_names_.GetConsName(prefix, name); 74 } 75 set_observer(CodeEventObserver * observer)76 void set_observer(CodeEventObserver* observer) { observer_ = observer; } 77 78 private: 79 const char* GetFunctionName(SharedFunctionInfo); 80 81 void AttachDeoptInlinedFrames(Handle<Code> code, CodeDeoptEventRecord* rec); 82 Name InferScriptName(Name name, SharedFunctionInfo info); DispatchCodeEvent(const CodeEventsContainer & evt_rec)83 V8_INLINE void DispatchCodeEvent(const CodeEventsContainer& evt_rec) { 84 observer_->CodeEventHandler(evt_rec); 85 } 86 87 Isolate* isolate_; 88 CodeEventObserver* observer_; 89 StringsStorage function_and_resource_names_; 90 const CpuProfilingNamingMode naming_mode_; 91 92 DISALLOW_COPY_AND_ASSIGN(ProfilerListener); 93 }; 94 95 } // namespace internal 96 } // namespace v8 97 98 #endif // V8_PROFILER_PROFILER_LISTENER_H_ 99