Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_PROFILER_SAMPLER_H_ | 5 #ifndef V8_PROFILER_SAMPLER_H_ |
| 6 #define V8_PROFILER_SAMPLER_H_ | 6 #define V8_PROFILER_SAMPLER_H_ |
| 7 | 7 |
| 8 #include "include/v8.h" | 8 #include "include/v8.h" |
| 9 | 9 |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| 11 #include "src/base/platform/time.h" | 11 #include "src/base/macros.h" |
| 12 #include "src/frames.h" | |
| 13 #include "src/globals.h" | 12 #include "src/globals.h" |
| 14 | 13 |
| 15 namespace v8 { | 14 namespace v8 { |
| 16 namespace internal { | 15 namespace internal { |
| 17 | 16 |
| 18 class Isolate; | 17 class Isolate; |
| 18 struct TickSample; | |
| 19 | 19 |
| 20 // ---------------------------------------------------------------------------- | 20 // ---------------------------------------------------------------------------- |
| 21 // Sampler | 21 // Sampler |
| 22 // | 22 // |
| 23 // A sampler periodically samples the state of the VM and optionally | 23 // A sampler periodically samples the state of the VM and optionally |
| 24 // (if used for profiling) the program counter and stack pointer for | 24 // (if used for profiling) the program counter and stack pointer for |
| 25 // the thread that created it. | 25 // the thread that created it. |
| 26 | 26 |
| 27 // TickSample captures the information collected for each sample. | |
| 28 struct TickSample { | |
| 29 // Internal profiling (with --prof + tools/$OS-tick-processor) wants to | |
| 30 // include the runtime function we're calling. Externally exposed tick | |
| 31 // samples don't care. | |
| 32 enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame }; | |
| 33 | |
| 34 TickSample() | |
| 35 : state(OTHER), | |
| 36 pc(NULL), | |
| 37 external_callback_entry(NULL), | |
| 38 frames_count(0), | |
| 39 has_external_callback(false), | |
| 40 update_stats(true), | |
| 41 top_frame_type(StackFrame::NONE) {} | |
| 42 void Init(Isolate* isolate, const v8::RegisterState& state, | |
| 43 RecordCEntryFrame record_c_entry_frame, bool update_stats); | |
| 44 static void GetStackSample(Isolate* isolate, const v8::RegisterState& state, | |
| 45 RecordCEntryFrame record_c_entry_frame, | |
| 46 void** frames, size_t frames_limit, | |
| 47 v8::SampleInfo* sample_info); | |
| 48 StateTag state; // The state of the VM. | |
| 49 Address pc; // Instruction pointer. | |
| 50 union { | |
| 51 Address tos; // Top stack value (*sp). | |
| 52 Address external_callback_entry; | |
| 53 }; | |
| 54 static const unsigned kMaxFramesCountLog2 = 8; | |
| 55 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; | |
| 56 Address stack[kMaxFramesCount]; // Call stack. | |
| 57 base::TimeTicks timestamp; | |
| 58 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. | |
| 59 bool has_external_callback : 1; | |
| 60 bool update_stats : 1; // Whether the sample should update aggregated stats. | |
| 61 StackFrame::Type top_frame_type : 5; | |
| 62 }; | |
| 63 | |
| 64 class Sampler { | 27 class Sampler { |
| 65 public: | 28 public: |
| 66 // Initializes the Sampler support. Called once at VM startup. | 29 // Initializes the Sampler support. Called once at VM startup. |
| 67 static void SetUp(); | 30 static void SetUp(); |
| 68 static void TearDown(); | 31 static void TearDown(); |
| 69 | 32 |
| 70 // Initialize sampler. | 33 // Initialize sampler. |
| 71 Sampler(Isolate* isolate, int interval); | 34 Sampler(Isolate* isolate, int interval); |
| 72 virtual ~Sampler(); | 35 virtual ~Sampler(); |
| 73 | 36 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 PlatformData* data_; // Platform specific data. | 98 PlatformData* data_; // Platform specific data. |
| 136 // Counts stack samples taken in various VM states. | 99 // Counts stack samples taken in various VM states. |
| 137 bool is_counting_samples_; | 100 bool is_counting_samples_; |
| 138 unsigned js_sample_count_; | 101 unsigned js_sample_count_; |
| 139 unsigned external_sample_count_; | 102 unsigned external_sample_count_; |
| 140 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 103 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 141 }; | 104 }; |
| 142 | 105 |
| 143 | 106 |
| 144 #if defined(USE_SIMULATOR) | 107 #if defined(USE_SIMULATOR) |
| 145 class SimulatorHelper : AllStatic { | 108 class SimulatorHelper { |
|
alph
2016/05/13 00:39:07
This should also stay along with TickSample in v8.
lpy
2016/05/13 21:29:04
Done.
alph
2016/05/13 21:38:40
Thanks. Looks even better now!
| |
| 146 public: | 109 public: |
| 147 // Returns true if register values were successfully retrieved | 110 // Returns true if register values were successfully retrieved |
| 148 // from the simulator, otherwise returns false. | 111 // from the simulator, otherwise returns false. |
| 149 static bool FillRegisters(Isolate* isolate, v8::RegisterState* state); | 112 static bool FillRegisters(Isolate* isolate, v8::RegisterState* state); |
| 150 }; | 113 }; |
| 151 #endif // USE_SIMULATOR | 114 #endif // USE_SIMULATOR |
| 152 | 115 |
| 153 | 116 |
| 154 } // namespace internal | 117 } // namespace internal |
| 155 } // namespace v8 | 118 } // namespace v8 |
| 156 | 119 |
| 157 #endif // V8_PROFILER_SAMPLER_H_ | 120 #endif // V8_PROFILER_SAMPLER_H_ |
| OLD | NEW |