Commit 0a8cd4dc authored by alph's avatar alph Committed by Commit bot

Sampling heap profiler: Force Full GC before retrieving the profile.

BUG=v8:4959
LOG=N

Review-Url: https://codereview.chromium.org/1949693003
Cr-Commit-Position: refs/heads/master@{#36042}
parent 8c55885f
......@@ -515,6 +515,11 @@ class V8_EXPORT AllocationProfile {
*/
class V8_EXPORT HeapProfiler {
public:
enum SamplingFlags {
kSamplingNoFlags = 0,
kSamplingForceGC = 1 << 0,
};
/**
* Callback function invoked for obtaining RetainedObjectInfo for
* the given JavaScript wrapper object. It is prohibited to enter V8
......@@ -640,7 +645,8 @@ class V8_EXPORT HeapProfiler {
* Returns false if a sampling heap profiler is already running.
*/
bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
int stack_depth = 16);
int stack_depth = 16,
SamplingFlags flags = kSamplingNoFlags);
/**
* Stops the sampling heap profile and discards the current profile.
......
......@@ -8528,11 +8528,11 @@ SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream,
return heap_profiler->PushHeapObjectsStats(stream, timestamp_us);
}
bool HeapProfiler::StartSamplingHeapProfiler(uint64_t sample_interval,
int stack_depth) {
return reinterpret_cast<i::HeapProfiler*>(this)
->StartSamplingHeapProfiler(sample_interval, stack_depth);
int stack_depth,
SamplingFlags flags) {
return reinterpret_cast<i::HeapProfiler*>(this)->StartSamplingHeapProfiler(
sample_interval, stack_depth, flags);
}
......
......@@ -84,14 +84,14 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
return result;
}
bool HeapProfiler::StartSamplingHeapProfiler(uint64_t sample_interval,
int stack_depth) {
bool HeapProfiler::StartSamplingHeapProfiler(
uint64_t sample_interval, int stack_depth,
v8::HeapProfiler::SamplingFlags flags) {
if (sampling_heap_profiler_.get()) {
return false;
}
sampling_heap_profiler_.Reset(new SamplingHeapProfiler(
heap(), names_.get(), sample_interval, stack_depth));
heap(), names_.get(), sample_interval, stack_depth, flags));
return true;
}
......
......@@ -30,7 +30,8 @@ class HeapProfiler {
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver);
bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth);
bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth,
v8::HeapProfiler::SamplingFlags);
void StopSamplingHeapProfiler();
bool is_sampling_allocations() { return !sampling_heap_profiler_.is_empty(); }
AllocationProfile* GetAllocationProfile();
......
......@@ -47,8 +47,9 @@ v8::AllocationProfile::Allocation SamplingHeapProfiler::ScaleSample(
return {size, static_cast<unsigned int>(count * scale + 0.5)};
}
SamplingHeapProfiler::SamplingHeapProfiler(Heap* heap, StringsStorage* names,
uint64_t rate, int stack_depth)
SamplingHeapProfiler::SamplingHeapProfiler(
Heap* heap, StringsStorage* names, uint64_t rate, int stack_depth,
v8::HeapProfiler::SamplingFlags flags)
: isolate_(heap->isolate()),
heap_(heap),
new_space_observer_(new SamplingAllocationObserver(
......@@ -61,7 +62,8 @@ SamplingHeapProfiler::SamplingHeapProfiler(Heap* heap, StringsStorage* names,
profile_root_(nullptr, "(root)", v8::UnboundScript::kNoScriptId, 0),
samples_(),
stack_depth_(stack_depth),
rate_(rate) {
rate_(rate),
flags_(flags) {
CHECK_GT(rate_, 0);
heap->new_space()->AddAllocationObserver(new_space_observer_.get());
AllSpaces spaces(heap);
......@@ -257,6 +259,10 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
}
v8::AllocationProfile* SamplingHeapProfiler::GetAllocationProfile() {
if (flags_ & v8::HeapProfiler::kSamplingForceGC) {
isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags,
"SamplingHeapProfiler");
}
// To resolve positions to line/column numbers, we will need to look up
// scripts. Build a map to allow fast mapping from script id to script.
std::map<int, Handle<Script>> scripts;
......
......@@ -41,7 +41,7 @@ class AllocationProfile : public v8::AllocationProfile {
class SamplingHeapProfiler {
public:
SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate,
int stack_depth);
int stack_depth, v8::HeapProfiler::SamplingFlags flags);
~SamplingHeapProfiler();
v8::AllocationProfile* GetAllocationProfile();
......@@ -130,6 +130,7 @@ class SamplingHeapProfiler {
std::set<Sample*> samples_;
const int stack_depth_;
const uint64_t rate_;
v8::HeapProfiler::SamplingFlags flags_;
friend class SamplingAllocationObserver;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment