Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/profiler/sampling-heap-profiler.h

Issue 1708363002: Revert of Sampling heap profiler data structure changes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/profiler/sampling-heap-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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_SAMPLING_HEAP_PROFILER_H_ 5 #ifndef V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ 6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 30 matching lines...) Expand all
41 class SamplingHeapProfiler { 41 class SamplingHeapProfiler {
42 public: 42 public:
43 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, 43 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate,
44 int stack_depth); 44 int stack_depth);
45 ~SamplingHeapProfiler(); 45 ~SamplingHeapProfiler();
46 46
47 v8::AllocationProfile* GetAllocationProfile(); 47 v8::AllocationProfile* GetAllocationProfile();
48 48
49 StringsStorage* names() const { return names_; } 49 StringsStorage* names() const { return names_; }
50 50
51 class AllocationNode; 51 class FunctionInfo {
52 public:
53 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names);
54 explicit FunctionInfo(const char* name)
55 : name_(name),
56 script_name_(""),
57 script_id_(v8::UnboundScript::kNoScriptId),
58 start_position_(0) {}
52 59
53 struct Sample { 60 const char* get_name() const { return name_; }
54 public: 61 const char* get_script_name() const { return script_name_; }
55 Sample(size_t size_, AllocationNode* owner_, Local<Value> local_, 62 int get_script_id() const { return script_id_; }
56 SamplingHeapProfiler* profiler_) 63 int get_start_position() const { return start_position_; }
57 : size(size_),
58 owner(owner_),
59 global(Global<Value>(
60 reinterpret_cast<v8::Isolate*>(profiler_->isolate_), local_)),
61 profiler(profiler_) {}
62 ~Sample() { global.Reset(); }
63 const size_t size;
64 AllocationNode* const owner;
65 Global<Value> global;
66 SamplingHeapProfiler* const profiler;
67 64
68 private: 65 private:
69 DISALLOW_COPY_AND_ASSIGN(Sample); 66 const char* const name_;
67 const char* script_name_;
68 int script_id_;
69 const int start_position_;
70 }; 70 };
71 71
72 class AllocationNode { 72 class SampledAllocation {
73 public: 73 public:
74 AllocationNode(const char* const name, int script_id, 74 SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler,
75 const int start_position) 75 Isolate* isolate, Local<Value> local, size_t size,
76 : script_id_(script_id), 76 int max_frames);
77 script_position_(start_position), 77 ~SampledAllocation() {
78 name_(name) {} 78 for (auto info : stack_) {
79 ~AllocationNode() { 79 delete info;
80 for (auto child : children_) {
81 delete child;
82 } 80 }
81 global_.Reset(); // drop the reference.
83 } 82 }
83 size_t get_size() const { return size_; }
84 const std::vector<FunctionInfo*>& get_stack() const { return stack_; }
84 85
85 private: 86 private:
86 std::map<size_t, unsigned int> allocations_; 87 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data);
87 std::vector<AllocationNode*> children_;
88 const int script_id_;
89 const int script_position_;
90 const char* const name_;
91 88
92 friend class SamplingHeapProfiler; 89 SamplingHeapProfiler* const sampling_heap_profiler_;
90 Global<Value> global_;
91 std::vector<FunctionInfo*> stack_;
92 const size_t size_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(AllocationNode); 94 DISALLOW_COPY_AND_ASSIGN(SampledAllocation);
95 }; 95 };
96 96
97 private: 97 private:
98 Heap* heap() const { return heap_; } 98 Heap* heap() const { return heap_; }
99 99
100 void SampleObject(Address soon_object, size_t size); 100 void SampleObject(Address soon_object, size_t size);
101 101
102 static void OnWeakCallback(const WeakCallbackInfo<Sample>& data);
103
104 // Methods that construct v8::AllocationProfile. 102 // Methods that construct v8::AllocationProfile.
105 103 v8::AllocationProfile::Node* AddStack(
106 // Translates the provided AllocationNode *node* returning an equivalent 104 AllocationProfile* profile, const std::map<int, Script*>& scripts,
107 // AllocationProfile::Node. The newly created AllocationProfile::Node is added 105 const std::vector<FunctionInfo*>& stack);
108 // to the provided AllocationProfile *profile*. Line numbers, column numbers, 106 v8::AllocationProfile::Node* FindOrAddChildNode(
109 // and script names are resolved using *scripts* which maps all currently 107 AllocationProfile* profile, const std::map<int, Script*>& scripts,
110 // loaded scripts keyed by their script id. 108 v8::AllocationProfile::Node* parent, FunctionInfo* function_info);
111 v8::AllocationProfile::Node* TranslateAllocationNode( 109 v8::AllocationProfile::Node* AllocateNode(
112 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, 110 AllocationProfile* profile, const std::map<int, Script*>& scripts,
113 const std::map<int, Script*>& scripts); 111 FunctionInfo* function_info);
114 AllocationNode* AddStack();
115 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name,
116 int script_id, int start_position);
117 112
118 Isolate* const isolate_; 113 Isolate* const isolate_;
119 Heap* const heap_; 114 Heap* const heap_;
120 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; 115 base::SmartPointer<SamplingAllocationObserver> new_space_observer_;
121 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; 116 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_;
122 StringsStorage* const names_; 117 StringsStorage* const names_;
123 AllocationNode profile_root_; 118 std::set<SampledAllocation*> samples_;
124 std::set<Sample*> samples_;
125 const int stack_depth_; 119 const int stack_depth_;
126 120
127 friend class SamplingAllocationObserver; 121 friend class SamplingAllocationObserver;
128 }; 122 };
129 123
130 class SamplingAllocationObserver : public AllocationObserver { 124 class SamplingAllocationObserver : public AllocationObserver {
131 public: 125 public:
132 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate, 126 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate,
133 SamplingHeapProfiler* profiler, 127 SamplingHeapProfiler* profiler,
134 base::RandomNumberGenerator* random) 128 base::RandomNumberGenerator* random)
(...skipping 19 matching lines...) Expand all
154 SamplingHeapProfiler* const profiler_; 148 SamplingHeapProfiler* const profiler_;
155 Heap* const heap_; 149 Heap* const heap_;
156 base::RandomNumberGenerator* const random_; 150 base::RandomNumberGenerator* const random_;
157 uint64_t const rate_; 151 uint64_t const rate_;
158 }; 152 };
159 153
160 } // namespace internal 154 } // namespace internal
161 } // namespace v8 155 } // namespace v8
162 156
163 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ 157 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
OLDNEW
« no previous file with comments | « no previous file | src/profiler/sampling-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698