private void listTop(String title, int[] list, int max) throws IOException { printLine('-'); int total = 0; int totalLines = 0; for (int j = 0; j < maxIndex; j++) { int l = list[j]; if (l > 0) { total += list[j]; totalLines++; } } if (max == 0) { max = totalLines; } print(title); print("Total: " + total); printLine('-'); String[] text = new String[max]; int[] index = new int[max]; for (int i = 0; i < max; i++) { int big = list[0]; int bigIndex = 0; for (int j = 1; j < maxIndex; j++) { int l = list[j]; if (l > big) { big = l; bigIndex = j; } } list[bigIndex] = -(big + 1); index[i] = bigIndex; } FileReader reader = null; try { reader = new FileReader("profile.txt"); LineNumberReader r = new LineNumberReader(reader); for (int i = 0; i < maxIndex; i++) { String line = r.readLine(); int k = list[i]; if (k < 0) { k = -(k + 1); list[i] = k; for (int j = 0; j < max; j++) { if (index[j] == i) { int percent = 100 * k / total; text[j] = k + " " + percent + "%: " + line; } } } } for (int i = 0; i < max; i++) { print(text[i]); } } finally { closeSilently(reader); } }
private void listUnvisited() throws IOException { printLine('='); print("NOT COVERED"); printLine('-'); FileReader reader = null; FileWriter fileWriter = null; try { reader = new FileReader("profile.txt"); LineNumberReader r = new LineNumberReader(reader); fileWriter = new FileWriter("notCovered.txt"); BufferedWriter writer = new BufferedWriter(fileWriter); int unvisited = 0; int unvisitedThrow = 0; for (int i = 0; i < maxIndex; i++) { String line = r.readLine(); if (count[i] == 0) { if (!line.endsWith("throw")) { writer.write(line + "\r\n"); if (LIST_UNVISITED) { print(line + "\r\n"); } unvisited++; } else { unvisitedThrow++; } } } int percent = 100 * unvisited / maxIndex; print( "Not covered: " + percent + " % " + " (" + unvisited + " of " + maxIndex + "; throw=" + unvisitedThrow + ")"); } finally { closeSilently(fileWriter); closeSilently(reader); } }
private Profile() { FileReader reader = null; try { reader = new FileReader("profile.txt"); LineNumberReader r = new LineNumberReader(reader); while (r.readLine() != null) { // nothing - just count lines } maxIndex = r.getLineNumber(); count = new int[maxIndex]; time = new int[maxIndex]; lastTime = System.currentTimeMillis(); Runtime.getRuntime().addShutdownHook(this); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { closeSilently(reader); } }