Home | History | Annotate | Download | only in profiler
      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 "src/code-events.h"
     12 #include "src/profiler/profile-generator.h"
     13 
     14 namespace v8 {
     15 namespace internal {
     16 
     17 class CodeEventsContainer;
     18 class CodeDeoptEventRecord;
     19 
     20 class CodeEventObserver {
     21  public:
     22   virtual void CodeEventHandler(const CodeEventsContainer& evt_rec) = 0;
     23   virtual ~CodeEventObserver() = default;
     24 };
     25 
     26 class ProfilerListener : public CodeEventListener {
     27  public:
     28   ProfilerListener(Isolate*, CodeEventObserver*);
     29   ~ProfilerListener() override;
     30 
     31   void CallbackEvent(Name* name, Address entry_point) override;
     32   void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
     33                        AbstractCode* code, const char* comment) override;
     34   void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
     35                        AbstractCode* code, Name* name) override;
     36   void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
     37                        AbstractCode* code, SharedFunctionInfo* shared,
     38                        Name* script_name) override;
     39   void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
     40                        AbstractCode* code, SharedFunctionInfo* shared,
     41                        Name* script_name, int line, int column) override;
     42   void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
     43                        const wasm::WasmCode* code,
     44                        wasm::WasmName name) override;
     45 
     46   void CodeMovingGCEvent() override {}
     47   void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
     48   void CodeDisableOptEvent(AbstractCode* code,
     49                            SharedFunctionInfo* shared) override;
     50   void CodeDeoptEvent(Code* code, DeoptimizeKind kind, Address pc,
     51                       int fp_to_sp_delta) override;
     52   void GetterCallbackEvent(Name* name, Address entry_point) override;
     53   void RegExpCodeCreateEvent(AbstractCode* code, String* source) override;
     54   void SetterCallbackEvent(Name* name, Address entry_point) override;
     55   void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
     56 
     57   CodeEntry* NewCodeEntry(
     58       CodeEventListener::LogEventsAndTags tag, const char* name,
     59       const char* resource_name = CodeEntry::kEmptyResourceName,
     60       int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
     61       int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
     62       std::unique_ptr<SourcePositionTable> line_info = nullptr,
     63       Address instruction_start = kNullAddress);
     64 
     65   const char* GetName(Name* name) {
     66     return function_and_resource_names_.GetName(name);
     67   }
     68   const char* GetName(int args_count) {
     69     return function_and_resource_names_.GetName(args_count);
     70   }
     71   const char* GetName(const char* name) {
     72     return function_and_resource_names_.GetCopy(name);
     73   }
     74   const char* GetConsName(const char* prefix, Name* name) {
     75     return function_and_resource_names_.GetConsName(prefix, name);
     76   }
     77 
     78  private:
     79   void RecordInliningInfo(CodeEntry* entry, AbstractCode* abstract_code);
     80   void AttachDeoptInlinedFrames(Code* code, CodeDeoptEventRecord* rec);
     81   Name* InferScriptName(Name* name, SharedFunctionInfo* info);
     82   V8_INLINE void DispatchCodeEvent(const CodeEventsContainer& evt_rec) {
     83     observer_->CodeEventHandler(evt_rec);
     84   }
     85 
     86   Isolate* isolate_;
     87   CodeEventObserver* observer_;
     88   StringsStorage function_and_resource_names_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(ProfilerListener);
     91 };
     92 
     93 }  // namespace internal
     94 }  // namespace v8
     95 
     96 #endif  // V8_PROFILER_PROFILER_LISTENER_H_
     97