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

Side by Side Diff: src/sampler.h

Issue 13852005: Move *BSD and Solaris Sampler implementations into sampler.cc (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed class TickSample forward declaration Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/platform-solaris.cc ('k') | src/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 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_SAMPLER_H_
29 #define V8_SAMPLER_H_
30
31 #include "atomicops.h"
32 #include "v8globals.h"
33
34 namespace v8 {
35 namespace internal {
36
37 class Isolate;
38
39 // ----------------------------------------------------------------------------
40 // Sampler
41 //
42 // A sampler periodically samples the state of the VM and optionally
43 // (if used for profiling) the program counter and stack pointer for
44 // the thread that created it.
45
46 // TickSample captures the information collected for each sample.
47 struct TickSample {
48 TickSample()
49 : state(OTHER),
50 pc(NULL),
51 sp(NULL),
52 fp(NULL),
53 external_callback(NULL),
54 frames_count(0) {}
55 StateTag state; // The state of the VM.
56 Address pc; // Instruction pointer.
57 Address sp; // Stack pointer.
58 Address fp; // Frame pointer.
59 Address external_callback;
60 static const int kMaxFramesCount = 64;
61 Address stack[kMaxFramesCount]; // Call stack.
62 int frames_count : 8; // Number of captured frames.
63 };
64
65 class Sampler {
66 public:
67 // Initializes the Sampler support. Called once at VM startup.
68 static void SetUp();
69 static void TearDown();
70
71 // Initialize sampler.
72 Sampler(Isolate* isolate, int interval);
73 virtual ~Sampler();
74
75 Isolate* isolate() const { return isolate_; }
76 int interval() const { return interval_; }
77
78 // Performs stack sampling.
79 void SampleStack(TickSample* sample);
80
81 // This method is called for each sampling period with the current
82 // program counter.
83 virtual void Tick(TickSample* sample) = 0;
84
85 // Start and stop sampler.
86 void Start();
87 void Stop();
88
89 // Is the sampler used for profiling?
90 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; }
91 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); }
92 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); }
93
94 // Whether the sampler is running (that is, consumes resources).
95 bool IsActive() const { return NoBarrier_Load(&active_); }
96
97 // Used in tests to make sure that stack sampling is performed.
98 int samples_taken() const { return samples_taken_; }
99 void ResetSamplesTaken() { samples_taken_ = 0; }
100
101 class PlatformData;
102 PlatformData* platform_data() const { return data_; }
103
104 private:
105 void SetActive(bool value) { NoBarrier_Store(&active_, value); }
106
107 Isolate* isolate_;
108 const int interval_;
109 Atomic32 profiling_;
110 Atomic32 active_;
111 PlatformData* data_; // Platform specific data.
112 int samples_taken_; // Counts stack samples taken.
113 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
114 };
115
116
117 } } // namespace v8::internal
118
119 #endif // V8_SAMPLER_H_
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698