Chromium Code Reviews| Index: src/profiler/sampling-heap-profiler.h |
| diff --git a/src/profiler/sampling-heap-profiler.h b/src/profiler/sampling-heap-profiler.h |
| index 1f98bec849f80f7f068c8e903d6b6b8e190f79e2..18fed7dac6044eef9de38f30dba0b77c9a71de1e 100644 |
| --- a/src/profiler/sampling-heap-profiler.h |
| +++ b/src/profiler/sampling-heap-profiler.h |
| @@ -48,50 +48,49 @@ class SamplingHeapProfiler { |
| StringsStorage* names() const { return names_; } |
| - class FunctionInfo { |
| + class AllocationNode; |
| + |
| + struct Sample { |
| public: |
| - FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); |
| - explicit FunctionInfo(const char* name) |
| - : name_(name), |
| - script_name_(""), |
| - script_id_(v8::UnboundScript::kNoScriptId), |
| - start_position_(0) {} |
| - |
| - const char* get_name() const { return name_; } |
| - const char* get_script_name() const { return script_name_; } |
| - int get_script_id() const { return script_id_; } |
| - int get_start_position() const { return start_position_; } |
| + Sample(size_t size_, AllocationNode* owner_, Local<Value> local_, |
| + SamplingHeapProfiler* profiler_) |
| + : size(size_), |
| + owner(owner_), |
| + global(Global<Value>( |
| + reinterpret_cast<v8::Isolate*>(profiler_->isolate_), local_)), |
| + profiler(profiler_) {} |
| + size_t size; |
|
ofrobots
2016/02/17 22:34:49
const size_t
mattloring
2016/02/17 23:11:00
Done.
|
| + AllocationNode* owner; |
|
ofrobots
2016/02/17 22:34:49
AllocationNode* const owner;
mattloring
2016/02/17 23:11:00
Done.
|
| + Global<Value> global; |
| + SamplingHeapProfiler* profiler; |
|
ofrobots
2016/02/17 22:34:49
SamplingHeapProfiler* const profiler;
mattloring
2016/02/17 23:11:00
Done.
|
| private: |
| - const char* const name_; |
| - const char* script_name_; |
| - int script_id_; |
| - const int start_position_; |
| + DISALLOW_COPY_AND_ASSIGN(Sample); |
| }; |
| - class SampledAllocation { |
| + class AllocationNode { |
| public: |
| - SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler, |
| - Isolate* isolate, Local<Value> local, size_t size, |
| - int max_frames); |
| - ~SampledAllocation() { |
| - for (auto info : stack_) { |
| - delete info; |
| + AllocationNode(const char* const name, int script_id, |
| + const int start_position) |
| + : script_id_(script_id), |
| + script_position_(start_position), |
| + name_(name) {} |
| + ~AllocationNode() { |
| + for (auto child : children_) { |
| + delete child; |
| } |
| - 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.
|
| } |
| - size_t get_size() const { return size_; } |
| - const std::vector<FunctionInfo*>& get_stack() const { return stack_; } |
| private: |
| - static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); |
| + std::map<size_t, unsigned int> allocations_; |
| + std::vector<AllocationNode*> children_; |
| + int script_id_; |
|
ofrobots
2016/02/17 22:34:49
const int script_id;
mattloring
2016/02/17 23:11:00
Done.
|
| + int script_position_; |
|
ofrobots
2016/02/17 22:34:49
const int start_position_;
mattloring
2016/02/17 23:11:00
Done.
|
| + const char* name_; |
|
ofrobots
2016/02/17 22:34:49
const char* const name_;
mattloring
2016/02/17 23:11:00
Done.
|
| - SamplingHeapProfiler* const sampling_heap_profiler_; |
| - Global<Value> global_; |
| - std::vector<FunctionInfo*> stack_; |
| - const size_t size_; |
| + friend class SamplingHeapProfiler; |
| - DISALLOW_COPY_AND_ASSIGN(SampledAllocation); |
| + DISALLOW_COPY_AND_ASSIGN(AllocationNode); |
| }; |
| private: |
| @@ -99,23 +98,29 @@ class SamplingHeapProfiler { |
| void SampleObject(Address soon_object, size_t size); |
| + static void OnWeakCallback(const WeakCallbackInfo<Sample>& data); |
| + |
| // Methods that construct v8::AllocationProfile. |
| - v8::AllocationProfile::Node* AddStack( |
| - AllocationProfile* profile, const std::map<int, Script*>& scripts, |
| - const std::vector<FunctionInfo*>& stack); |
| - v8::AllocationProfile::Node* FindOrAddChildNode( |
| - AllocationProfile* profile, const std::map<int, Script*>& scripts, |
| - v8::AllocationProfile::Node* parent, FunctionInfo* function_info); |
| - v8::AllocationProfile::Node* AllocateNode( |
| - AllocationProfile* profile, const std::map<int, Script*>& scripts, |
| - FunctionInfo* function_info); |
| + |
| + // Translates the provided AllocationNode *node* returning an equivalent |
| + // AllocationProfile::Node. The newly created AllocationProfile::Node is added |
| + // to the provided AllocationProfile *profile*. Line numbers, column numbers, |
| + // and script names are resolved using *scripts* which maps all currently |
| + // loaded scripts keyed by their script id. |
| + v8::AllocationProfile::Node* TranslateAllocationNode( |
| + AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, |
| + const std::map<int, Script*>& scripts); |
| + AllocationNode* AddStack(); |
| + AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name, |
| + int script_id, int start_position); |
| Isolate* const isolate_; |
| Heap* const heap_; |
| base::SmartPointer<SamplingAllocationObserver> new_space_observer_; |
| base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; |
| StringsStorage* const names_; |
| - std::set<SampledAllocation*> samples_; |
| + AllocationNode profile_root_; |
| + std::set<Sample*> samples_; |
| const int stack_depth_; |
| friend class SamplingAllocationObserver; |