/** * Get the top stack traces. * * @param count the maximum number of stack traces * @return the stack traces. */ public String getTop(int count) { stopCollecting(); return getTopTraces(count); }
private static List<Object[]> readRunnableStackTraces(int pid) { try { String jstack = exec("jstack", "" + pid); LineNumberReader r = new LineNumberReader( new StringReader(jstack)); return readStackTrace(r); } catch (IOException e) { throw new RuntimeException(e); } }
public void startProfiler() { profiler = new Profiler().startCollecting(); }
" <pid> | <stackTraceFileNames>"); System.out.println("Processes:"); String processes = exec("jps", "-l"); System.out.println(processes); return; long last = 0; while (true) { tick(); long t = System.currentTimeMillis(); if (t - last > 5000) { time = System.currentTimeMillis() - start; System.out.println(getTopTraces(3)); last = t; new FileInputStream(file), "CP1252"); r = new LineNumberReader(reader); processList(readStackTrace(r)); reader.close(); System.out.println(getTopTraces(5)); } catch (IOException e) { throw new RuntimeException(e);
private void tick() { if (interval > 0) { if (paused) { return; } try { Thread.sleep(interval); } catch (Exception e) { // ignore } } List<Object[]> list; if (pid != 0) { list = readRunnableStackTraces(pid); } else { list = getRunnableStackTraces(); } threadDumps++; processList(list); }
private void processList(List<Object[]> list) { for (Object[] dump : list) { if (startsWithAny(dump[0].toString(), ignoreThreads)) { continue; for (int j = 0, i = 0; i < dump.length && j < depth; i++) { String el = dump[i].toString(); if (!el.equals(last) && !startsWithAny(el, ignoreLines)) { last = el; buff.append("at ").append(el).append(LINE_SEPARATOR); if (!packageCounts && !startsWithAny(el, ignorePackages)) { packageCounts = true; int index = 0; increment(summary, groupName, 0); minCount = increment(counts, buff.toString().trim(), minCount); total++;
public void stopProfiler() { if (profiler != null) { LOG.info(profiler.stopCollecting().getTop(5)); profiler = null; } }
private static String exec(String... args) { ByteArrayOutputStream err = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Process p = Runtime.getRuntime().exec(args); copyInThread(p.getInputStream(), out); copyInThread(p.getErrorStream(), err); p.waitFor(); String e = new String(err.toByteArray(), "UTF-8"); if (e.length() > 0) { throw new RuntimeException(e); } String output = new String(out.toByteArray(), "UTF-8"); return output; } catch (Exception e) { throw new RuntimeException(e); } }
private String getTopTraces(int count) { StringBuilder buff = new StringBuilder(); buff.append("Profiler: top ").append(count).append(" stack trace(s) of "); if (time > 0) { buff.append(" of ").append(time).append(" ms"); } if (threadDumps > 0) { buff.append(" of ").append(threadDumps).append(" thread dumps"); } buff.append(":").append(LINE_SEPARATOR); if (counts.size() == 0) { buff.append("(none)").append(LINE_SEPARATOR); } HashMap<String, Integer> copy = new HashMap<String, Integer>(counts); appendTop(buff, copy, count, total, false); buff.append("summary:").append(LINE_SEPARATOR); copy = new HashMap<String, Integer>(summary); appendTop(buff, copy, count, total, true); buff.append('.'); return buff.toString(); }
" <pid> | <stackTraceFileNames>"); System.out.println("Processes:"); String processes = exec("jps", "-l"); System.out.println(processes); return; long last = 0; while (true) { tick(); long t = System.currentTimeMillis(); if (t - last > 5000) { time = System.currentTimeMillis() - start; System.out.println(getTopTraces(3)); last = t; new FileInputStream(file), "CP1252"); r = new LineNumberReader(reader); processList(readStackTrace(r)); reader.close(); System.out.println(getTopTraces(5)); } catch (IOException e) { throw new RuntimeException(e);
private void tick() { if (interval > 0) { if (paused) { return; } try { Thread.sleep(interval); } catch (Exception e) { // ignore } } List<Object[]> list; if (pid != 0) { list = readRunnableStackTraces(pid); } else { list = getRunnableStackTraces(); } threadDumps++; processList(list); }
private void processList(List<Object[]> list) { for (Object[] dump : list) { if (startsWithAny(dump[0].toString(), ignoreThreads)) { continue; for (int j = 0, i = 0; i < dump.length && j < depth; i++) { String el = dump[i].toString(); if (!el.equals(last) && !startsWithAny(el, ignoreLines)) { last = el; buff.append("at ").append(el).append(LINE_SEPARATOR); if (!packageCounts && !startsWithAny(el, ignorePackages)) { packageCounts = true; int index = 0; increment(summary, groupName, 0); minCount = increment(counts, buff.toString().trim(), minCount); total++;
/** * Cleans up after this performance benchmark. * * @throws Exception if the benchmark can not be cleaned up */ public void tearDown() throws Exception { issueHaltChildThreads(); this.running = false; for (Thread thread : threads) { thread.join(); } if (profiler != null) { System.out.println(profiler.stopCollecting().getTop(5)); profiler = null; } afterSuite(); for (Session session : sessions) { if (session.isLive()) { session.logout(); } } this.threads = null; this.sessions = null; this.credentials = null; this.repository = null; }
/** * Prepares this performance benchmark. * * @param repository the repository to use * @param credentials credentials of a user with write access * @throws Exception if the benchmark can not be prepared */ public void setUp(Repository repository, Credentials credentials) throws Exception { this.repository = repository; this.credentials = credentials; this.sessions = new LinkedList<Session>(); this.threads = new LinkedList<Thread>(); this.running = true; haltRequested = false; beforeSuite(); if (PROFILE) { profiler = new Profiler().startCollecting(); } }
private static String exec(String... args) { ByteArrayOutputStream err = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Process p = Runtime.getRuntime().exec(args); copyInThread(p.getInputStream(), out); copyInThread(p.getErrorStream(), err); p.waitFor(); String e = new String(err.toByteArray(), "UTF-8"); if (e.length() > 0) { throw new RuntimeException(e); } String output = new String(out.toByteArray(), "UTF-8"); return output; } catch (Exception e) { throw new RuntimeException(e); } }
private String getTopTraces(int count) { StringBuilder buff = new StringBuilder(); buff.append("Profiler: top ").append(count).append(" stack trace(s) of "); if (time > 0) { buff.append(" of ").append(time).append(" ms"); } if (threadDumps > 0) { buff.append(" of ").append(threadDumps).append(" thread dumps"); } buff.append(":").append(LINE_SEPARATOR); if (counts.size() == 0) { buff.append("(none)").append(LINE_SEPARATOR); } HashMap<String, Integer> copy = new HashMap<String, Integer>(counts); appendTop(buff, copy, count, total, false); buff.append("summary:").append(LINE_SEPARATOR); copy = new HashMap<String, Integer>(summary); appendTop(buff, copy, count, total, true); buff.append('.'); return buff.toString(); }
" <pid> | <stackTraceFileNames>"); System.out.println("Processes:"); String processes = exec("jps", "-l"); System.out.println(processes); return; long last = 0; while (true) { tick(); long t = System.currentTimeMillis(); if (t - last > 5000) { time = System.currentTimeMillis() - start; System.out.println(getTopTraces(3)); last = t; new FileInputStream(file), "CP1252"); r = new LineNumberReader(reader); processList(readStackTrace(r)); reader.close(); System.out.println(getTopTraces(5)); } catch (IOException e) { throw new RuntimeException(e);
private void tick() { if (interval > 0) { if (paused) { return; } try { Thread.sleep(interval); } catch (Exception e) { // ignore } } List<Object[]> list; if (pid != 0) { list = readRunnableStackTraces(pid); } else { list = getRunnableStackTraces(); } threadDumps++; processList(list); }
/** * Get the top stack traces. * * @param count the maximum number of stack traces * @return the stack traces. */ public String getTop(int count) { stopCollecting(); return getTopTraces(count); }