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

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

Issue 1697903002: Sampling heap profiler data structure changes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Store profile_root_ by value 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 FunctionInfo { 51 class AllocationNode;
52
53 struct Sample {
52 public: 54 public:
53 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); 55 Sample(size_t size_, AllocationNode* owner_, Local<Value> local_,
54 explicit FunctionInfo(const char* name) 56 SamplingHeapProfiler* profiler_)
55 : name_(name), 57 : size(size_),
56 script_name_(""), 58 owner(owner_),
57 script_id_(v8::UnboundScript::kNoScriptId), 59 global(Global<Value>(
58 start_position_(0) {} 60 reinterpret_cast<v8::Isolate*>(profiler_->isolate_), local_)),
59 61 profiler(profiler_) {}
60 const char* get_name() const { return name_; } 62 size_t size;
ofrobots 2016/02/17 22:34:49 const size_t
mattloring 2016/02/17 23:11:00 Done.
61 const char* get_script_name() const { return script_name_; } 63 AllocationNode* owner;
ofrobots 2016/02/17 22:34:49 AllocationNode* const owner;
mattloring 2016/02/17 23:11:00 Done.
62 int get_script_id() const { return script_id_; } 64 Global<Value> global;
63 int get_start_position() const { return start_position_; } 65 SamplingHeapProfiler* profiler;
ofrobots 2016/02/17 22:34:49 SamplingHeapProfiler* const profiler;
mattloring 2016/02/17 23:11:00 Done.
64 66
65 private: 67 private:
66 const char* const name_; 68 DISALLOW_COPY_AND_ASSIGN(Sample);
67 const char* script_name_;
68 int script_id_;
69 const int start_position_;
70 }; 69 };
71 70
72 class SampledAllocation { 71 class AllocationNode {
73 public: 72 public:
74 SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler, 73 AllocationNode(const char* const name, int script_id,
75 Isolate* isolate, Local<Value> local, size_t size, 74 const int start_position)
76 int max_frames); 75 : script_id_(script_id),
77 ~SampledAllocation() { 76 script_position_(start_position),
78 for (auto info : stack_) { 77 name_(name) {}
79 delete info; 78 ~AllocationNode() {
79 for (auto child : children_) {
80 delete child;
80 } 81 }
81 global_.Reset(); // drop the reference.
ofrobots 2016/02/17 22:34:49 You missed this. You should drop the reference in
mattloring 2016/02/17 23:11:00 Done.
82 } 82 }
83 size_t get_size() const { return size_; }
84 const std::vector<FunctionInfo*>& get_stack() const { return stack_; }
85 83
86 private: 84 private:
87 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); 85 std::map<size_t, unsigned int> allocations_;
86 std::vector<AllocationNode*> children_;
87 int script_id_;
ofrobots 2016/02/17 22:34:49 const int script_id;
mattloring 2016/02/17 23:11:00 Done.
88 int script_position_;
ofrobots 2016/02/17 22:34:49 const int start_position_;
mattloring 2016/02/17 23:11:00 Done.
89 const char* name_;
ofrobots 2016/02/17 22:34:49 const char* const name_;
mattloring 2016/02/17 23:11:00 Done.
88 90
89 SamplingHeapProfiler* const sampling_heap_profiler_; 91 friend class SamplingHeapProfiler;
90 Global<Value> global_;
91 std::vector<FunctionInfo*> stack_;
92 const size_t size_;
93 92
94 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); 93 DISALLOW_COPY_AND_ASSIGN(AllocationNode);
95 }; 94 };
96 95
97 private: 96 private:
98 Heap* heap() const { return heap_; } 97 Heap* heap() const { return heap_; }
99 98
100 void SampleObject(Address soon_object, size_t size); 99 void SampleObject(Address soon_object, size_t size);
101 100
101 static void OnWeakCallback(const WeakCallbackInfo<Sample>& data);
102
102 // Methods that construct v8::AllocationProfile. 103 // Methods that construct v8::AllocationProfile.
103 v8::AllocationProfile::Node* AddStack( 104
104 AllocationProfile* profile, const std::map<int, Script*>& scripts, 105 // Translates the provided AllocationNode *node* returning an equivalent
105 const std::vector<FunctionInfo*>& stack); 106 // AllocationProfile::Node. The newly created AllocationProfile::Node is added
106 v8::AllocationProfile::Node* FindOrAddChildNode( 107 // to the provided AllocationProfile *profile*. Line numbers, column numbers,
107 AllocationProfile* profile, const std::map<int, Script*>& scripts, 108 // and script names are resolved using *scripts* which maps all currently
108 v8::AllocationProfile::Node* parent, FunctionInfo* function_info); 109 // loaded scripts keyed by their script id.
109 v8::AllocationProfile::Node* AllocateNode( 110 v8::AllocationProfile::Node* TranslateAllocationNode(
110 AllocationProfile* profile, const std::map<int, Script*>& scripts, 111 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node,
111 FunctionInfo* function_info); 112 const std::map<int, Script*>& scripts);
113 AllocationNode* AddStack();
114 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name,
115 int script_id, int start_position);
112 116
113 Isolate* const isolate_; 117 Isolate* const isolate_;
114 Heap* const heap_; 118 Heap* const heap_;
115 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; 119 base::SmartPointer<SamplingAllocationObserver> new_space_observer_;
116 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; 120 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_;
117 StringsStorage* const names_; 121 StringsStorage* const names_;
118 std::set<SampledAllocation*> samples_; 122 AllocationNode profile_root_;
123 std::set<Sample*> samples_;
119 const int stack_depth_; 124 const int stack_depth_;
120 125
121 friend class SamplingAllocationObserver; 126 friend class SamplingAllocationObserver;
122 }; 127 };
123 128
124 class SamplingAllocationObserver : public AllocationObserver { 129 class SamplingAllocationObserver : public AllocationObserver {
125 public: 130 public:
126 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate, 131 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate,
127 SamplingHeapProfiler* profiler, 132 SamplingHeapProfiler* profiler,
128 base::RandomNumberGenerator* random) 133 base::RandomNumberGenerator* random)
(...skipping 19 matching lines...) Expand all
148 SamplingHeapProfiler* const profiler_; 153 SamplingHeapProfiler* const profiler_;
149 Heap* const heap_; 154 Heap* const heap_;
150 base::RandomNumberGenerator* const random_; 155 base::RandomNumberGenerator* const random_;
151 uint64_t const rate_; 156 uint64_t const rate_;
152 }; 157 };
153 158
154 } // namespace internal 159 } // namespace internal
155 } // namespace v8 160 } // namespace v8
156 161
157 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ 162 #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