public synchronized QueryInfo getQueryInfo(StageInfo rootStage)
{
QueryState state = queryState.get();
Duration elapsedTime;
if (endTime != null) {
elapsedTime = new Duration(endTime.getMillis() - createTime.getMillis(), MILLISECONDS);
}
else {
elapsedTime = Duration.nanosSince(createNanos);
}
// don't report failure info is query is marked as success
FailureInfo failureInfo = null;
if (state != FINISHED) {
failureInfo = toFailure(failureCause);
}
int totalTasks = 0;
int runningTasks = 0;
int completedTasks = 0;
int totalDrivers = 0;
int queuedDrivers = 0;
int runningDrivers = 0;
int completedDrivers = 0;
long totalMemoryReservation = 0;
long totalScheduledTime = 0;
long totalCpuTime = 0;
long totalUserTime = 0;
long totalBlockedTime = 0;
long rawInputDataSize = 0;
long rawInputPositions = 0;
long processedInputDataSize = 0;
long processedInputPositions = 0;
long outputDataSize = 0;
long outputPositions = 0;
if (rootStage != null) {
for (StageInfo stageInfo : getAllStages(rootStage)) {
StageStats stageStats = stageInfo.getStageStats();
totalTasks += stageStats.getTotalTasks();
runningTasks += stageStats.getRunningTasks();
completedTasks += stageStats.getCompletedTasks();
totalDrivers += stageStats.getTotalDrivers();
queuedDrivers += stageStats.getQueuedDrivers();
runningDrivers += stageStats.getRunningDrivers();
completedDrivers += stageStats.getCompletedDrivers();
totalMemoryReservation += stageStats.getTotalMemoryReservation().toBytes();
totalScheduledTime += stageStats.getTotalScheduledTime().roundTo(NANOSECONDS);
totalCpuTime += stageStats.getTotalCpuTime().roundTo(NANOSECONDS);
totalUserTime += stageStats.getTotalUserTime().roundTo(NANOSECONDS);
totalBlockedTime += stageStats.getTotalBlockedTime().roundTo(NANOSECONDS);
if (stageInfo.getSubStages().isEmpty()) {
rawInputDataSize += stageStats.getRawInputDataSize().toBytes();
rawInputPositions += stageStats.getRawInputPositions();
processedInputDataSize += stageStats.getProcessedInputDataSize().toBytes();
processedInputPositions += stageStats.getProcessedInputPositions();
}
}
StageStats outputStageStats = rootStage.getStageStats();
outputDataSize += outputStageStats.getOutputDataSize().toBytes();
outputPositions += outputStageStats.getOutputPositions();
}
QueryStats queryStats = new QueryStats(
createTime,
executionStartTime,
lastHeartbeat,
endTime,
elapsedTime.convertToMostSuccinctTimeUnit(),
queuedTime,
analysisTime,
distributedPlanningTime,
totalPlanningTime,
totalTasks,
runningTasks,
completedTasks,
totalDrivers,
queuedDrivers,
runningDrivers,
completedDrivers,
new DataSize(totalMemoryReservation, BYTE).convertToMostSuccinctDataSize(),
new Duration(totalScheduledTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
new Duration(totalCpuTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
new Duration(totalUserTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
new Duration(totalBlockedTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
new DataSize(rawInputDataSize, BYTE).convertToMostSuccinctDataSize(),
rawInputPositions,
new DataSize(processedInputDataSize, BYTE).convertToMostSuccinctDataSize(),
processedInputPositions,
new DataSize(outputDataSize, BYTE).convertToMostSuccinctDataSize(),