profiler-listener.h 3.4 KB
Newer Older
lpy's avatar
lpy committed
1 2 3 4 5 6 7
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_PROFILER_PROFILER_LISTENER_H_
#define V8_PROFILER_PROFILER_LISTENER_H_

8
#include <memory>
lpy's avatar
lpy committed
9 10
#include <vector>

11
#include "include/v8-profiler.h"
12
#include "src/logging/code-events.h"
lpy's avatar
lpy committed
13 14 15 16 17 18
#include "src/profiler/profile-generator.h"

namespace v8 {
namespace internal {

class CodeEventsContainer;
19
class CodeDeoptEventRecord;
lpy's avatar
lpy committed
20 21 22 23

class CodeEventObserver {
 public:
  virtual void CodeEventHandler(const CodeEventsContainer& evt_rec) = 0;
24
  virtual ~CodeEventObserver() = default;
lpy's avatar
lpy committed
25 26
};

27
class V8_EXPORT_PRIVATE ProfilerListener : public CodeEventListener {
lpy's avatar
lpy committed
28
 public:
29 30
  ProfilerListener(Isolate*, CodeEventObserver*,
                   CpuProfilingNamingMode mode = kDebugNaming);
lpy's avatar
lpy committed
31 32
  ~ProfilerListener() override;

33
  void CallbackEvent(Name name, Address entry_point) override;
lpy's avatar
lpy committed
34
  void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
35
                       AbstractCode code, const char* comment) override;
lpy's avatar
lpy committed
36
  void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
37
                       AbstractCode code, Name name) override;
lpy's avatar
lpy committed
38
  void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
39
                       AbstractCode code, SharedFunctionInfo shared,
40
                       Name script_name) override;
lpy's avatar
lpy committed
41
  void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
42
                       AbstractCode code, SharedFunctionInfo shared,
43
                       Name script_name, int line, int column) override;
44
  void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
45 46
                       const wasm::WasmCode* code,
                       wasm::WasmName name) override;
47

lpy's avatar
lpy committed
48
  void CodeMovingGCEvent() override {}
49 50
  void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
  void CodeDisableOptEvent(AbstractCode code,
51
                           SharedFunctionInfo shared) override;
52
  void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
53
                      int fp_to_sp_delta) override;
54 55 56
  void GetterCallbackEvent(Name name, Address entry_point) override;
  void RegExpCodeCreateEvent(AbstractCode code, String source) override;
  void SetterCallbackEvent(Name name, Address entry_point) override;
lpy's avatar
lpy committed
57 58
  void SharedFunctionInfoMoveEvent(Address from, Address to) override {}

59
  const char* GetName(Name name) {
lpy's avatar
lpy committed
60 61 62 63 64
    return function_and_resource_names_.GetName(name);
  }
  const char* GetName(int args_count) {
    return function_and_resource_names_.GetName(args_count);
  }
65 66 67
  const char* GetName(const char* name) {
    return function_and_resource_names_.GetCopy(name);
  }
68
  const char* GetConsName(const char* prefix, Name name) {
69 70
    return function_and_resource_names_.GetConsName(prefix, name);
  }
lpy's avatar
lpy committed
71

72 73
  void set_observer(CodeEventObserver* observer) { observer_ = observer; }

lpy's avatar
lpy committed
74
 private:
75 76
  const char* GetFunctionName(SharedFunctionInfo);

77
  void AttachDeoptInlinedFrames(Code code, CodeDeoptEventRecord* rec);
78
  Name InferScriptName(Name name, SharedFunctionInfo info);
lpy's avatar
lpy committed
79
  V8_INLINE void DispatchCodeEvent(const CodeEventsContainer& evt_rec) {
80
    observer_->CodeEventHandler(evt_rec);
lpy's avatar
lpy committed
81 82
  }

83
  Isolate* isolate_;
84
  CodeEventObserver* observer_;
lpy's avatar
lpy committed
85
  StringsStorage function_and_resource_names_;
86
  const CpuProfilingNamingMode naming_mode_;
lpy's avatar
lpy committed
87 88 89 90 91 92 93 94

  DISALLOW_COPY_AND_ASSIGN(ProfilerListener);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_PROFILER_PROFILER_LISTENER_H_