OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_V8_SAMPLER_H_ |
| 6 #define V8_V8_SAMPLER_H_ |
| 7 |
| 8 #include "v8.h" |
| 9 |
| 10 /** |
| 11 * Sampler API for the V8 JavaScript engine. |
| 12 * The API to be consumed by any code which |
| 13 * wants to build a sampling profiler for v8. |
| 14 */ |
| 15 namespace v8 { |
| 16 typedef unsigned char* Address; |
| 17 |
| 18 /** |
| 19 * A collected sample contains, |
| 20 * - state : The state of the VM at the time of collecting the sample. |
| 21 * - stack : An array of addresses. |
| 22 * One address per stack frame. |
| 23 * The address is the instruction pointer, |
| 24 * pointing to the instruction which led to the |
| 25 * creation of the stack frame. |
| 26 * (for example, a function call) |
| 27 * - frames_count: Number of stack frames that were captured. |
| 28 * That is, stack[frames_count+i] might contain meaningless |
| 29 * addresses for any i >= 0. |
| 30 */ |
| 31 struct Sample { |
| 32 Sample() |
| 33 : frames_count(0) {} |
| 34 static const unsigned kMaxFramesCountLog2 = 8; |
| 35 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; |
| 36 |
| 37 Address stack[kMaxFramesCount]; // Call stack. |
| 38 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. |
| 39 }; |
| 40 |
| 41 /** |
| 42 * Interface for collecting execution stack samples. |
| 43 */ |
| 44 class V8_EXPORT Sampler { |
| 45 public: |
| 46 /** |
| 47 * Obtain a sample from the isolate. |
| 48 * Updates the sample pointer with the newly obtained |
| 49 * sampling information. |
| 50 * On success, returns the sample pointer. |
| 51 * On failure, returns NULL. |
| 52 */ |
| 53 static Sample* GetSample(Isolate* isolate, |
| 54 Sample* sample); |
| 55 }; |
| 56 } // namespace v8 |
| 57 #endif // V8_V8_SAMPLER_H_ |
OLD | NEW |