OLD | NEW |
---|---|
(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 class TickSample { | |
48 public: | |
Sven Panne
2013/04/15 07:08:40
Style nit: Use a struct instead of class+public, i
yurys
2013/04/15 11:37:55
Done.
| |
49 TickSample() | |
50 : state(OTHER), | |
51 pc(NULL), | |
52 sp(NULL), | |
53 fp(NULL), | |
54 external_callback(NULL), | |
55 frames_count(0) {} | |
56 StateTag state; // The state of the VM. | |
57 Address pc; // Instruction pointer. | |
58 Address sp; // Stack pointer. | |
59 Address fp; // Frame pointer. | |
60 Address external_callback; | |
61 static const int kMaxFramesCount = 64; | |
62 Address stack[kMaxFramesCount]; // Call stack. | |
63 int frames_count : 8; // Number of captured frames. | |
64 }; | |
65 | |
66 class Sampler { | |
67 public: | |
68 // Initializes the Sampler support. Called once at VM startup. | |
69 static void SetUp(); | |
70 static void TearDown(); | |
71 | |
72 // Initialize sampler. | |
73 Sampler(Isolate* isolate, int interval); | |
74 virtual ~Sampler(); | |
75 | |
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 Isolate* isolate() { return isolate_; } | |
Sven Panne
2013/04/15 07:08:40
Add "const". Move it just above interval(), this m
yurys
2013/04/15 11:37:55
Done.
| |
98 | |
99 // Used in tests to make sure that stack sampling is performed. | |
100 int samples_taken() const { return samples_taken_; } | |
101 void ResetSamplesTaken() { samples_taken_ = 0; } | |
102 | |
103 class PlatformData; | |
104 PlatformData* data() { return data_; } | |
105 | |
106 PlatformData* platform_data() { return data_; } | |
Sven Panne
2013/04/15 07:08:40
Why do we need 2 accessors? "const" would be nice,
yurys
2013/04/15 11:37:55
Removed data() accessor, it wasn't used. Added con
| |
107 | |
108 private: | |
109 void SetActive(bool value) { NoBarrier_Store(&active_, value); } | |
110 | |
111 Isolate* isolate_; | |
112 const int interval_; | |
113 Atomic32 profiling_; | |
114 Atomic32 active_; | |
115 PlatformData* data_; // Platform specific data. | |
116 int samples_taken_; // Counts stack samples taken. | |
117 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | |
118 }; | |
119 | |
120 | |
121 } } // namespace v8::internal | |
122 | |
123 #endif // V8_SAMPLER_H_ | |
OLD | NEW |