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

Side by Side Diff: include/v8-sampler.h

Issue 1708573003: [WIP]Create a V8 sampler library and tracing controller. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | include/v8-tracing-controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_SAMPLER_H_
6 #define V8_SAMPLER_H_
7
8 #include "src/globals.h"
9 #include "src/profiler/sampler.h"
10
11 #if V8_OS_POSIX && !V8_OS_CYGWIN
12 #define USE_SIGNALS
13 #endif
14
15 #if defined(ANDROID)
16 // Phones and tablets have processors that are much slower than desktop
17 // and laptop computers for which current heuristics are tuned.
18 static const int kSamplingIntervalMs = 5;
19 #else
20 static const int kSamplingIntervalMs = 1;
21 #endif
22
23 namespace v8 {
24
25 namespace internal {
26 class Isolate;
27 }
28
29 class Isolate;
30 class SamplerThread;
31 #if defined(USE_SIGNALS)
32 class SignalHandler;
33 #endif
34
35 class V8Sampler {
36 public:
37 // Initializes the sampler support. Called once at embedder startup.
38 static void SetUp();
39 static void TearDown();
40 static void SetInterval(int interval);
41
42 // Initialize sampler.
43 V8Sampler(Isolate* isolate);
44 virtual ~V8Sampler();
45
46 void CollectStackSample(const RegisterState& state,
47 void** frames, size_t frames_limit,
48 SampleInfo* sample_info);
49 void SetJitCodeEventHandler(JitCodeEventOptions,
50 void* handler);
51
52 Isolate* isolate() const { return isolate_; }
53
54 // Performs stack sampling.
55 void SampleStack(const RegisterState& regs);
56
57 // Start and stop sampler.
58 void Start();
59 void Stop();
60
61 // Whether the sampling thread should use this Sampler for CPU profiling?
62 bool IsProfiling() const {
63 return base::NoBarrier_Load(&profiling_) > 0 &&
64 !base::NoBarrier_Load(&has_processing_thread_);
65 }
66 void IncreaseProfilingDepth();
67 void DecreaseProfilingDepth();
68
69 // Whether the sampler is running (that is, consumes resources).
70 bool IsActive() const { return base::NoBarrier_Load(&active_); }
71
72 void DoSample();
73 // If true next sample must be initiated on the profiler event processor
74 // thread right after latest sample is processed.
75 void SetHasProcessingThread(bool value) {
76 base::NoBarrier_Store(&has_processing_thread_, value);
77 }
78
79 // Used in tests to make sure that stack sampling is performed.
80 unsigned js_sample_count() const { return js_sample_count_; }
81 unsigned external_sample_count() const { return external_sample_count_; }
82 void StartCountingSamples() {
83 js_sample_count_ = 0;
84 external_sample_count_ = 0;
85 is_counting_samples_ = true;
86 }
87
88 class PlatformData;
89 PlatformData* platform_data() const { return data_; }
90
91 protected:
92 // This method is called for each sampling period with the current
93 // program counter.
94 virtual void Tick(i::TickSample* tick_sample) = 0;
95
96 private:
97 void SetActive(bool value) { base::NoBarrier_Store(&active_, value); }
98
99 Isolate* isolate_;
100 base::Atomic32 profiling_;
101 base::Atomic32 has_processing_thread_;
102 base::Atomic32 active_;
103 PlatformData* data_; // Platform specific data.
104 // Counts stack samples taken in JS VM state.
105 bool is_counting_samples_;
106 unsigned js_sample_count_;
107 unsigned external_sample_count_;
108 DISALLOW_COPY_AND_ASSIGN(V8Sampler);
109 // DISALLOW_IMPLICIT_CONSTRUCTORS(V8Sampler);
110 };
111
112 } // v8
113
114 #endif // V8_SAMPLER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | include/v8-tracing-controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698