Chromium Code Reviews| Index: include/v8-sampler.h |
| diff --git a/include/v8-sampler.h b/include/v8-sampler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..37626d4e2b7dd59e7ebec8820df2b5b7604dff37 |
| --- /dev/null |
| +++ b/include/v8-sampler.h |
| @@ -0,0 +1,114 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef V8_V8_SAMPLER_H_ |
| +#define V8_V8_SAMPLER_H_ |
| + |
| +#include <string> |
| + |
| +#include "v8.h" |
| + |
| +/** |
| + * Sampler API for the V8 JavaScript engine. |
| + * The API to be consumed by any code which |
| + * wants to build a sampling profiler for v8. |
| + */ |
| +namespace v8 { |
| + /* TODO(gholap): This should go away and struct Smaple sholud |
| + just use const void* instead of Address. |
| + Currently we need it because of implementation details. */ |
| + typedef unsigned char* Address; |
| + |
| +/** |
| + * A collected sample contains, |
| + * - state : The state of the VM at the time of collecting the sample. |
| + * - stack : An array of addresses. |
| + * One address per stack frame. |
| + * The address is the instruction pointer, |
| + * pointing to the instruction which led to the |
| + * creation of the stack frame. |
| + * (for example, a function call) |
| + * - frames_count: Number of stack frames that were captured. |
| + * That is, stack[frames_count+i] might contain meaningless |
| + * addresses for any i >= 0. |
| + */ |
| +struct Sample { |
| + Sample() |
| + : frames_count(0) {} |
| + static const unsigned kMaxFramesCountLog2 = 8; |
| + static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; |
| + |
| + Address stack[kMaxFramesCount]; // Call stack. |
| + unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. |
| +}; |
| + |
| +/** |
| + * To make sense of the PC values gotten from each sample, |
| + * information like the location of compiled code for functions, |
| + * whether the code ever moved from that address etc. |
| + * |
| + * Whenever v8 creates/moves/deletes code, or links a shared library, |
| + * this handler will be called to notify of the code event. |
| + */ |
| +class V8_EXPORT CodeEventHandler { |
|
Sven Panne
2014/08/28 07:14:40
Hmmm, this seems to duplicate functionality from J
|
| + public: |
| + virtual ~CodeEventHandler() {} |
| + |
| + /** |
| + * Called when code is created. |
| + * @from: The address where this newly created code begins. |
| + * @size: Size of the code. |
| + * @name: String representing the name of the code. |
| + */ |
| + virtual void Create(const void* from, |
| + const int size, |
| + const std::string& name) = 0; |
| + |
| + /** |
| + * Called when code is deleted. |
| + * @from: The address from where the code was deleted. |
| + */ |
| + virtual void Delete(const void* from) = 0; |
|
Jarin
2014/08/26 08:23:57
FYI: V8 does not send notifications about deleted
|
| + |
| + /** |
| + * Called when code is moved. |
| + * @from: The initial address where code was. |
| + * @to: New address where the code currently resides. |
| + */ |
| + virtual void Move(const void* from, const void* to) = 0; |
| + |
| + /** |
| + * Called when v8 loads a shared library. |
| + * @library_path: Path to the shared library as a string. |
| + * @start: The shared library is loaded into memory starting with this address. |
| + * @end: Code beyond this address doesn't belong to the shared library. |
| + */ |
| + 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
|
| + const void* start, |
| + const void* end) = 0; |
| +}; |
| + |
| +/** |
| + * Interface for collecting execution stack samples. |
| + */ |
| +class V8_EXPORT Sampler { |
| + public: |
| + /** |
| + * Set the code event handler for the isolate. |
| + */ |
| + static void Install(Isolate* isolate, |
|
Benedikt Meurer
2014/08/26 05:03:57
Jochen suggested that all functions that operate o
|
| + CodeEventHandler* codeEventHandler); |
| + |
| + /** |
| + * Obtain a sample from the isolate. |
| + * Updates the sample pointer with the newly obtained |
| + * sampling information. |
| + * On success, returns the sample pointer. |
| + * On failure, returns NULL. |
| + */ |
| + static Sample* GetSample(Isolate* isolate, |
| + Sample* sample); |
| +}; |
| +} // namespace v8 |
| +#endif // V8_V8_SAMPLER_H_ |