Add generic V8 API functions for controlling profiling aspects.

As we'll have several aspects of heap profiling, it is more handy to control them using binary flags than by individual functions. CPU profiling represent just a particular aspect to control, so {Pause,Resume}Profiler and IsProfilerPaused are only left for compatibility.

For now, PROFILER_FLAG_HEAP_STATS and PROFILER_FLAG_JS_CONSTRUCTOR are equivalent, but later will be split.

Review URL: http://codereview.chromium.org/159581

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2574 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 84d8e51d
......@@ -1966,6 +1966,20 @@ typedef void (*GCCallback)();
typedef Persistent<Context> (*ContextGenerator)();
/**
* Profiler modules.
*
* In V8, profiler consists of several modules: CPU profiler, and different
* kinds of heap profiling. Each can be turned on / off independently.
*/
enum ProfilerModules {
PROFILER_MODULE_NONE = 0,
PROFILER_MODULE_CPU = 1,
PROFILER_MODULE_HEAP_STATS = 1 << 1,
PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2
};
/**
* Container class for static utility functions.
*/
......@@ -2119,6 +2133,32 @@ class V8EXPORT V8 {
*/
static bool IsProfilerPaused();
/**
* Resumes specified profiler modules.
* "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)".
* See ProfilerModules enum.
*
* \param flags Flags specifying profiler modules.
*/
static void ResumeProfilerEx(int flags);
/**
* Pauses specified profiler modules.
* "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)".
* See ProfilerModules enum.
*
* \param flags Flags specifying profiler modules.
*/
static void PauseProfilerEx(int flags);
/**
* Returns active (resumed) profiler modules.
* See ProfilerModules enum.
*
* \returns active profiler modules.
*/
static int GetActiveProfilerModules();
/**
* If logging is performed into a memory buffer (via --logfile=*), allows to
* retrieve previously written messages. This can be used for retrieving
......
......@@ -3235,6 +3235,46 @@ bool V8::IsProfilerPaused() {
}
void V8::ResumeProfilerEx(int flags) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (flags & PROFILER_MODULE_CPU) {
i::Logger::ResumeProfiler();
}
if (flags & (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
i::FLAG_log_gc = true;
}
#endif
}
void V8::PauseProfilerEx(int flags) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (flags & PROFILER_MODULE_CPU) {
i::Logger::PauseProfiler();
}
if (flags & (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
i::FLAG_log_gc = false;
}
#endif
}
int V8::GetActiveProfilerModules() {
#ifdef ENABLE_LOGGING_AND_PROFILING
int result = PROFILER_MODULE_NONE;
if (!i::Logger::IsProfilerPaused()) {
result |= PROFILER_MODULE_CPU;
}
if (i::FLAG_log_gc) {
result |= PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS;
}
return result;
#else
return PROFILER_MODULE_NONE;
#endif
}
int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
#ifdef ENABLE_LOGGING_AND_PROFILING
return i::Logger::GetLogLines(from_pos, dest_buf, max_size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment