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 | |
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')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/profiler/Profiler.java | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Parser.java | 10 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java index 6a9b41e752..2e971fedfa 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java @@ -652,6 +652,7 @@ public final class Profiler { private void logTask(long startTimeNanos, long duration, ProfilerTask type, String description) { Preconditions.checkNotNull(description); Preconditions.checkState(startTimeNanos > 0, "startTime was %s", startTimeNanos); + Preconditions.checkState(!"".equals(description), "No description -> not helpful"); if (duration < 0) { // See note in Clock#nanoTime, which is used by Profiler#nanoTimeMaybe. duration = 0; 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; } |