Chromium Code Reviews| Index: include/v8-profiler.h |
| diff --git a/include/v8-profiler.h b/include/v8-profiler.h |
| index e432600290c6bb3e6749e7836b916eb5e0315e17..5a757f01e68674a82ad6f887400394a83dba1df5 100644 |
| --- a/include/v8-profiler.h |
| +++ b/include/v8-profiler.h |
| @@ -5,6 +5,7 @@ |
| #ifndef V8_V8_PROFILER_H_ |
| #define V8_V8_PROFILER_H_ |
| +#include <string> |
|
alph
2016/01/20 23:13:01
not used?
ofrobots
2016/01/21 03:03:28
Done.
|
| #include <vector> |
| #include "v8.h" // NOLINT(build/include) |
| @@ -419,6 +420,101 @@ class V8_EXPORT ActivityControl { // NOLINT |
| /** |
| + * AllocationProfile is a sampled profile of allocations done by the program. |
| + * This is structured as a call-graph. |
| + */ |
| +class V8_EXPORT AllocationProfile { |
| + public: |
| + struct Allocation { |
|
alph
2016/01/20 23:13:01
Out of curiosity, does it need to be that fine gra
ofrobots
2016/01/21 03:03:28
The goal is to have some flexibility in how much o
|
| + /** |
| + * Size of the sampled allocation object. |
| + */ |
| + size_t size; |
| + |
| + /** |
| + * The number of objects of such size that were sampled. |
| + */ |
| + unsigned int count; |
| + }; |
| + |
| + /** |
| + * Represents a node in the call-graph. |
| + */ |
| + struct Node { |
| + Node(Local<String> arg_name, Local<String> arg_script_name, |
|
alph
2016/01/20 23:13:01
I'd move it out of the interface, as the client is
ofrobots
2016/01/21 03:03:28
Done.
|
| + int arg_script_id, int arg_start_position, int line, int column) |
| + : name(arg_name), |
| + script_name(arg_script_name), |
| + script_id(arg_script_id), |
| + start_position(arg_start_position), |
| + line_number(line), |
| + column_number(column), |
| + children(), |
|
alph
2016/01/20 23:13:01
No need to explicitly initialize children and allo
ofrobots
2016/01/21 03:03:28
Acknowledged.
|
| + allocations() {} |
| + |
| + /** |
| + * Name of the function. May be empty for anonymous functions or if the |
| + * script corresponding to this function has been unloaded. |
| + */ |
| + Local<String> name; |
| + |
| + /** |
| + * Name of the script containing the function. May be empty if the script |
| + * name is not available, or if the script has been unloaded. |
| + */ |
| + Local<String> script_name; |
| + |
| + /** |
| + * id of the script where the function is located. May be equal to |
| + * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist. |
| + */ |
| + int script_id; |
| + |
| + /** |
| + * Start position of the function in the script. |
| + */ |
| + int start_position; |
| + |
| + /** |
| + * 1-indexed line number where the function starts. May be |
| + * kNoLineNumberInfo if no line number information is available. |
| + */ |
| + int line_number; |
| + |
| + /** |
| + * 1-indexed column number where the function starts. May be |
| + * kNoColumnNumberInfo if no line number information is available. |
| + */ |
| + int column_number; |
| + |
| + /** |
| + * List of callees called from this node for which we have sampled |
| + * allocations. The lifetime of the children is scoped to the containing |
| + * AllocationProfile. |
| + */ |
| + std::vector<Node*> children; |
| + |
| + /** |
| + * List of self allocations done by this node in the call-graph. |
| + */ |
| + std::vector<Allocation> allocations; |
| + }; |
| + |
| + /** |
| + * Returns the root node of the call-graph. The root node corresponds to an |
| + * empty JS call-stack. The lifetime of the returned Node* is scoped to the |
| + * containing AllocationProfile. |
| + */ |
| + virtual Node* GetRootNode() = 0; |
| + |
| + virtual ~AllocationProfile() {} |
| + |
| + static const int kNoLineNumberInfo = Message::kNoLineNumberInfo; |
| + static const int kNoColumnNumberInfo = Message::kNoColumnInfo; |
| +}; |
| + |
| + |
| +/** |
| * Interface for controlling heap profiling. Instance of the |
| * profiler can be retrieved using v8::Isolate::GetHeapProfiler. |
| */ |
| @@ -522,6 +618,49 @@ class V8_EXPORT HeapProfiler { |
| void StopTrackingHeapObjects(); |
| /** |
| + * Starts gathering a sampling heap profile. A sampling heap profile is |
| + * similar to tcmalloc's heap profiler and Go's mprof. It samples object |
| + * allocations and builds an online 'sampling' heap profile. At any point in |
| + * time, this profile is expected to be a representative sample of objects |
| + * currently live in the system. Each sampled allocation includes the stack |
| + * trace at the time of allocation, which makes this really useful for memory |
| + * leak detection. |
| + * |
| + * This mechanism is intended to be cheap enough that it can be used in |
| + * production with minimal performance overhead. |
| + * |
| + * Allocations are sampled using a randomized Poisson process. On average, one |
| + * allocation will be sampled every |sample_interval| bytes allocated. The |
| + * |stack_depth| parameter controls the maximum number of stack frames to be |
| + * captured on each allocation. |
| + * |
| + * NOTE: This is a proof-of-concept at this point. Right now we only sample |
| + * newspace allocations. Support for paged space allocation (e.g. pre-tenured |
| + * objects, large objects, code objects, etc.) and native allocations |
| + * doesn't exist yet, but is anticipated in the future. |
| + * |
| + * Objects allocated before the sampling is started will not be included in |
| + * the profile. |
| + * |
| + * Returns false if a sampling heap profiler is already running. |
| + */ |
| + bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024, |
| + int stack_depth = 16); |
| + |
| + /** |
| + * Stops the sampling heap profile and discards the current profile. |
| + */ |
| + void StopSamplingHeapProfiler(); |
| + |
| + /** |
| + * Returns the sampled profile of allocations allocated (and still live) since |
| + * StartSamplingHeapProfiler was called. The ownership of the pointer is |
| + * transfered to the caller. Returns nullptr if sampling heap profiler is not |
| + * active. |
| + */ |
| + AllocationProfile* GetAllocationProfile(); |
| + |
| + /** |
| * Deletes all snapshots taken. All previously returned pointers to |
| * snapshots and their contents become invalid after this call. |
| */ |