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 /* TODO(gholap): Find a better way of doing this? */ |
| 17 typedef unsigned char* Address; |
| 18 |
| 19 /** |
| 20 * VMState indicates what action the VM is performing during that state. |
| 21 */ |
| 22 enum VMState { |
| 23 JS, // Executing JavaScript. |
| 24 GC, // Garbage Collection. |
| 25 COMPILER, // Compiling JavaScript. |
| 26 OTHER, |
| 27 EXTERNAL, // External call. (For example, a call into blink) |
| 28 IDLE // The VM is idle. |
| 29 }; |
| 30 |
| 31 /** |
| 32 * A collected sample contains, |
| 33 * - state : The state of the VM at the time of collecting the sample. |
| 34 * - stack : An array of addresses. |
| 35 * One address per stack frame. |
| 36 * The address is the instruction pointer, |
| 37 * pointing to the instruction which led to the |
| 38 * creation of the stack frame. |
| 39 * (for example, a function call) |
| 40 * - frames_count: Number of stack frames that were captured. |
| 41 * That is, stack[frames_count+i] might contain meaningless |
| 42 * addresses for any i >= 0. |
| 43 */ |
| 44 struct Sample { |
| 45 static const unsigned kMaxFramesCountLog2 = 8; |
| 46 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; |
| 47 |
| 48 VMState state; // The state of the VM. |
| 49 Address stack[kMaxFramesCount]; // Call stack. |
| 50 unsigned frames_count; // Number of captured frames. |
| 51 }; |
| 52 |
| 53 /** |
| 54 * Interface for collecting execution stack samples. |
| 55 */ |
| 56 class V8_EXPORT Sampler { |
| 57 public: |
| 58 /** |
| 59 * Obtain a sample from the isolate. |
| 60 * Updates the sample pointer with the newly obtained |
| 61 * sampling information. |
| 62 * On success, returns the sample pointer. |
| 63 * On failure, returns NULL. |
| 64 */ |
| 65 static Sample* GetSample(Isolate* isolate, |
| 66 Sample* sample); |
| 67 }; |
| 68 } // namespace v8 |
| 69 #endif // V8_V8_SAMPLER_H_ |
OLD | NEW |