diff options
author | twerth <twerth@google.com> | 2018-07-09 02:33:27 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-09 02:34:41 -0700 |
commit | ee91e232b9286fe05ea0261a5a68e5f4cd0c4ebb (patch) | |
tree | a7ee52a18f637a9d63adfe6c8cb1c39f292958a8 /src/main/java/com/google/devtools/build/lib/syntax | |
parent | 325e2ea234418d906778bee4aacea90163e2c311 (diff) |
Improve logging for parsing skylark files.
Also add preconditions check.
RELNOTES: None.
PiperOrigin-RevId: 203731929
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Parser.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java index d2d0af16c9..9656ea1068 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java @@ -25,6 +25,7 @@ import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.profiler.Profiler; import com.google.devtools.build.lib.profiler.ProfilerTask; +import com.google.devtools.build.lib.profiler.SilentCloseable; import com.google.devtools.build.lib.syntax.DictionaryLiteral.DictionaryEntryLiteral; import com.google.devtools.build.lib.syntax.IfStatement.ConditionalStatements; import java.util.ArrayList; @@ -185,12 +186,15 @@ public class Parser { * @param input the input to parse * @param eventHandler a reporter for parsing errors * @see BuildFileAST#parseBuildString - * @see BuildFileAST#parseSkylarkString */ public static ParseResult parseFile(ParserInputSource input, EventHandler eventHandler) { Lexer lexer = new Lexer(input, eventHandler); Parser parser = new Parser(lexer, eventHandler); - List<Statement> statements = parser.parseFileInput(); + List<Statement> statements; + try (SilentCloseable c = + Profiler.instance().profile(ProfilerTask.SKYLARK_PARSER, input.getPath().getPathString())) { + statements = parser.parseFileInput(); + } boolean errors = parser.errorsCount > 0 || lexer.containsErrors(); return new ParseResult( statements, lexer.getComments(), locationFromStatements(lexer, statements), errors); @@ -1002,7 +1006,6 @@ public class Parser { // file_input ::= ('\n' | stmt)* EOF private List<Statement> parseFileInput() { - long startTime = Profiler.nanoTimeMaybe(); List<Statement> list = new ArrayList<>(); while (token.kind != TokenKind.EOF) { if (token.kind == TokenKind.NEWLINE) { @@ -1016,7 +1019,6 @@ public class Parser { parseTopLevelStatement(list); } } - Profiler.instance().logSimpleTask(startTime, ProfilerTask.SKYLARK_PARSER, ""); return list; } |