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

Side by Side Diff: src/sampler.h

Issue 578163002: Implemented GetSample. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Including win32-headers.h in v8.h for testing on trybots. Created 6 years, 3 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 {
yurys 2014/09/19 08:08:12 I would expect this struct to be moved into v8.h a
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);
41 StateTag state; // The state of the VM. 36 StateTag state; // The state of the VM.
42 Address pc; // Instruction pointer. 37 Address pc; // Instruction pointer.
43 union { 38 union {
44 Address tos; // Top stack value (*sp). 39 Address tos; // Top stack value (*sp).
45 Address external_callback; 40 Address external_callback;
46 }; 41 };
47 static const unsigned kMaxFramesCountLog2 = 8; 42 static const unsigned kMaxFramesCountLog2 = 8;
48 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; 43 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
49 Address stack[kMaxFramesCount]; // Call stack. 44 Address stack[kMaxFramesCount]; // Call stack.
50 base::TimeTicks timestamp; 45 base::TimeTicks timestamp;
51 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. 46 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
52 bool has_external_callback : 1; 47 bool has_external_callback : 1;
53 StackFrame::Type top_frame_type : 4; 48 StackFrame::Type top_frame_type : 4;
54 }; 49 };
55 50
56 class Sampler { 51 class Sampler {
57 public: 52 public:
58 // Initializes the Sampler support. Called once at VM startup. 53 // Initializes the Sampler support. Called once at VM startup.
59 static void SetUp(); 54 static void SetUp();
60 static void TearDown(); 55 static void TearDown();
61 56
62 // Initialize sampler. 57 // Initialize sampler.
63 Sampler(Isolate* isolate, int interval); 58 Sampler(Isolate* isolate, int interval);
64 virtual ~Sampler(); 59 virtual ~Sampler();
65 60
66 Isolate* isolate() const { return isolate_; } 61 Isolate* isolate() const { return isolate_; }
67 int interval() const { return interval_; } 62 int interval() const { return interval_; }
68 63
69 // Performs stack sampling. 64 // Performs stack sampling.
70 void SampleStack(const RegisterState& regs); 65 void SampleStack(const v8::RegisterState& regs);
71 66
72 // Start and stop sampler. 67 // Start and stop sampler.
73 void Start(); 68 void Start();
74 void Stop(); 69 void Stop();
75 70
76 // Whether the sampling thread should use this Sampler for CPU profiling? 71 // Whether the sampling thread should use this Sampler for CPU profiling?
77 bool IsProfiling() const { 72 bool IsProfiling() const {
78 return base::NoBarrier_Load(&profiling_) > 0 && 73 return base::NoBarrier_Load(&profiling_) > 0 &&
79 !base::NoBarrier_Load(&has_processing_thread_); 74 !base::NoBarrier_Load(&has_processing_thread_);
80 } 75 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 bool is_counting_samples_; 115 bool is_counting_samples_;
121 // Counts stack samples taken in JS VM state. 116 // Counts stack samples taken in JS VM state.
122 unsigned js_and_external_sample_count_; 117 unsigned js_and_external_sample_count_;
123 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 118 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
124 }; 119 };
125 120
126 121
127 } } // namespace v8::internal 122 } } // namespace v8::internal
128 123
129 #endif // V8_SAMPLER_H_ 124 #endif // V8_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698