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

Unified Diff: src/profiler/sampling-heap-profiler.cc

Issue 1706343002: Unsampling for the sampling heap profiler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adjust sampling rates in comparatives rate test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/profiler/sampling-heap-profiler.h ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/profiler/sampling-heap-profiler.cc
diff --git a/src/profiler/sampling-heap-profiler.cc b/src/profiler/sampling-heap-profiler.cc
index 4127858123af5400b0c5415214d1c62c88291898..ac481b09a33c5455f1e7ab8981b0b17529075f4f 100644
--- a/src/profiler/sampling-heap-profiler.cc
+++ b/src/profiler/sampling-heap-profiler.cc
@@ -33,6 +33,20 @@ intptr_t SamplingAllocationObserver::GetNextSampleInterval(uint64_t rate) {
: (next > INT_MAX ? INT_MAX : static_cast<intptr_t>(next));
}
+// Samples were collected according to a poisson process. Since we have not
+// recorded all allocations, we must approximate the shape of the underlying
+// space of allocations based on the samples we have collected. Given that
+// we sample at rate R, the probability that an allocation of size S will be
+// sampled is 1-exp(-S/R). This function uses the above probability to
+// approximate the true number of allocations with size *size* given that
+// *count* samples were observed.
+v8::AllocationProfile::Allocation SamplingHeapProfiler::ScaleSample(
+ size_t size, unsigned int count) {
+ double scale = 1.0 / (1.0 - std::exp(-static_cast<double>(size) / rate_));
+ // Round count instead of truncating.
+ return {size, static_cast<unsigned int>(count * scale + 0.5)};
+}
+
SamplingHeapProfiler::SamplingHeapProfiler(Heap* heap, StringsStorage* names,
uint64_t rate, int stack_depth)
: isolate_(heap->isolate()),
@@ -46,7 +60,9 @@ SamplingHeapProfiler::SamplingHeapProfiler(Heap* heap, StringsStorage* names,
names_(names),
profile_root_("(root)", v8::UnboundScript::kNoScriptId, 0),
samples_(),
- stack_depth_(stack_depth) {
+ stack_depth_(stack_depth),
+ rate_(rate) {
+ CHECK_GT(rate_, 0);
heap->new_space()->AddAllocationObserver(new_space_observer_.get());
AllSpaces spaces(heap);
for (Space* space = spaces.next(); space != NULL; space = spaces.next()) {
@@ -196,7 +212,7 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
line = 1 + Script::GetLineNumber(script_handle, node->script_position_);
column = 1 + Script::GetColumnNumber(script_handle, node->script_position_);
for (auto alloc : node->allocations_) {
- allocations.push_back({alloc.first, alloc.second});
+ allocations.push_back(ScaleSample(alloc.first, alloc.second));
}
}
« no previous file with comments | « src/profiler/sampling-heap-profiler.h ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698