Skip to content

Commit

Permalink
Add planningCpuTime stats excluding mysql-event-listener DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
weijiii authored and sopel39 committed Apr 20, 2023
1 parent 7e90112 commit a524709
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ private static QueryStats immediateFailureQueryStats()
new Duration(0, MILLISECONDS),
new Duration(0, MILLISECONDS),
new Duration(0, MILLISECONDS),
new Duration(0, MILLISECONDS),
0,
0,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public void queryImmediateFailureEvent(BasicQueryInfo queryInfo, ExecutionFailur
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
0,
0,
0,
Expand Down Expand Up @@ -304,6 +305,7 @@ private QueryStatistics createQueryStatistics(QueryInfo queryInfo)
Optional.of(ofMillis(queryStats.getResourceWaitingTime().toMillis())),
Optional.of(ofMillis(queryStats.getAnalysisTime().toMillis())),
Optional.of(ofMillis(queryStats.getPlanningTime().toMillis())),
Optional.of(ofMillis(queryStats.getPlanningCpuTime().toMillis())),
Optional.of(ofMillis(queryStats.getExecutionTime().toMillis())),
Optional.of(ofMillis(queryStats.getInputBlockedTime().toMillis())),
Optional.of(ofMillis(queryStats.getFailedInputBlockedTime().toMillis())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ private QueryStats getQueryStats(Optional<StageInfo> rootStage, List<StageInfo>
queryStateTimer.getExecutionTime(),
queryStateTimer.getAnalysisTime(),
queryStateTimer.getPlanningTime(),
queryStateTimer.getPlanningCpuTime(),
queryStateTimer.getFinishingTime(),

totalTasks,
Expand Down Expand Up @@ -1345,6 +1346,7 @@ private static QueryStats pruneQueryStats(QueryStats queryStats)
queryStats.getExecutionTime(),
queryStats.getAnalysisTime(),
queryStats.getPlanningTime(),
queryStats.getPlanningCpuTime(),
queryStats.getFinishingTime(),
queryStats.getTotalTasks(),
queryStats.getFailedTasks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.airlift.units.Duration;
import org.joda.time.DateTime;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -28,6 +30,7 @@

class QueryStateTimer
{
private static final ThreadMXBean THREAD_MX_BEAN = ManagementFactory.getThreadMXBean();
private final Ticker ticker;

private final DateTime createTime = DateTime.now();
Expand All @@ -36,6 +39,7 @@ class QueryStateTimer
private final AtomicReference<Long> beginResourceWaitingNanos = new AtomicReference<>();
private final AtomicReference<Long> beginDispatchingNanos = new AtomicReference<>();
private final AtomicReference<Long> beginPlanningNanos = new AtomicReference<>();
private final AtomicReference<Long> beginPlanningCpuNanos = new AtomicReference<>();
private final AtomicReference<Long> beginFinishingNanos = new AtomicReference<>();
private final AtomicReference<Long> endNanos = new AtomicReference<>();

Expand All @@ -44,6 +48,7 @@ class QueryStateTimer
private final AtomicReference<Duration> dispatchingTime = new AtomicReference<>();
private final AtomicReference<Duration> executionTime = new AtomicReference<>();
private final AtomicReference<Duration> planningTime = new AtomicReference<>();
private final AtomicReference<Duration> planningCpuTime = new AtomicReference<>();
private final AtomicReference<Duration> finishingTime = new AtomicReference<>();

private final AtomicReference<Long> beginAnalysisNanos = new AtomicReference<>();
Expand Down Expand Up @@ -87,25 +92,27 @@ private void beginDispatching(long now)

public void beginPlanning()
{
beginPlanning(tickerNanos());
beginPlanning(tickerNanos(), currentThreadCpuTime());
}

private void beginPlanning(long now)
private void beginPlanning(long now, long cpuNow)
{
beginDispatching(now);
dispatchingTime.compareAndSet(null, nanosSince(beginDispatchingNanos, now));
beginPlanningNanos.compareAndSet(null, now);
beginPlanningCpuNanos.compareAndSet(null, cpuNow);
}

public void beginStarting()
{
beginStarting(tickerNanos());
beginStarting(tickerNanos(), currentThreadCpuTime());
}

private void beginStarting(long now)
private void beginStarting(long now, long cpuNow)
{
beginPlanning(now);
beginPlanning(now, cpuNow);
planningTime.compareAndSet(null, nanosSince(beginPlanningNanos, now));
planningCpuTime.compareAndSet(null, nanosSince(beginPlanningCpuNanos, cpuNow));
}

public void beginRunning()
Expand All @@ -115,7 +122,7 @@ public void beginRunning()

private void beginRunning(long now)
{
beginStarting(now);
beginStarting(now, currentThreadCpuTime());
}

public void beginFinishing()
Expand Down Expand Up @@ -228,6 +235,11 @@ public Duration getPlanningTime()
return getDuration(planningTime, beginPlanningNanos);
}

public Duration getPlanningCpuTime()
{
return getDuration(planningCpuTime, beginPlanningCpuNanos);
}

public Duration getFinishingTime()
{
return getDuration(finishingTime, beginFinishingNanos);
Expand Down Expand Up @@ -303,4 +315,9 @@ private DateTime toDateTime(long instantNanos)
long millisSinceCreate = NANOSECONDS.toMillis(instantNanos - createNanos);
return new DateTime(createTime.getMillis() + millisSinceCreate);
}

private static long currentThreadCpuTime()
{
return THREAD_MX_BEAN.getCurrentThreadCpuTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class QueryStats
private final Duration executionTime;
private final Duration analysisTime;
private final Duration planningTime;
private final Duration planningCpuTime;
private final Duration finishingTime;

private final int totalTasks;
Expand Down Expand Up @@ -145,6 +146,7 @@ public QueryStats(
@JsonProperty("executionTime") Duration executionTime,
@JsonProperty("analysisTime") Duration analysisTime,
@JsonProperty("planningTime") Duration planningTime,
@JsonProperty("planningCpuTime") Duration planningCpuTime,
@JsonProperty("finishingTime") Duration finishingTime,

@JsonProperty("totalTasks") int totalTasks,
Expand Down Expand Up @@ -236,6 +238,7 @@ public QueryStats(
this.executionTime = requireNonNull(executionTime, "executionTime is null");
this.analysisTime = requireNonNull(analysisTime, "analysisTime is null");
this.planningTime = requireNonNull(planningTime, "planningTime is null");
this.planningCpuTime = requireNonNull(planningCpuTime, "planningCpuTime is null");
this.finishingTime = requireNonNull(finishingTime, "finishingTime is null");

checkArgument(totalTasks >= 0, "totalTasks is negative");
Expand Down Expand Up @@ -401,6 +404,12 @@ public Duration getPlanningTime()
return planningTime;
}

@JsonProperty
public Duration getPlanningCpuTime()
{
return planningCpuTime;
}

@JsonProperty
public Duration getFinishingTime()
{
Expand Down
2 changes: 1 addition & 1 deletion core/trino-main/src/main/resources/webapp/dist/query.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,14 @@ export class QueryDetail extends React.Component {
{query.queryStats.planningTime}
</td>
</tr>
<tr>
<td className="info-title">
Planning CPU Time
</td>
<td className="info-text">
{query.queryStats.planningCpuTime}
</td>
</tr>
<tr>
<td className="info-title">
Execution Time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public QueryInfo getFullQueryInfo()
new Duration(8, NANOSECONDS),

new Duration(100, NANOSECONDS),
new Duration(150, NANOSECONDS),
new Duration(200, NANOSECONDS),

9,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ private static void assertState(QueryStateMachine stateMachine, QueryState expec
assertNotNull(queryStats.getDispatchingTime());
assertNotNull(queryStats.getExecutionTime());
assertNotNull(queryStats.getPlanningTime());
assertNotNull(queryStats.getPlanningCpuTime());
assertNotNull(queryStats.getFinishingTime());

assertNotNull(queryStats.getCreateTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public class TestQueryStats
new Duration(33, NANOSECONDS),

new Duration(100, NANOSECONDS),
new Duration(150, NANOSECONDS),
new Duration(200, NANOSECONDS),

9,
Expand Down Expand Up @@ -300,6 +301,7 @@ public static void assertExpectedQueryStats(QueryStats actual)
assertEquals(actual.getAnalysisTime(), new Duration(33, NANOSECONDS));

assertEquals(actual.getPlanningTime(), new Duration(100, NANOSECONDS));
assertEquals(actual.getPlanningCpuTime(), new Duration(150, NANOSECONDS));
assertEquals(actual.getFinishingTime(), new Duration(200, NANOSECONDS));

assertEquals(actual.getTotalTasks(), 9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void testConstructor()
new Duration(44, MINUTES),
new Duration(9, MINUTES),
new Duration(99, SECONDS),
new Duration(1, SECONDS),
new Duration(12, MINUTES),
13,
14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private QueryInfo createQueryInfo(String queryId, QueryState state, String query
new Duration(9, MINUTES),
new Duration(10, MINUTES),
new Duration(11, MINUTES),
new Duration(1, SECONDS),
new Duration(12, MINUTES),
13,
14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class QueryStatistics
private final Optional<Duration> resourceWaitingTime;
private final Optional<Duration> analysisTime;
private final Optional<Duration> planningTime;
private final Optional<Duration> planningCpuTime;
private final Optional<Duration> executionTime;
private final Optional<Duration> inputBlockedTime;
private final Optional<Duration> failedInputBlockedTime;
Expand Down Expand Up @@ -96,6 +97,7 @@ public QueryStatistics(
Optional<Duration> resourceWaitingTime,
Optional<Duration> analysisTime,
Optional<Duration> planningTime,
Optional<Duration> planningCpuTime,
Optional<Duration> executionTime,
Optional<Duration> inputBlockedTime,
Optional<Duration> failedInputBlockedTime,
Expand Down Expand Up @@ -138,6 +140,7 @@ public QueryStatistics(
this.resourceWaitingTime = requireNonNull(resourceWaitingTime, "resourceWaitingTime is null");
this.analysisTime = requireNonNull(analysisTime, "analysisTime is null");
this.planningTime = requireNonNull(planningTime, "planningTime is null");
this.planningCpuTime = requireNonNull(planningCpuTime, "planningCpuTime is null");
this.executionTime = requireNonNull(executionTime, "executionTime is null");
this.inputBlockedTime = requireNonNull(inputBlockedTime, "inputBlockedTime is null");
this.failedInputBlockedTime = requireNonNull(failedInputBlockedTime, "failedInputBlockedTime is null");
Expand Down Expand Up @@ -226,6 +229,12 @@ public Optional<Duration> getPlanningTime()
return planningTime;
}

@JsonProperty
public Optional<Duration> getPlanningCpuTime()
{
return planningCpuTime;
}

@JsonProperty
public Optional<Duration> getExecutionTime()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public class TestHttpEventListener
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
0L,
0L,
0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class TestMysqlEventListener
Optional.of(ofMillis(107)),
Optional.of(ofMillis(108)),
Optional.of(ofMillis(109)),
Optional.of(ofMillis(1091)),
Optional.of(ofMillis(110)),
Optional.of(ofMillis(111)),
Optional.of(ofMillis(112)),
Expand Down Expand Up @@ -245,6 +246,7 @@ public class TestMysqlEventListener
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
115L,
116L,
117L,
Expand Down

0 comments on commit a524709

Please sign in to comment.