Search in sources :

Example 1 with ProfilingContext

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());
    }
}
Also used : InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ArrayList(java.util.ArrayList) ProfilingContext(io.crate.profile.ProfilingContext) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler)

Example 2 with ProfilingContext

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());
    }
}
Also used : InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ArrayList(java.util.ArrayList) ProfilingContext(io.crate.profile.ProfilingContext) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler)

Example 3 with ProfilingContext

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));
}
Also used : ProfilingContext(io.crate.profile.ProfilingContext) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) Test(org.junit.Test)

Example 4 with ProfilingContext

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);
}
Also used : Timer(io.crate.profile.Timer) Statement(io.crate.sql.tree.Statement) ProfilingContext(io.crate.profile.ProfilingContext)

Example 5 with 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);
    }
}
Also used : Timer(io.crate.profile.Timer) ProfilingContext(io.crate.profile.ProfilingContext) CreateBlobTablePlan(io.crate.planner.node.ddl.CreateBlobTablePlan) CreateFunctionPlan(io.crate.planner.node.ddl.CreateFunctionPlan) CreateSnapshotPlan(io.crate.planner.node.ddl.CreateSnapshotPlan) AlterTableDropCheckConstraintPlan(io.crate.planner.node.ddl.AlterTableDropCheckConstraintPlan) SetSessionAuthorizationPlan(io.crate.planner.statement.SetSessionAuthorizationPlan) ResetSettingsPlan(io.crate.planner.node.ddl.ResetSettingsPlan) AlterBlobTablePlan(io.crate.planner.node.ddl.AlterBlobTablePlan) CreateUserPlan(io.crate.planner.node.ddl.CreateUserPlan) RerouteRetryFailedPlan(io.crate.planner.node.management.RerouteRetryFailedPlan) ShowCreateTablePlan(io.crate.planner.node.management.ShowCreateTablePlan) DropUserPlan(io.crate.planner.node.ddl.DropUserPlan) ExplainPlan(io.crate.planner.node.management.ExplainPlan) CopyFromPlan(io.crate.planner.statement.CopyFromPlan) AlterTableOpenClosePlan(io.crate.planner.node.ddl.AlterTableOpenClosePlan) CreateAnalyzerPlan(io.crate.planner.node.ddl.CreateAnalyzerPlan) OptimizeTablePlan(io.crate.planner.node.ddl.OptimizeTablePlan) DropRepositoryPlan(io.crate.planner.node.ddl.DropRepositoryPlan) DropAnalyzerPlan(io.crate.planner.node.ddl.DropAnalyzerPlan) AlterTableAddColumnPlan(io.crate.planner.node.ddl.AlterTableAddColumnPlan) UpdateSettingsPlan(io.crate.planner.node.ddl.UpdateSettingsPlan) AlterTablePlan(io.crate.planner.node.ddl.AlterTablePlan) AlterTableReroutePlan(io.crate.planner.node.management.AlterTableReroutePlan) AlterTableRenameTablePlan(io.crate.planner.node.ddl.AlterTableRenameTablePlan) DropSnapshotPlan(io.crate.planner.node.ddl.DropSnapshotPlan) DropFunctionPlan(io.crate.planner.node.ddl.DropFunctionPlan) SetLicensePlan(io.crate.planner.statement.SetLicensePlan) SetSessionPlan(io.crate.planner.statement.SetSessionPlan) CreateRepositoryPlan(io.crate.planner.node.ddl.CreateRepositoryPlan) CreateTablePlan(io.crate.planner.node.ddl.CreateTablePlan) GenericDCLPlan(io.crate.planner.node.dcl.GenericDCLPlan) KillPlan(io.crate.planner.node.management.KillPlan) CopyToPlan(io.crate.planner.statement.CopyToPlan) AlterUserPlan(io.crate.planner.node.ddl.AlterUserPlan) DropTablePlan(io.crate.planner.node.ddl.DropTablePlan) RestoreSnapshotPlan(io.crate.planner.node.ddl.RestoreSnapshotPlan) RefreshTablePlan(io.crate.planner.node.ddl.RefreshTablePlan) ExplainPlan(io.crate.planner.node.management.ExplainPlan)

Aggregations

ProfilingContext (io.crate.profile.ProfilingContext)5 InstrumentedIndexSearcher (io.crate.execution.jobs.InstrumentedIndexSearcher)2 SharedShardContexts (io.crate.execution.jobs.SharedShardContexts)2 Timer (io.crate.profile.Timer)2 ArrayList (java.util.ArrayList)2 QueryProfiler (org.elasticsearch.search.profile.query.QueryProfiler)2 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)1 GenericDCLPlan (io.crate.planner.node.dcl.GenericDCLPlan)1 AlterBlobTablePlan (io.crate.planner.node.ddl.AlterBlobTablePlan)1 AlterTableAddColumnPlan (io.crate.planner.node.ddl.AlterTableAddColumnPlan)1 AlterTableDropCheckConstraintPlan (io.crate.planner.node.ddl.AlterTableDropCheckConstraintPlan)1 AlterTableOpenClosePlan (io.crate.planner.node.ddl.AlterTableOpenClosePlan)1 AlterTablePlan (io.crate.planner.node.ddl.AlterTablePlan)1 AlterTableRenameTablePlan (io.crate.planner.node.ddl.AlterTableRenameTablePlan)1 AlterUserPlan (io.crate.planner.node.ddl.AlterUserPlan)1 CreateAnalyzerPlan (io.crate.planner.node.ddl.CreateAnalyzerPlan)1 CreateBlobTablePlan (io.crate.planner.node.ddl.CreateBlobTablePlan)1 CreateFunctionPlan (io.crate.planner.node.ddl.CreateFunctionPlan)1 CreateRepositoryPlan (io.crate.planner.node.ddl.CreateRepositoryPlan)1 CreateSnapshotPlan (io.crate.planner.node.ddl.CreateSnapshotPlan)1