use of io.trino.sql.planner.PlanFragment in project trino by trinodb.
the class QueryStateMachine method getQueryStats.
private QueryStats getQueryStats(Optional<StageInfo> rootStage) {
int totalTasks = 0;
int runningTasks = 0;
int completedTasks = 0;
int failedTasks = 0;
int totalDrivers = 0;
int queuedDrivers = 0;
int runningDrivers = 0;
int blockedDrivers = 0;
int completedDrivers = 0;
long cumulativeUserMemory = 0;
long failedCumulativeUserMemory = 0;
long userMemoryReservation = 0;
long revocableMemoryReservation = 0;
long totalMemoryReservation = 0;
long totalScheduledTime = 0;
long failedScheduledTime = 0;
long totalCpuTime = 0;
long failedCpuTime = 0;
long totalBlockedTime = 0;
long physicalInputDataSize = 0;
long failedPhysicalInputDataSize = 0;
long physicalInputPositions = 0;
long failedPhysicalInputPositions = 0;
long physicalInputReadTime = 0;
long failedPhysicalInputReadTime = 0;
long internalNetworkInputDataSize = 0;
long failedInternalNetworkInputDataSize = 0;
long internalNetworkInputPositions = 0;
long failedInternalNetworkInputPositions = 0;
long rawInputDataSize = 0;
long failedRawInputDataSize = 0;
long rawInputPositions = 0;
long failedRawInputPositions = 0;
long processedInputDataSize = 0;
long failedProcessedInputDataSize = 0;
long processedInputPositions = 0;
long failedProcessedInputPositions = 0;
long outputDataSize = 0;
long failedOutputDataSize = 0;
long outputPositions = 0;
long failedOutputPositions = 0;
long physicalWrittenDataSize = 0;
long failedPhysicalWrittenDataSize = 0;
ImmutableList.Builder<StageGcStatistics> stageGcStatistics = ImmutableList.builder();
boolean fullyBlocked = rootStage.isPresent();
Set<BlockedReason> blockedReasons = new HashSet<>();
ImmutableList.Builder<OperatorStats> operatorStatsSummary = ImmutableList.builder();
boolean completeInfo = true;
for (StageInfo stageInfo : getAllStages(rootStage)) {
StageStats stageStats = stageInfo.getStageStats();
totalTasks += stageStats.getTotalTasks();
runningTasks += stageStats.getRunningTasks();
completedTasks += stageStats.getCompletedTasks();
failedTasks += stageStats.getFailedTasks();
totalDrivers += stageStats.getTotalDrivers();
queuedDrivers += stageStats.getQueuedDrivers();
runningDrivers += stageStats.getRunningDrivers();
blockedDrivers += stageStats.getBlockedDrivers();
completedDrivers += stageStats.getCompletedDrivers();
cumulativeUserMemory += stageStats.getCumulativeUserMemory();
failedCumulativeUserMemory += stageStats.getFailedCumulativeUserMemory();
userMemoryReservation += stageStats.getUserMemoryReservation().toBytes();
revocableMemoryReservation += stageStats.getRevocableMemoryReservation().toBytes();
totalMemoryReservation += stageStats.getTotalMemoryReservation().toBytes();
totalScheduledTime += stageStats.getTotalScheduledTime().roundTo(MILLISECONDS);
failedScheduledTime += stageStats.getFailedScheduledTime().roundTo(MILLISECONDS);
totalCpuTime += stageStats.getTotalCpuTime().roundTo(MILLISECONDS);
failedCpuTime += stageStats.getFailedCpuTime().roundTo(MILLISECONDS);
totalBlockedTime += stageStats.getTotalBlockedTime().roundTo(MILLISECONDS);
if (!stageInfo.getState().isDone()) {
fullyBlocked &= stageStats.isFullyBlocked();
blockedReasons.addAll(stageStats.getBlockedReasons());
}
physicalInputDataSize += stageStats.getPhysicalInputDataSize().toBytes();
failedPhysicalInputDataSize += stageStats.getFailedPhysicalInputDataSize().toBytes();
physicalInputPositions += stageStats.getPhysicalInputPositions();
failedPhysicalInputPositions += stageStats.getFailedPhysicalInputPositions();
physicalInputReadTime += stageStats.getPhysicalInputReadTime().roundTo(MILLISECONDS);
failedPhysicalInputReadTime += stageStats.getFailedPhysicalInputReadTime().roundTo(MILLISECONDS);
internalNetworkInputDataSize += stageStats.getInternalNetworkInputDataSize().toBytes();
failedInternalNetworkInputDataSize += stageStats.getFailedInternalNetworkInputDataSize().toBytes();
internalNetworkInputPositions += stageStats.getInternalNetworkInputPositions();
failedInternalNetworkInputPositions += stageStats.getFailedInternalNetworkInputPositions();
PlanFragment plan = stageInfo.getPlan();
if (plan != null && plan.getPartitionedSourceNodes().stream().anyMatch(TableScanNode.class::isInstance)) {
rawInputDataSize += stageStats.getRawInputDataSize().toBytes();
failedRawInputDataSize += stageStats.getFailedRawInputDataSize().toBytes();
rawInputPositions += stageStats.getRawInputPositions();
failedRawInputPositions += stageStats.getFailedRawInputPositions();
processedInputDataSize += stageStats.getProcessedInputDataSize().toBytes();
failedProcessedInputDataSize += stageStats.getFailedProcessedInputDataSize().toBytes();
processedInputPositions += stageStats.getProcessedInputPositions();
failedProcessedInputPositions += stageStats.getFailedProcessedInputPositions();
}
physicalWrittenDataSize += stageStats.getPhysicalWrittenDataSize().toBytes();
failedPhysicalWrittenDataSize += stageStats.getFailedPhysicalWrittenDataSize().toBytes();
stageGcStatistics.add(stageStats.getGcInfo());
completeInfo = completeInfo && stageInfo.isCompleteInfo();
operatorStatsSummary.addAll(stageInfo.getStageStats().getOperatorSummaries());
}
if (rootStage.isPresent()) {
StageStats outputStageStats = rootStage.get().getStageStats();
outputDataSize += outputStageStats.getOutputDataSize().toBytes();
failedOutputDataSize += outputStageStats.getFailedOutputDataSize().toBytes();
outputPositions += outputStageStats.getOutputPositions();
failedOutputPositions += outputStageStats.getFailedOutputPositions();
}
boolean isScheduled = isScheduled(rootStage);
return new QueryStats(queryStateTimer.getCreateTime(), getExecutionStartTime().orElse(null), getLastHeartbeat(), getEndTime().orElse(null), queryStateTimer.getElapsedTime(), queryStateTimer.getQueuedTime(), queryStateTimer.getResourceWaitingTime(), queryStateTimer.getDispatchingTime(), queryStateTimer.getExecutionTime(), queryStateTimer.getAnalysisTime(), queryStateTimer.getPlanningTime(), queryStateTimer.getFinishingTime(), totalTasks, runningTasks, completedTasks, failedTasks, totalDrivers, queuedDrivers, runningDrivers, blockedDrivers, completedDrivers, cumulativeUserMemory, failedCumulativeUserMemory, succinctBytes(userMemoryReservation), succinctBytes(revocableMemoryReservation), succinctBytes(totalMemoryReservation), succinctBytes(getPeakUserMemoryInBytes()), succinctBytes(getPeakRevocableMemoryInBytes()), succinctBytes(getPeakTotalMemoryInBytes()), succinctBytes(getPeakTaskUserMemory()), succinctBytes(getPeakTaskRevocableMemory()), succinctBytes(getPeakTaskTotalMemory()), isScheduled, new Duration(totalScheduledTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), new Duration(failedScheduledTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), new Duration(totalCpuTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), new Duration(failedCpuTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), new Duration(totalBlockedTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), fullyBlocked, blockedReasons, succinctBytes(physicalInputDataSize), succinctBytes(failedPhysicalInputDataSize), physicalInputPositions, failedPhysicalInputPositions, new Duration(physicalInputReadTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), new Duration(failedPhysicalInputReadTime, MILLISECONDS).convertToMostSuccinctTimeUnit(), succinctBytes(internalNetworkInputDataSize), succinctBytes(failedInternalNetworkInputDataSize), internalNetworkInputPositions, failedInternalNetworkInputPositions, succinctBytes(rawInputDataSize), succinctBytes(failedRawInputDataSize), rawInputPositions, failedRawInputPositions, succinctBytes(processedInputDataSize), succinctBytes(failedProcessedInputDataSize), processedInputPositions, failedProcessedInputPositions, succinctBytes(outputDataSize), succinctBytes(failedOutputDataSize), outputPositions, failedOutputPositions, succinctBytes(physicalWrittenDataSize), succinctBytes(failedPhysicalWrittenDataSize), stageGcStatistics.build(), getDynamicFiltersStats(), operatorStatsSummary.build());
}
Aggregations