use of io.crate.profile.ProfilingContext in project crate by crate.
the class TransportJobAction method maybeInstrumentProfiler.
private SharedShardContexts maybeInstrumentProfiler(boolean enableProfiling, RootTask.Builder contextBuilder) {
if (enableProfiling) {
var profilers = new ArrayList<QueryProfiler>();
ProfilingContext profilingContext = new ProfilingContext(profilers);
contextBuilder.profilingContext(profilingContext);
return new SharedShardContexts(indicesService, indexSearcher -> {
var queryProfiler = new QueryProfiler();
profilers.add(queryProfiler);
return new InstrumentedIndexSearcher(indexSearcher, queryProfiler);
});
} else {
return new SharedShardContexts(indicesService, UnaryOperator.identity());
}
}
use of io.crate.profile.ProfilingContext in project crate by crate.
the class JobLauncher method maybeInstrumentProfiler.
private SharedShardContexts maybeInstrumentProfiler(RootTask.Builder builder) {
if (enableProfiling) {
var profilers = new ArrayList<QueryProfiler>();
ProfilingContext profilingContext = new ProfilingContext(profilers);
builder.profilingContext(profilingContext);
return new SharedShardContexts(indicesService, indexSearcher -> {
var queryProfiler = new QueryProfiler();
profilers.add(queryProfiler);
return new InstrumentedIndexSearcher(indexSearcher, queryProfiler);
});
} else {
return new SharedShardContexts(indicesService, UnaryOperator.identity());
}
}
use of io.crate.profile.ProfilingContext in project crate by crate.
the class RootTaskTest method testEnablingProfilingGathersExecutionTimes.
@Test
public void testEnablingProfilingGathersExecutionTimes() throws Throwable {
RootTask.Builder builder = new RootTask.Builder(logger, UUID.randomUUID(), "dummy-user", coordinatorNode, Collections.emptySet(), mock(JobsLogs.class));
ProfilingContext profilingContext = new ProfilingContext(List.of());
builder.profilingContext(profilingContext);
AbstractTaskTest.TestingTask ctx1 = new AbstractTaskTest.TestingTask(1);
builder.addTask(ctx1);
AbstractTaskTest.TestingTask ctx2 = new AbstractTaskTest.TestingTask(2);
builder.addTask(ctx2);
RootTask rootTask = builder.build();
rootTask.start();
// fake execution time so we can sure the measurement is > 0
Thread.sleep(5L);
// kill because the testing subcontexts would run infinitely
rootTask.kill(null);
assertThat(rootTask.executionTimes(), hasKey("1-TestingTask"));
assertThat(((double) rootTask.executionTimes().get("1-TestingTask")), Matchers.greaterThan(0d));
assertTrue(rootTask.executionTimes().containsKey("2-TestingTask"));
assertThat(((double) rootTask.executionTimes().get("2-TestingTask")), Matchers.greaterThan(0d));
assertThat(rootTask.completionFuture().isCompletedExceptionally(), is(true));
}
use of io.crate.profile.ProfilingContext in project crate by crate.
the class ExplainStatementAnalyzer method analyze.
public ExplainAnalyzedStatement analyze(Explain node, Analysis analysis) {
Statement statement = node.getStatement();
statement.accept(CHECK_VISITOR, null);
final AnalyzedStatement subStatement;
ProfilingContext profilingContext;
if (node.isAnalyze()) {
profilingContext = new ProfilingContext(List.of());
Timer timer = profilingContext.createAndStartTimer(ExplainPlan.Phase.Analyze.name());
subStatement = analyzer.analyzedStatement(statement, analysis);
profilingContext.stopTimerAndStoreDuration(timer);
} else {
profilingContext = null;
subStatement = analyzer.analyzedStatement(statement, analysis);
}
String columnName = SqlFormatter.formatSql(node);
return new ExplainAnalyzedStatement(columnName, subStatement, profilingContext);
}
use of io.crate.profile.ProfilingContext in project crate by crate.
the class Planner method visitExplainStatement.
@Override
public Plan visitExplainStatement(ExplainAnalyzedStatement explainAnalyzedStatement, PlannerContext context) {
ProfilingContext ctx = explainAnalyzedStatement.context();
if (ctx == null) {
return new ExplainPlan(explainAnalyzedStatement.statement().accept(this, context), null);
} else {
Timer timer = ctx.createAndStartTimer(ExplainPlan.Phase.Plan.name());
Plan subPlan = explainAnalyzedStatement.statement().accept(this, context);
ctx.stopTimerAndStoreDuration(timer);
return new ExplainPlan(subPlan, ctx);
}
}
Aggregations