Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_SAMPLING_HEAP_PROFILER_H_ | |
| 6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <map> | |
| 10 #include <set> | |
| 11 #include "src/base/utils/random-number-generator.h" | |
|
alph
2016/01/20 23:13:01
You can forward ref instead.
ofrobots
2016/01/21 03:03:28
Done.
| |
| 12 #include "src/heap/heap.h" | |
| 13 #include "src/profiler/allocation-tracker.h" | |
|
alph
2016/01/20 23:13:01
Is it used?
ofrobots
2016/01/21 03:03:28
Done.
| |
| 14 | |
| 15 namespace v8 { | |
| 16 namespace internal { | |
| 17 | |
| 18 class AllocationProfile : public v8::AllocationProfile { | |
| 19 public: | |
| 20 AllocationProfile() : nodes_() {} | |
| 21 | |
| 22 Node* GetRootNode() override { | |
| 23 return nodes_.size() == 0 ? nullptr : &nodes_.front(); | |
| 24 } | |
| 25 | |
| 26 std::deque<Node>& nodes() { return nodes_; } | |
| 27 | |
| 28 private: | |
| 29 std::deque<Node> nodes_; | |
| 30 | |
| 31 DISALLOW_COPY_AND_ASSIGN(AllocationProfile); | |
| 32 }; | |
| 33 | |
| 34 class SamplingHeapProfiler : public InlineAllocationObserver { | |
| 35 public: | |
| 36 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, | |
| 37 int stack_depth); | |
| 38 ~SamplingHeapProfiler(); | |
| 39 | |
| 40 v8::AllocationProfile* GetAllocationProfile(); | |
| 41 | |
| 42 void Step(int bytes_allocated, Address soon_object, size_t size) override; | |
| 43 intptr_t GetNextStepSize() override { | |
| 44 return GetNextSampleInterval(random_, rate_); | |
| 45 } | |
| 46 | |
| 47 StringsStorage* names() const { return names_; } | |
| 48 | |
| 49 class FunctionInfo { | |
| 50 public: | |
| 51 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); | |
| 52 FunctionInfo(const char* name, const char* script_name, int script_id, | |
| 53 int start_position) | |
| 54 : name_(name), | |
| 55 script_name_(script_name), | |
| 56 script_id_(script_id), | |
| 57 start_position_(start_position) {} | |
| 58 | |
| 59 const char* get_name() const { return name_; } | |
| 60 const char* get_script_name() const { return script_name_; } | |
| 61 int get_script_id() const { return script_id_; } | |
| 62 int get_start_position() const { return start_position_; } | |
| 63 | |
| 64 private: | |
| 65 const char* const name_; | |
| 66 const char* script_name_; | |
| 67 int script_id_; | |
| 68 int start_position_; | |
| 69 }; | |
| 70 | |
| 71 class SampledAllocation { | |
| 72 public: | |
| 73 SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler, | |
| 74 Isolate* isolate, Local<Value> local, size_t size, | |
| 75 int max_frames); | |
| 76 ~SampledAllocation() { | |
| 77 for (auto info : stack_) { | |
| 78 delete info; | |
| 79 } | |
| 80 global_.Reset(); // drop the reference. | |
| 81 } | |
| 82 size_t get_size() const { return size_; } | |
| 83 const std::vector<FunctionInfo*>& get_stack() const { return stack_; } | |
| 84 | |
| 85 private: | |
| 86 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); | |
| 87 | |
| 88 SamplingHeapProfiler* const sampling_heap_profiler_; | |
| 89 Global<Value> global_; | |
| 90 std::vector<FunctionInfo*> stack_; | |
| 91 const size_t size_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); | |
| 94 }; | |
| 95 | |
| 96 private: | |
| 97 using Node = v8::AllocationProfile::Node; | |
| 98 | |
| 99 Heap* heap() const { return heap_; } | |
| 100 | |
| 101 void SampleObject(Address soon_object, size_t size); | |
| 102 | |
| 103 static intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, | |
| 104 uint64_t rate); | |
| 105 | |
| 106 // Methods that construct v8::AllocationProfile. | |
| 107 Node* AddStack(AllocationProfile& profile, | |
| 108 const std::map<int, Script*>& scripts, | |
| 109 const std::vector<FunctionInfo*>& stack); | |
| 110 Node* FindOrAddChildNode(AllocationProfile& profile, | |
| 111 const std::map<int, Script*>& scripts, Node* parent, | |
| 112 FunctionInfo* function_info); | |
| 113 Node* AllocateNode(AllocationProfile& profile, | |
| 114 const std::map<int, Script*>& scripts, | |
| 115 FunctionInfo* function_info); | |
| 116 | |
| 117 Isolate* const isolate_; | |
| 118 Heap* const heap_; | |
| 119 base::RandomNumberGenerator* const random_; | |
| 120 StringsStorage* const names_; | |
| 121 std::set<SampledAllocation*> samples_; | |
| 122 const uint64_t rate_; | |
| 123 const int stack_depth_; | |
| 124 }; | |
| 125 | |
| 126 | |
| 127 } // namespace internal | |
| 128 } // namespace v8 | |
| 129 | |
| 130 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | |
| OLD | NEW |