From: mstarzinger@chromium.org Date: Wed, 18 Jul 2012 11:22:46 +0000 (+0000) Subject: Add --trace-parse flag to parser. X-Git-Tag: upstream/4.7.83~16302 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d552f09d1898092682f98317ce73363ef8611f5;p=platform%2Fupstream%2Fv8.git Add --trace-parse flag to parser. R=yangguo@chromium.org Review URL: https://chromiumcodereview.appspot.com/10802012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12120 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 4ad73ad..82e0513 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -409,6 +409,7 @@ DEFINE_bool(use_verbose_printer, true, "allows verbose printing") // parser.cc DEFINE_bool(allow_natives_syntax, false, "allow natives syntax") +DEFINE_bool(trace_parse, false, "trace parsing and preparsing") // simulator-arm.cc and simulator-mips.cc DEFINE_bool(trace_sim, false, "Trace simulator execution") diff --git a/src/parser.cc b/src/parser.cc index 5ec2857..5ee217c 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -567,14 +567,15 @@ Parser::Parser(CompilationInfo* info, FunctionLiteral* Parser::ParseProgram() { ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT); - HistogramTimerScope timer(isolate()->counters()->parse()); Handle source(String::cast(script_->source())); isolate()->counters()->total_parse_size()->Increment(source->length()); + int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); // Initialize parser state. source->TryFlatten(); + FunctionLiteral* result; if (source->IsExternalTwoByteString()) { // Notice that the stream is destroyed at the end of the branch block. // The last line of the blocks can't be moved outside, even though they're @@ -582,12 +583,27 @@ FunctionLiteral* Parser::ParseProgram() { ExternalTwoByteStringUtf16CharacterStream stream( Handle::cast(source), 0, source->length()); scanner_.Initialize(&stream); - return DoParseProgram(info(), source, &zone_scope); + result = DoParseProgram(info(), source, &zone_scope); } else { GenericStringUtf16CharacterStream stream(source, 0, source->length()); scanner_.Initialize(&stream); - return DoParseProgram(info(), source, &zone_scope); + result = DoParseProgram(info(), source, &zone_scope); } + + if (FLAG_trace_parse && result != NULL) { + double ms = static_cast(OS::Ticks() - start) / 1000; + if (info()->is_eval()) { + PrintF("[parsing eval"); + } else if (info()->script()->name()->IsString()) { + String* name = String::cast(info()->script()->name()); + SmartArrayPointer name_chars = name->ToCString(); + PrintF("[parsing script: %s", *name_chars); + } else { + PrintF("[parsing script"); + } + PrintF(" - took %0.3f ms]\n", ms); + } + return result; } @@ -668,24 +684,31 @@ FunctionLiteral* Parser::ParseLazy() { HistogramTimerScope timer(isolate()->counters()->parse_lazy()); Handle source(String::cast(script_->source())); isolate()->counters()->total_parse_size()->Increment(source->length()); - + int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; Handle shared_info = info()->shared_info(); + // Initialize parser state. source->TryFlatten(); + FunctionLiteral* result; if (source->IsExternalTwoByteString()) { ExternalTwoByteStringUtf16CharacterStream stream( Handle::cast(source), shared_info->start_position(), shared_info->end_position()); - FunctionLiteral* result = ParseLazy(&stream, &zone_scope); - return result; + result = ParseLazy(&stream, &zone_scope); } else { GenericStringUtf16CharacterStream stream(source, shared_info->start_position(), shared_info->end_position()); - FunctionLiteral* result = ParseLazy(&stream, &zone_scope); - return result; + result = ParseLazy(&stream, &zone_scope); } + + if (FLAG_trace_parse && result != NULL) { + double ms = static_cast(OS::Ticks() - start) / 1000; + SmartArrayPointer name_chars = result->name()->ToCString(); + PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); + } + return result; }