public void printInitialStatusUpdates() { long lastPrint = System.nanoTime(); try { while (client.isValid()) { try { // exit status loop if there is there is pending output if (client.current().getData() != null) { return; } // check if time to update screen boolean update = nanosSince(lastPrint).getValue(SECONDS) >= 0.5; // check for keyboard input int key = readKey(); if (key == CTRL_P) { partialCancel(); } else if (key == CTRL_C) { updateScreen(); update = false; client.close(); } else if (toUpperCase(key) == 'D') { debug = !debug; console.resetScreen(); update = true; } // update screen if (update) { updateScreen(); lastPrint = System.nanoTime(); } // fetch next results (server will wait for a while if no data) client.advance(); } catch (RuntimeException e) { log.debug(e, "error printing status"); if (debug) { e.printStackTrace(out); } } } } finally { console.resetScreen(); } }
private void printQueryInfo(QueryResults results) { StatementStats stats = results.getStats(); Duration wallTime = nanosSince(start); // cap progress at 99%, otherwise it looks weird when the query is still running and it says // 100% int progressPercentage = (int) min(99, percentage(stats.getCompletedSplits(), stats.getTotalSplits())); if (console.isRealTerminal()) { // blank line reprintLine(""); int terminalWidth = console.getWidth(); if (terminalWidth < 75) { reprintLine("WARNING: Terminal"); reprintLine("must be at least"); reprintLine("80 characters wide"); reprintLine(""); reprintLine(stats.getState()); reprintLine(String.format("%s %d%%", formatTime(wallTime), progressPercentage)); return; } int nodes = stats.getNodes(); // Query 10, RUNNING, 1 node, 778 splits String querySummary = String.format( "Query %s, %s, %,d %s, %,d splits", results.getId(), stats.getState(), nodes, pluralize("node", nodes), stats.getTotalSplits()); reprintLine(querySummary); String url = results.getInfoUri().toString(); if (debug && (url.length() < terminalWidth)) { reprintLine(url); } if ((nodes == 0) || (stats.getTotalSplits() == 0)) { return; } if (debug) { // Splits: 620 queued, 34 running, 124 done String splitsSummary = String.format( "Splits: %,d queued, %,d running, %,d done", stats.getQueuedSplits(), stats.getRunningSplits(), stats.getCompletedSplits()); reprintLine(splitsSummary); // CPU Time: 56.5s total, 36.4K rows/s, 4.44MB/s, 60% active Duration cpuTime = millis(stats.getCpuTimeMillis()); String cpuTimeSummary = String.format( "CPU Time: %.1fs total, %5s rows/s, %8s, %d%% active", cpuTime.getValue(SECONDS), formatCountRate(stats.getProcessedRows(), cpuTime, false), formatDataRate(bytes(stats.getProcessedBytes()), cpuTime, true), (int) percentage(stats.getCpuTimeMillis(), stats.getWallTimeMillis())); reprintLine(cpuTimeSummary); double parallelism = cpuTime.getValue(MILLISECONDS) / wallTime.getValue(MILLISECONDS); // Per Node: 3.5 parallelism, 83.3K rows/s, 0.7 MB/s String perNodeSummary = String.format( "Per Node: %.1f parallelism, %5s rows/s, %8s", parallelism / nodes, formatCountRate((double) stats.getProcessedRows() / nodes, wallTime, false), formatDataRate(bytes(stats.getProcessedBytes() / nodes), wallTime, true)); reprintLine(perNodeSummary); reprintLine(String.format("Parallelism: %.1f", parallelism)); } assert terminalWidth >= 75; int progressWidth = (min(terminalWidth, 100) - 75) + 17; // progress bar is 17-42 characters wide if (stats.isScheduled()) { String progressBar = formatProgressBar( progressWidth, stats.getCompletedSplits(), max(0, stats.getRunningSplits()), stats.getTotalSplits()); // 0:17 [ 103MB, 802K rows] [5.74MB/s, 44.9K rows/s] [=====>> // ] 10% String progressLine = String.format( "%s [%5s rows, %6s] [%5s rows/s, %8s] [%s] %d%%", formatTime(wallTime), formatCount(stats.getProcessedRows()), formatDataSize(bytes(stats.getProcessedBytes()), true), formatCountRate(stats.getProcessedRows(), wallTime, false), formatDataRate(bytes(stats.getProcessedBytes()), wallTime, true), progressBar, progressPercentage); reprintLine(progressLine); } else { String progressBar = formatProgressBar( progressWidth, Ints.saturatedCast(nanosSince(start).roundTo(SECONDS))); // 0:17 [ 103MB, 802K rows] [5.74MB/s, 44.9K rows/s] [ <=> // ] String progressLine = String.format( "%s [%5s rows, %6s] [%5s rows/s, %8s] [%s]", formatTime(wallTime), formatCount(stats.getProcessedRows()), formatDataSize(bytes(stats.getProcessedBytes()), true), formatCountRate(stats.getProcessedRows(), wallTime, false), formatDataRate(bytes(stats.getProcessedBytes()), wallTime, true), progressBar); reprintLine(progressLine); } // todo Mem: 1949M shared, 7594M private // blank line reprintLine(""); // STAGE S ROWS RPS BYTES BPS QUEUED RUN DONE String stagesHeader = String.format( "%10s%1s %5s %6s %5s %7s %6s %5s %5s", "STAGE", "S", "ROWS", "ROWS/s", "BYTES", "BYTES/s", "QUEUED", "RUN", "DONE"); reprintLine(stagesHeader); printStageTree(stats.getRootStage(), "", new AtomicInteger()); } else { // Query 31 [S] i[2.7M 67.3MB 62.7MBps] o[35 6.1KB 1KBps] splits[252/16/380] String querySummary = String.format( "Query %s [%s] i[%s %s %s] o[%s %s %s] splits[%,d/%,d/%,d]", results.getId(), stats.getState(), formatCount(stats.getProcessedRows()), formatDataSize(bytes(stats.getProcessedBytes()), false), formatDataRate(bytes(stats.getProcessedBytes()), wallTime, false), formatCount(stats.getProcessedRows()), formatDataSize(bytes(stats.getProcessedBytes()), false), formatDataRate(bytes(stats.getProcessedBytes()), wallTime, false), stats.getQueuedSplits(), stats.getRunningSplits(), stats.getCompletedSplits()); reprintLine(querySummary); } }
private void reprintLine(String line) { console.reprintLine(line); }
private void updateScreen() { console.repositionCursor(); printQueryInfo(client.current()); }