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

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: More efficient samples_ cleanup 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 ~Sample() { global.Reset(); }
61 const char* get_script_name() const { return script_name_; } 63 const size_t size;
62 int get_script_id() const { return script_id_; } 64 AllocationNode* const owner;
63 int get_start_position() const { return start_position_; } 65 Global<Value> global;
66 SamplingHeapProfiler* const profiler;
64 67
65 private: 68 private:
66 const char* const name_; 69 DISALLOW_COPY_AND_ASSIGN(Sample);
67 const char* script_name_;
68 int script_id_;
69 const int start_position_;
70 }; 70 };
71 71
72 class SampledAllocation { 72 class AllocationNode {
73 public: 73 public:
74 SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler, 74 AllocationNode(const char* const name, int script_id,
75 Isolate* isolate, Local<Value> local, size_t size, 75 const int start_position)
76 int max_frames); 76 : script_id_(script_id),
77 ~SampledAllocation() { 77 script_position_(start_position),
78 for (auto info : stack_) { 78 name_(name) {}
79 delete info; 79 ~AllocationNode() {
80 for (auto child : children_) {
81 delete child;
80 } 82 }
81 global_.Reset(); // drop the reference.
82 } 83 }
83 size_t get_size() const { return size_; }
84 const std::vector<FunctionInfo*>& get_stack() const { return stack_; }
85 84
86 private: 85 private:
87 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); 86 std::map<size_t, unsigned int> allocations_;
87 std::vector<AllocationNode*> children_;
88 const int script_id_;
89 const int script_position_;
90 const char* const name_;
88 91
89 SamplingHeapProfiler* const sampling_heap_profiler_; 92 friend class SamplingHeapProfiler;
90 Global<Value> global_;
91 std::vector<FunctionInfo*> stack_;
92 const size_t size_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); 94 DISALLOW_COPY_AND_ASSIGN(AllocationNode);
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
102 // Methods that construct v8::AllocationProfile. 104 // Methods that construct v8::AllocationProfile.
103 v8::AllocationProfile::Node* AddStack( 105
104 AllocationProfile* profile, const std::map<int, Script*>& scripts, 106 // Translates the provided AllocationNode *node* returning an equivalent
105 const std::vector<FunctionInfo*>& stack); 107 // AllocationProfile::Node. The newly created AllocationProfile::Node is added
106 v8::AllocationProfile::Node* FindOrAddChildNode( 108 // to the provided AllocationProfile *profile*. Line numbers, column numbers,
107 AllocationProfile* profile, const std::map<int, Script*>& scripts, 109 // and script names are resolved using *scripts* which maps all currently
108 v8::AllocationProfile::Node* parent, FunctionInfo* function_info); 110 // loaded scripts keyed by their script id.
109 v8::AllocationProfile::Node* AllocateNode( 111 v8::AllocationProfile::Node* TranslateAllocationNode(
110 AllocationProfile* profile, const std::map<int, Script*>& scripts, 112 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node,
111 FunctionInfo* function_info); 113 const std::map<int, Script*>& scripts);
114 AllocationNode* AddStack();
115 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name,
116 int script_id, int start_position);
112 117
113 Isolate* const isolate_; 118 Isolate* const isolate_;
114 Heap* const heap_; 119 Heap* const heap_;
115 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; 120 base::SmartPointer<SamplingAllocationObserver> new_space_observer_;
116 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; 121 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_;
117 StringsStorage* const names_; 122 StringsStorage* const names_;
118 std::set<SampledAllocation*> samples_; 123 AllocationNode profile_root_;
124 std::set<Sample*> samples_;
119 const int stack_depth_; 125 const int stack_depth_;
120 126
121 friend class SamplingAllocationObserver; 127 friend class SamplingAllocationObserver;
122 }; 128 };
123 129
124 class SamplingAllocationObserver : public AllocationObserver { 130 class SamplingAllocationObserver : public AllocationObserver {
125 public: 131 public:
126 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate, 132 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate,
127 SamplingHeapProfiler* profiler, 133 SamplingHeapProfiler* profiler,
128 base::RandomNumberGenerator* random) 134 base::RandomNumberGenerator* random)
(...skipping 19 matching lines...) Expand all
148 SamplingHeapProfiler* const profiler_; 154 SamplingHeapProfiler* const profiler_;
149 Heap* const heap_; 155 Heap* const heap_;
150 base::RandomNumberGenerator* const random_; 156 base::RandomNumberGenerator* const random_;
151 uint64_t const rate_; 157 uint64_t const rate_;
152 }; 158 };
153 159
154 } // namespace internal 160 } // namespace internal
155 } // namespace v8 161 } // namespace v8
156 162
157 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ 163 #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