private StageInfo buildStageInfo(StageId stageId, Map<StageId, StageInfo> stageInfos) { StageInfo parent = stageInfos.get(stageId); checkArgument(parent != null, "No stageInfo for %s", parent); List<StageInfo> childStages = stageLinkages .get(stageId) .getChildStageIds() .stream() .map(childStageId -> buildStageInfo(childStageId, stageInfos)) .collect(toImmutableList()); if (childStages.isEmpty()) { return parent; } return new StageInfo( parent.getStageId(), parent.getState(), parent.getSelf(), parent.getPlan(), parent.getTypes(), parent.getStageStats(), parent.getTasks(), childStages, parent.getFailureCause()); }
private void logQueryTimeline(QueryInfo queryInfo) { try { QueryStats queryStats = queryInfo.getQueryStats(); DateTime queryStartTime = queryStats.getCreateTime(); DateTime queryEndTime = queryStats.getEndTime(); // query didn't finish cleanly if (queryStartTime == null || queryEndTime == null) { return; } // planning duration -- start to end of planning Duration planning = queryStats.getTotalPlanningTime(); if (planning == null) { planning = new Duration(0, MILLISECONDS); } List<StageInfo> stages = StageInfo.getAllStages(queryInfo.getOutputStage()); // long lastSchedulingCompletion = 0; long firstTaskStartTime = queryEndTime.getMillis(); long lastTaskStartTime = queryStartTime.getMillis() + planning.toMillis(); long lastTaskEndTime = queryStartTime.getMillis() + planning.toMillis(); for (StageInfo stage : stages) { // only consider leaf stages if (!stage.getSubStages().isEmpty()) { continue; } for (TaskInfo taskInfo : stage.getTasks()) { TaskStats taskStats = taskInfo.getStats(); DateTime firstStartTime = taskStats.getFirstStartTime(); if (firstStartTime != null) { firstTaskStartTime = Math.min(firstStartTime.getMillis(), firstTaskStartTime); } DateTime lastStartTime = taskStats.getLastStartTime(); if (lastStartTime != null) { lastTaskStartTime = Math.max(lastStartTime.getMillis(), lastTaskStartTime); } DateTime endTime = taskStats.getEndTime(); if (endTime != null) { lastTaskEndTime = Math.max(endTime.getMillis(), lastTaskEndTime); } } } Duration elapsed = millis(queryEndTime.getMillis() - queryStartTime.getMillis()); Duration scheduling = millis(firstTaskStartTime - queryStartTime.getMillis() - planning.toMillis()); Duration running = millis(lastTaskEndTime - firstTaskStartTime); Duration finishing = millis(queryEndTime.getMillis() - lastTaskEndTime); log.info( "TIMELINE: Query %s :: elapsed %s :: planning %s :: scheduling %s :: running %s :: finishing %s :: begin %s :: end %s", queryInfo.getQueryId(), elapsed, planning, scheduling, running, finishing, queryStartTime, queryEndTime); } catch (Exception e) { log.error(e, "Error logging query timeline"); } }