diff options
author | 2016-11-14 21:28:47 +0000 | |
---|---|---|
committer | 2016-11-15 15:59:10 +0000 | |
commit | 6630c25b1c8c8d55b2afa2d37acd1a1ebcfe205b (patch) | |
tree | 94fb6285e1872f360a012ebead001e6160331538 /src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java | |
parent | 5bd26b24a643432c962b6256876b6729199c03d9 (diff) |
Avoid AutoProfiler overhead in AbstractBlazeQueryEnvironment#evaluateQuery.
--
MOS_MIGRATED_REVID=139113333
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java index 32d8617f8b..c16a592797 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java @@ -24,7 +24,6 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.packages.DependencyFilter; import com.google.devtools.build.lib.packages.Target; -import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.query2.engine.OutputFormatterCallback; import com.google.devtools.build.lib.query2.engine.QueryEnvironment; import com.google.devtools.build.lib.query2.engine.QueryEvalResult; @@ -61,7 +60,8 @@ public abstract class AbstractBlazeQueryEnvironment<T> protected final List<QueryFunction> extraFunctions; private final QueryExpressionEvalListener<T> evalListener; - private static final Logger LOG = Logger.getLogger(AbstractBlazeQueryEnvironment.class.getName()); + private static final Logger logger = + Logger.getLogger(AbstractBlazeQueryEnvironment.class.getName()); protected AbstractBlazeQueryEnvironment(boolean keepGoing, boolean strictScope, @@ -122,37 +122,40 @@ public abstract class AbstractBlazeQueryEnvironment<T> final OutputFormatterCallback<T> callback) throws QueryException, InterruptedException, IOException { EmptinessSensingCallback<T> emptySensingCallback = createEmptinessSensingCallback(callback); - try (final AutoProfiler p = AutoProfiler.logged("evaluating query", LOG)) { - // In the --nokeep_going case, errors are reported in the order in which the patterns are - // specified; using a linked hash set here makes sure that the left-most error is reported. - Set<String> targetPatternSet = new LinkedHashSet<>(); - expr.collectTargetPatterns(targetPatternSet); - try { - preloadOrThrow(expr, targetPatternSet); - } catch (TargetParsingException e) { - // Unfortunately, by evaluating the patterns in parallel, we lose some location information. - throw new QueryException(expr, e.getMessage()); - } - IOException ioExn = null; + long startTime = System.currentTimeMillis(); + // In the --nokeep_going case, errors are reported in the order in which the patterns are + // specified; using a linked hash set here makes sure that the left-most error is reported. + Set<String> targetPatternSet = new LinkedHashSet<>(); + expr.collectTargetPatterns(targetPatternSet); + try { + preloadOrThrow(expr, targetPatternSet); + } catch (TargetParsingException e) { + // Unfortunately, by evaluating the patterns in parallel, we lose some location information. + throw new QueryException(expr, e.getMessage()); + } + IOException ioExn = null; + try { + callback.start(); + evalTopLevelInternal(expr, emptySensingCallback); + } catch (QueryException e) { + throw new QueryException(e, expr); + } catch (InterruptedException e) { + throw e; + } finally { try { - callback.start(); - evalTopLevelInternal(expr, emptySensingCallback); - } catch (QueryException e) { - throw new QueryException(e, expr); - } catch (InterruptedException e) { - throw e; - } finally { - try { - callback.close(); - } catch (IOException e) { - // Only throw this IOException if we weren't about to throw a different exception. - ioExn = e; - } - } - if (ioExn != null) { - throw ioExn; + callback.close(); + } catch (IOException e) { + // Only throw this IOException if we weren't about to throw a different exception. + ioExn = e; } } + if (ioExn != null) { + throw ioExn; + } + long elapsedTime = System.currentTimeMillis() - startTime; + if (elapsedTime > 1) { + logger.info("Spent " + elapsedTime + " milliseconds evaluating query"); + } if (eventHandler.hasErrors()) { if (!keepGoing) { |