Introduce Logger::LogCompiledFunctions that logs current map of compiled code.

The goal is to make possible having --prof flag always enabled in Chromium.  Currently we can't do this because --prof causes compiler and gc to log code creations / moves / deletes which aren't needed until we start profiling.  With LogCompiledFunctions it will be possible not to log anything until we start profiling.  When started, the current map of compiled functions will be logged and compiler / gc logging will be enabled to update current state.  When profling is stopped, logging will be turned off again.

Funny that testing code is actually much longer and complex than function code.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2009 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent aec2f3d5
......@@ -357,8 +357,8 @@ bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
// name and line number. Check explicit whether logging is enabled as finding
// the line number is not for free.
if (Logger::is_enabled() || OProfileAgent::is_enabled()) {
Handle<String> func_name(lit->name()->length() > 0 ?
*lit->name() : shared->inferred_name());
Handle<String> func_name(name->length() > 0 ?
*name : shared->inferred_name());
if (script->name()->IsString()) {
int line_num = GetScriptLineNumber(script, start_position);
if (line_num > 0) {
......
......@@ -1108,6 +1108,69 @@ int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) {
return Log::GetLogLines(from_pos, dest_buf, max_size);
}
void Logger::LogCompiledFunctions() {
HandleScope scope;
Handle<SharedFunctionInfo>* sfis = NULL;
int compiled_funcs_count = 0;
{
AssertNoAllocation no_alloc;
HeapIterator iterator;
while (iterator.has_next()) {
HeapObject* obj = iterator.next();
ASSERT(obj != NULL);
if (obj->IsSharedFunctionInfo()
&& SharedFunctionInfo::cast(obj)->is_compiled()) {
++compiled_funcs_count;
}
}
sfis = NewArray< Handle<SharedFunctionInfo> >(compiled_funcs_count);
iterator.reset();
int i = 0;
while (iterator.has_next()) {
HeapObject* obj = iterator.next();
ASSERT(obj != NULL);
if (obj->IsSharedFunctionInfo()
&& SharedFunctionInfo::cast(obj)->is_compiled()) {
sfis[i++] = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(obj));
}
}
}
// During iteration, there can be heap allocation due to
// GetScriptLineNumber call.
for (int i = 0; i < compiled_funcs_count; ++i) {
Handle<SharedFunctionInfo> shared = sfis[i];
Handle<String> name(String::cast(shared->name()));
Handle<String> func_name(name->length() > 0 ?
*name : shared->inferred_name());
if (shared->script()->IsScript()) {
Handle<Script> script(Script::cast(shared->script()));
if (script->name()->IsString()) {
Handle<String> script_name(String::cast(script->name()));
int line_num = GetScriptLineNumber(script, shared->start_position());
if (line_num > 0) {
line_num += script->line_offset()->value() + 1;
LOG(CodeCreateEvent("LazyCompile", shared->code(), *func_name,
*script_name, line_num));
} else {
// Can't distinguish enum and script here, so always use Script.
LOG(CodeCreateEvent("Script", shared->code(), *script_name));
}
continue;
}
}
// If no script or script has no name.
LOG(CodeCreateEvent("LazyCompile", shared->code(), *func_name));
}
DeleteArray(sfis);
}
#endif
......
......@@ -214,6 +214,9 @@ class Logger {
// retrieve previously written messages. See v8.h.
static int GetLogLines(int from_pos, char* dest_buf, int max_size);
// Logs all compiled functions found in the heap.
static void LogCompiledFunctions();
private:
// Emits the source code of a regexp. Used by regexp events.
......
This diff is collapsed.
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