Skip to content

Commit

Permalink
Repeat bazelbuild@d9b0cfd for profiling of Starlark file parsing.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 609306213
Change-Id: I3227bf3175f7b7121b9e4fc4928f475c9adc1ba4
  • Loading branch information
meisterT authored and copybara-github committed Feb 22, 2024
1 parent 4193954 commit a59deae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
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.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.PackageLoading;
import com.google.devtools.build.lib.server.FailureDetails.PackageLoading.Code;
Expand Down Expand Up @@ -549,13 +548,14 @@ public void visit(CallExpression node) {
StarlarkFile.setParseProfiler(
new StarlarkFile.ParseProfiler() {
@Override
public Object start(String filename) {
return Profiler.instance().profile(ProfilerTask.STARLARK_PARSER, filename);
public long start() {
return Profiler.nanoTimeMaybe();
}

@Override
public void end(Object span) {
((SilentCloseable) span).close();
public void end(long startTimeNanos, String filename) {
Profiler.instance()
.completeTask(startTimeNanos, ProfilerTask.STARLARK_PARSER, filename);
}
});

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/starlark/java/syntax/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ static ParseResult parseFile(ParserInput input, FileOptions options) {
Parser parser = new Parser(lexer, errors);

StarlarkFile.ParseProfiler profiler = Parser.profiler;
Object span = profiler != null ? profiler.start(input.getFile()) : null;
long profileStartNanos = profiler != null ? profiler.start() : -1;
try {
ImmutableList<Statement> statements = parser.parseFileInput();
return new ParseResult(lexer.locs, statements, lexer.getComments(), errors);
} finally {
if (profiler != null) {
profiler.end(span);
if (profileStartNanos != -1) {
profiler.end(profileStartNanos, input.getFile());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/starlark/java/syntax/StarlarkFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public String getName() {

/** A ParseProfiler records the start and end times of parse operations. */
public interface ParseProfiler {
Object start(String filename);
long start();

void end(Object span);
void end(long profileStartNanos, String filename);
}

/** Installs a global hook that will be notified of parse operations. */
Expand Down

0 comments on commit a59deae

Please sign in to comment.