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

Side by Side Diff: src/profiler/sampling-heap-profiler.cc

Issue 2053893003: [builtins] Introduce proper base::ieee754::log. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: BUILD.gn Created 4 years, 6 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 | « src/external-reference-table.cc ('k') | src/v8.gyp » ('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 #include "src/profiler/sampling-heap-profiler.h" 5 #include "src/profiler/sampling-heap-profiler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <memory> 8 #include <memory>
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/ieee754.h"
10 #include "src/base/utils/random-number-generator.h" 11 #include "src/base/utils/random-number-generator.h"
11 #include "src/frames-inl.h" 12 #include "src/frames-inl.h"
12 #include "src/heap/heap.h" 13 #include "src/heap/heap.h"
13 #include "src/isolate.h" 14 #include "src/isolate.h"
14 #include "src/profiler/strings-storage.h" 15 #include "src/profiler/strings-storage.h"
15 16
16 namespace v8 { 17 namespace v8 {
17 namespace internal { 18 namespace internal {
18 19
19 // We sample with a Poisson process, with constant average sampling interval. 20 // We sample with a Poisson process, with constant average sampling interval.
20 // This follows the exponential probability distribution with parameter 21 // This follows the exponential probability distribution with parameter
21 // λ = 1/rate where rate is the average number of bytes between samples. 22 // λ = 1/rate where rate is the average number of bytes between samples.
22 // 23 //
23 // Let u be a uniformly distributed random number between 0 and 1, then 24 // Let u be a uniformly distributed random number between 0 and 1, then
24 // next_sample = (- ln u) / λ 25 // next_sample = (- ln u) / λ
25 intptr_t SamplingAllocationObserver::GetNextSampleInterval(uint64_t rate) { 26 intptr_t SamplingAllocationObserver::GetNextSampleInterval(uint64_t rate) {
26 if (FLAG_sampling_heap_profiler_suppress_randomness) { 27 if (FLAG_sampling_heap_profiler_suppress_randomness) {
27 return static_cast<intptr_t>(rate); 28 return static_cast<intptr_t>(rate);
28 } 29 }
29 double u = random_->NextDouble(); 30 double u = random_->NextDouble();
30 double next = (-std::log(u)) * rate; 31 double next = (-base::ieee754::log(u)) * rate;
31 return next < kPointerSize 32 return next < kPointerSize
32 ? kPointerSize 33 ? kPointerSize
33 : (next > INT_MAX ? INT_MAX : static_cast<intptr_t>(next)); 34 : (next > INT_MAX ? INT_MAX : static_cast<intptr_t>(next));
34 } 35 }
35 36
36 // Samples were collected according to a poisson process. Since we have not 37 // Samples were collected according to a poisson process. Since we have not
37 // recorded all allocations, we must approximate the shape of the underlying 38 // recorded all allocations, we must approximate the shape of the underlying
38 // space of allocations based on the samples we have collected. Given that 39 // space of allocations based on the samples we have collected. Given that
39 // we sample at rate R, the probability that an allocation of size S will be 40 // we sample at rate R, the probability that an allocation of size S will be
40 // sampled is 1-exp(-S/R). This function uses the above probability to 41 // sampled is 1-exp(-S/R). This function uses the above probability to
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 272 }
272 } 273 }
273 auto profile = new v8::internal::AllocationProfile(); 274 auto profile = new v8::internal::AllocationProfile();
274 TranslateAllocationNode(profile, &profile_root_, scripts); 275 TranslateAllocationNode(profile, &profile_root_, scripts);
275 return profile; 276 return profile;
276 } 277 }
277 278
278 279
279 } // namespace internal 280 } // namespace internal
280 } // namespace v8 281 } // namespace v8
OLDNEW
« no previous file with comments | « src/external-reference-table.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698