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 <string> | |
9 | |
10 #include "v8.h" | |
11 | |
12 /** | |
13 * Sampler API for the V8 JavaScript engine. | |
14 * The API to be consumed by any code which | |
15 * wants to build a sampling profiler for v8. | |
16 */ | |
17 namespace v8 { | |
18 /* TODO(gholap): This should go away and struct Smaple sholud | |
19 just use const void* instead of Address. | |
20 Currently we need it because of implementation details. */ | |
21 typedef unsigned char* Address; | |
22 | |
23 /** | |
24 * A collected sample contains, | |
25 * - state : The state of the VM at the time of collecting the sample. | |
26 * - stack : An array of addresses. | |
27 * One address per stack frame. | |
28 * The address is the instruction pointer, | |
29 * pointing to the instruction which led to the | |
30 * creation of the stack frame. | |
31 * (for example, a function call) | |
32 * - frames_count: Number of stack frames that were captured. | |
33 * That is, stack[frames_count+i] might contain meaningless | |
34 * addresses for any i >= 0. | |
35 */ | |
36 struct Sample { | |
37 Sample() | |
38 : frames_count(0) {} | |
39 static const unsigned kMaxFramesCountLog2 = 8; | |
40 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; | |
41 | |
42 Address stack[kMaxFramesCount]; // Call stack. | |
43 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. | |
44 }; | |
45 | |
46 /** | |
47 * To make sense of the PC values gotten from each sample, | |
48 * information like the location of compiled code for functions, | |
49 * whether the code ever moved from that address etc. | |
50 * | |
51 * Whenever v8 creates/moves/deletes code, or links a shared library, | |
52 * this handler will be called to notify of the code event. | |
53 */ | |
54 class V8_EXPORT CodeEventHandler { | |
Sven Panne
2014/08/28 07:14:40
Hmmm, this seems to duplicate functionality from J
| |
55 public: | |
56 virtual ~CodeEventHandler() {} | |
57 | |
58 /** | |
59 * Called when code is created. | |
60 * @from: The address where this newly created code begins. | |
61 * @size: Size of the code. | |
62 * @name: String representing the name of the code. | |
63 */ | |
64 virtual void Create(const void* from, | |
65 const int size, | |
66 const std::string& name) = 0; | |
67 | |
68 /** | |
69 * Called when code is deleted. | |
70 * @from: The address from where the code was deleted. | |
71 */ | |
72 virtual void Delete(const void* from) = 0; | |
Jarin
2014/08/26 08:23:57
FYI: V8 does not send notifications about deleted
| |
73 | |
74 /** | |
75 * Called when code is moved. | |
76 * @from: The initial address where code was. | |
77 * @to: New address where the code currently resides. | |
78 */ | |
79 virtual void Move(const void* from, const void* to) = 0; | |
80 | |
81 /** | |
82 * Called when v8 loads a shared library. | |
83 * @library_path: Path to the shared library as a string. | |
84 * @start: The shared library is loaded into memory starting with this address . | |
85 * @end: Code beyond this address doesn't belong to the shared library. | |
86 */ | |
87 virtual void SharedLibrary(const std::string& library_path, | |
Benedikt Meurer
2014/08/26 05:03:57
As discussed earlier, this should really not be ha
| |
88 const void* start, | |
89 const void* end) = 0; | |
90 }; | |
91 | |
92 /** | |
93 * Interface for collecting execution stack samples. | |
94 */ | |
95 class V8_EXPORT Sampler { | |
96 public: | |
97 /** | |
98 * Set the code event handler for the isolate. | |
99 */ | |
100 static void Install(Isolate* isolate, | |
Benedikt Meurer
2014/08/26 05:03:57
Jochen suggested that all functions that operate o
| |
101 CodeEventHandler* codeEventHandler); | |
102 | |
103 /** | |
104 * Obtain a sample from the isolate. | |
105 * Updates the sample pointer with the newly obtained | |
106 * sampling information. | |
107 * On success, returns the sample pointer. | |
108 * On failure, returns NULL. | |
109 */ | |
110 static Sample* GetSample(Isolate* isolate, | |
111 Sample* sample); | |
112 }; | |
113 } // namespace v8 | |
114 #endif // V8_V8_SAMPLER_H_ | |
OLD | NEW |