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

Side by Side Diff: src/profiler/sampler.h

Issue 1922303002: Create libsampler as V8 sampler library. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix TSAN failure 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/profiler/cpu-profiler.cc ('k') | src/profiler/sampler.cc » ('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 2013 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_PROFILER_SAMPLER_H_
6 #define V8_PROFILER_SAMPLER_H_
7
8 #include "include/v8.h"
9
10 #include "src/base/atomicops.h"
11 #include "src/base/macros.h"
12
13 namespace v8 {
14 namespace internal {
15
16 class Isolate;
17 struct TickSample;
18
19 // ----------------------------------------------------------------------------
20 // Sampler
21 //
22 // A sampler periodically samples the state of the VM and optionally
23 // (if used for profiling) the program counter and stack pointer for
24 // the thread that created it.
25
26 class Sampler {
27 public:
28 // Initializes the Sampler support. Called once at VM startup.
29 static void SetUp();
30 static void TearDown();
31
32 // Initialize sampler.
33 Sampler(Isolate* isolate, int interval);
34 virtual ~Sampler();
35
36 Isolate* isolate() const { return isolate_; }
37 int interval() const { return interval_; }
38
39 // Performs stack sampling.
40 void SampleStack(const v8::RegisterState& regs);
41
42 // Start and stop sampler.
43 void Start();
44 void Stop();
45
46 // Whether the sampling thread should use this Sampler for CPU profiling?
47 bool IsProfiling() const {
48 return base::NoBarrier_Load(&profiling_) > 0 &&
49 !base::NoBarrier_Load(&has_processing_thread_);
50 }
51 void IncreaseProfilingDepth();
52 void DecreaseProfilingDepth();
53
54 // Whether the sampler is running (that is, consumes resources).
55 bool IsActive() const { return base::NoBarrier_Load(&active_); }
56
57 // CpuProfiler collects samples by calling DoSample directly
58 // without calling Start. To keep it working, we register the sampler
59 // with the CpuProfiler.
60 bool IsRegistered() const { return base::NoBarrier_Load(&registered_); }
61
62 void DoSample();
63 // If true next sample must be initiated on the profiler event processor
64 // thread right after latest sample is processed.
65 void SetHasProcessingThread(bool value) {
66 base::NoBarrier_Store(&has_processing_thread_, value);
67 }
68
69 // Used in tests to make sure that stack sampling is performed.
70 unsigned js_sample_count() const { return js_sample_count_; }
71 unsigned external_sample_count() const { return external_sample_count_; }
72 void StartCountingSamples() {
73 js_sample_count_ = 0;
74 external_sample_count_ = 0;
75 is_counting_samples_ = true;
76 }
77
78 class PlatformData;
79 PlatformData* platform_data() const { return data_; }
80
81 protected:
82 // This method is called for each sampling period with the current
83 // program counter.
84 virtual void Tick(TickSample* sample) = 0;
85
86 private:
87 void SetActive(bool value) { base::NoBarrier_Store(&active_, value); }
88
89 void SetRegistered(bool value) { base::NoBarrier_Store(&registered_, value); }
90
91 Isolate* isolate_;
92 const int interval_;
93 base::Atomic32 profiling_;
94 base::Atomic32 has_processing_thread_;
95 base::Atomic32 active_;
96 base::Atomic32 registered_;
97 PlatformData* data_; // Platform specific data.
98 // Counts stack samples taken in various VM states.
99 bool is_counting_samples_;
100 unsigned js_sample_count_;
101 unsigned external_sample_count_;
102 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
103 };
104
105 } // namespace internal
106 } // namespace v8
107
108 #endif // V8_PROFILER_SAMPLER_H_
OLDNEW
« no previous file with comments | « src/profiler/cpu-profiler.cc ('k') | src/profiler/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698