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

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: Fix ARM32 build. 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
« no previous file with comments | « src/globals.h ('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
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 void GetStackSample(Isolate* isolate, const v8::RegisterState& state,
37 void** frames, size_t frames_limit,
38 v8::SampleInfo* sample_info);
41 StateTag state; // The state of the VM. 39 StateTag state; // The state of the VM.
42 Address pc; // Instruction pointer. 40 Address pc; // Instruction pointer.
43 union { 41 union {
44 Address tos; // Top stack value (*sp). 42 Address tos; // Top stack value (*sp).
45 Address external_callback; 43 Address external_callback;
46 }; 44 };
47 static const unsigned kMaxFramesCountLog2 = 8; 45 static const unsigned kMaxFramesCountLog2 = 8;
48 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; 46 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
49 Address stack[kMaxFramesCount]; // Call stack. 47 Address stack[kMaxFramesCount]; // Call stack.
50 base::TimeTicks timestamp; 48 base::TimeTicks timestamp;
51 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. 49 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
52 bool has_external_callback : 1; 50 bool has_external_callback : 1;
53 StackFrame::Type top_frame_type : 4; 51 StackFrame::Type top_frame_type : 4;
54 }; 52 };
55 53
56 class Sampler { 54 class Sampler {
57 public: 55 public:
58 // Initializes the Sampler support. Called once at VM startup. 56 // Initializes the Sampler support. Called once at VM startup.
59 static void SetUp(); 57 static void SetUp();
60 static void TearDown(); 58 static void TearDown();
61 59
62 // Initialize sampler. 60 // Initialize sampler.
63 Sampler(Isolate* isolate, int interval); 61 Sampler(Isolate* isolate, int interval);
64 virtual ~Sampler(); 62 virtual ~Sampler();
65 63
66 Isolate* isolate() const { return isolate_; } 64 Isolate* isolate() const { return isolate_; }
67 int interval() const { return interval_; } 65 int interval() const { return interval_; }
68 66
69 // Performs stack sampling. 67 // Performs stack sampling.
70 void SampleStack(const RegisterState& regs); 68 void SampleStack(const v8::RegisterState& regs);
71 69
72 // Start and stop sampler. 70 // Start and stop sampler.
73 void Start(); 71 void Start();
74 void Stop(); 72 void Stop();
75 73
76 // Whether the sampling thread should use this Sampler for CPU profiling? 74 // Whether the sampling thread should use this Sampler for CPU profiling?
77 bool IsProfiling() const { 75 bool IsProfiling() const {
78 return base::NoBarrier_Load(&profiling_) > 0 && 76 return base::NoBarrier_Load(&profiling_) > 0 &&
79 !base::NoBarrier_Load(&has_processing_thread_); 77 !base::NoBarrier_Load(&has_processing_thread_);
80 } 78 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 bool is_counting_samples_; 118 bool is_counting_samples_;
121 // Counts stack samples taken in JS VM state. 119 // Counts stack samples taken in JS VM state.
122 unsigned js_and_external_sample_count_; 120 unsigned js_and_external_sample_count_;
123 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 121 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
124 }; 122 };
125 123
126 124
127 } } // namespace v8::internal 125 } } // namespace v8::internal
128 126
129 #endif // V8_SAMPLER_H_ 127 #endif // V8_SAMPLER_H_
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698