| Index: src/profiler/sampling-heap-profiler.h
|
| diff --git a/src/profiler/sampling-heap-profiler.h b/src/profiler/sampling-heap-profiler.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..25962d984d1aee54ed96e995be4e61b6edb6a430
|
| --- /dev/null
|
| +++ b/src/profiler/sampling-heap-profiler.h
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2015 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
|
| +#define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
|
| +
|
| +#include <set>
|
| +#include "src/base/utils/random-number-generator.h"
|
| +#include "src/profiler/allocation-tracker.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +class SamplingHeapProfiler : public InlineAllocationObserver {
|
| + public:
|
| + SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate,
|
| + int stack_depth);
|
| + ~SamplingHeapProfiler();
|
| +
|
| + void GetHeapSample(OutputStream* stream);
|
| +
|
| + void Step(int bytes_allocated, Address soon_object, size_t size) override;
|
| + intptr_t GetNextStepSize() override {
|
| + return GetNextSampleInterval(random_, rate_);
|
| + }
|
| +
|
| + StringsStorage* names() const { return names_; }
|
| +
|
| + struct FunctionInfo {
|
| + FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names);
|
| +
|
| + const char* const name;
|
| + const char* script_name;
|
| + int script_id;
|
| + int start_position;
|
| + };
|
| +
|
| + class SampledAllocation {
|
| + public:
|
| + SampledAllocation(SamplingHeapProfiler* shp, Isolate* isolate,
|
| + Local<Value> local, size_t size, int max_frames);
|
| + ~SampledAllocation() {
|
| + stack_.Iterate(&DeleteFunctionInfo);
|
| + global_.Reset(); // drop the reference.
|
| + }
|
| + size_t get_size() const { return size_; }
|
| + List<FunctionInfo*>& get_stack() { return stack_; }
|
| +
|
| + private:
|
| + static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data);
|
| + static void DeleteFunctionInfo(FunctionInfo** infop) { delete *infop; }
|
| +
|
| + SamplingHeapProfiler* const shp_;
|
| + Global<Value> global_;
|
| + List<FunctionInfo*> stack_;
|
| + const size_t size_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SampledAllocation);
|
| + };
|
| +
|
| + private:
|
| + Heap* heap() const { return heap_; }
|
| +
|
| + void SampleObject(Address soon_object, size_t size);
|
| +
|
| + static intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random,
|
| + uint64_t rate);
|
| +
|
| + Isolate* const isolate_;
|
| + Heap* const heap_;
|
| + base::RandomNumberGenerator* const random_;
|
| + StringsStorage* const names_;
|
| + std::set<SampledAllocation*> samples_;
|
| + const uint64_t rate_;
|
| + const int stack_depth_;
|
| +};
|
| +
|
| +} // namespace internal
|
| +} // namespace v8
|
| +
|
| +#endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
|
|
|