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

Side by Side Diff: src/sampler.h

Issue 596533002: Initial implementation of GetStackSample sampling profiler API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 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 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 #ifndef V8_SAMPLER_H_ 5 #ifndef V8_SAMPLER_H_
6 #define V8_SAMPLER_H_ 6 #define V8_SAMPLER_H_
7 7
8 #include "include/v8.h"
9
8 #include "src/base/atomicops.h" 10 #include "src/base/atomicops.h"
9 #include "src/frames.h" 11 #include "src/frames.h"
10 #include "src/globals.h" 12 #include "src/globals.h"
11 13
12 namespace v8 { 14 namespace v8 {
13 namespace internal { 15 namespace internal {
14 16
15 class Isolate; 17 class Isolate;
16 18
17 // ---------------------------------------------------------------------------- 19 // ----------------------------------------------------------------------------
18 // Sampler 20 // Sampler
19 // 21 //
20 // A sampler periodically samples the state of the VM and optionally 22 // A sampler periodically samples the state of the VM and optionally
21 // (if used for profiling) the program counter and stack pointer for 23 // (if used for profiling) the program counter and stack pointer for
22 // the thread that created it. 24 // the thread that created it.
23 25
24 struct RegisterState {
25 RegisterState() : pc(NULL), sp(NULL), fp(NULL) {}
26 Address pc; // Instruction pointer.
27 Address sp; // Stack pointer.
28 Address fp; // Frame pointer.
29 };
30
31 // TickSample captures the information collected for each sample. 26 // TickSample captures the information collected for each sample.
32 struct TickSample { 27 struct TickSample {
33 TickSample() 28 TickSample()
34 : state(OTHER), 29 : state(OTHER),
35 pc(NULL), 30 pc(NULL),
36 external_callback(NULL), 31 external_callback(NULL),
37 frames_count(0), 32 frames_count(0),
38 has_external_callback(false), 33 has_external_callback(false),
39 top_frame_type(StackFrame::NONE) {} 34 top_frame_type(StackFrame::NONE) {}
40 void Init(Isolate* isolate, const RegisterState& state); 35 void Init(Isolate* isolate, const v8::RegisterState& state);
36 static int GetStackSample(Isolate* isolate, const v8::RegisterState& state,
37 void** frames, int frames_limit);
41 StateTag state; // The state of the VM. 38 StateTag state; // The state of the VM.
42 Address pc; // Instruction pointer. 39 Address pc; // Instruction pointer.
43 union { 40 union {
44 Address tos; // Top stack value (*sp). 41 Address tos; // Top stack value (*sp).
45 Address external_callback; 42 Address external_callback;
46 }; 43 };
47 static const unsigned kMaxFramesCountLog2 = 8; 44 static const unsigned kMaxFramesCountLog2 = 8;
48 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; 45 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
49 Address stack[kMaxFramesCount]; // Call stack. 46 Address stack[kMaxFramesCount]; // Call stack.
50 base::TimeTicks timestamp; 47 base::TimeTicks timestamp;
51 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. 48 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
52 bool has_external_callback : 1; 49 bool has_external_callback : 1;
53 StackFrame::Type top_frame_type : 4; 50 StackFrame::Type top_frame_type : 4;
54 }; 51 };
55 52
56 class Sampler { 53 class Sampler {
57 public: 54 public:
58 // Initializes the Sampler support. Called once at VM startup. 55 // Initializes the Sampler support. Called once at VM startup.
59 static void SetUp(); 56 static void SetUp();
60 static void TearDown(); 57 static void TearDown();
61 58
62 // Initialize sampler. 59 // Initialize sampler.
63 Sampler(Isolate* isolate, int interval); 60 Sampler(Isolate* isolate, int interval);
64 virtual ~Sampler(); 61 virtual ~Sampler();
65 62
66 Isolate* isolate() const { return isolate_; } 63 Isolate* isolate() const { return isolate_; }
67 int interval() const { return interval_; } 64 int interval() const { return interval_; }
68 65
69 // Performs stack sampling. 66 // Performs stack sampling.
70 void SampleStack(const RegisterState& regs); 67 void SampleStack(const v8::RegisterState& regs);
71 68
72 // Start and stop sampler. 69 // Start and stop sampler.
73 void Start(); 70 void Start();
74 void Stop(); 71 void Stop();
75 72
76 // Whether the sampling thread should use this Sampler for CPU profiling? 73 // Whether the sampling thread should use this Sampler for CPU profiling?
77 bool IsProfiling() const { 74 bool IsProfiling() const {
78 return base::NoBarrier_Load(&profiling_) > 0 && 75 return base::NoBarrier_Load(&profiling_) > 0 &&
79 !base::NoBarrier_Load(&has_processing_thread_); 76 !base::NoBarrier_Load(&has_processing_thread_);
80 } 77 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 bool is_counting_samples_; 117 bool is_counting_samples_;
121 // Counts stack samples taken in JS VM state. 118 // Counts stack samples taken in JS VM state.
122 unsigned js_and_external_sample_count_; 119 unsigned js_and_external_sample_count_;
123 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 120 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
124 }; 121 };
125 122
126 123
127 } } // namespace v8::internal 124 } } // namespace v8::internal
128 125
129 #endif // V8_SAMPLER_H_ 126 #endif // V8_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698