Bug 1349917 - Outputting parse duration draft
authorDavid Teller <dteller@mozilla.com>
Mon, 24 Apr 2017 16:50:59 +0200
changeset 567763 6e4b9a97f7b7e13e2c8383ed1efc0891456c90c6
parent 567762 d4db1ee1b5b3faf894417ba1d13a1ccb9a43f5e2
child 567764 577f734dc70ab25065edce91e4a6d0a402c958f0
push id55689
push userdteller@mozilla.com
push dateTue, 25 Apr 2017 14:21:34 +0000
bugs1349917
milestone55.0a1
Bug 1349917 - Outputting parse duration MozReview-Commit-ID: H4iMVZzMcc1
js/src/frontend/BinaryAST.cpp
js/src/frontend/Parser.cpp
js/src/shell/js.cpp
--- a/js/src/frontend/BinaryAST.cpp
+++ b/js/src/frontend/BinaryAST.cpp
@@ -151,16 +151,17 @@ void serializeAtom(JSContext* cx, JSAtom
         JSAutoByteString bs;
         if (!bs.encodeUtf8(cx, string)) { // 0 terminated, right?
             MOZ_CRASH();
         }
 
         out.write(bs.ptr(), bs.length());
     } else {
         // FIXME: We could magically map this to string identifier 0. Is it worth it?
+        // FIXME: This constant is poorly chosen. Pick something else that's invalid UTF-8.
         const char zero[2] = { 0, 0 }; // Magic constant (invalid utf8 string).
         out.write((const char*)&zero, sizeof zero);
     }
     result = Move(out.str());
 }
 
 JSAtom* deserializeAtom(JSContext* cx, const std::string& data)
 {
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -973,17 +973,21 @@ Parser<ParseHandler, CharT>::parse()
     ParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr);
     if (!globalpc.init())
         return null();
 
     ParseContext::VarScope varScope(this);
     if (!varScope.init(pc))
         return null();
 
+    const mozilla::TimeStamp start = mozilla::TimeStamp::Now();
     Node pn = statementList(YieldIsName);
+    const mozilla::TimeStamp stop = mozilla::TimeStamp::Now();
+    fprintf(stderr, "Parser<>::parse() duration: %fms\n", (stop - start).ToMilliseconds());
+
     if (!pn)
         return null();
 
     TokenKind tt;
     if (!tokenStream.getToken(&tt, TokenStream::Operand))
         return null();
     if (tt != TOK_EOF) {
         error(JSMSG_GARBAGE_AFTER_INPUT, "script", TokenKindToDesc(tt));
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -4443,20 +4443,22 @@ ReadBinaryAST(JSContext* cx, unsigned ar
         // In a real implementation, we'll probably want to replace istringstream with something better.
     std::cerr << "ReadBinaryAST from " << buf_length << " bytes at " << (void*)buf_data << "\n";
     std::cerr << "ReadBinaryAST string: " << buf_str.length() << "\n";
 
     std::ostringstream _debug; // Ignored.
 //    in_stream.exceptions(in_stream.exceptions() | std::istringstream::badbit | std::istringstream::failbit | std::istringstream::eofbit );
 
     ParseNodeAllocator allocator(cx, cx->tempLifoAlloc());
+    const mozilla::TimeStamp start = mozilla::TimeStamp::Now();
     if (!binParse(cx, allocator, in_stream, _debug)) {
         return false;
     }
-
+    const mozilla::TimeStamp stop = mozilla::TimeStamp::Now();
+    std::cerr << "ReadBinaryAST duration: " << (stop-start).ToMilliseconds() << "ms\n";
     args.rval().setUndefined();
     return true;
 }
 
 static bool
 ParseAux(JSContext* cx, unsigned argc, Value* vp, ParseOptions& instructions)
 {
     using namespace js::frontend;