@Override public void testRunFinished(final Result result) throws InterruptedException { sampler.stop(); }
@PreDestroy public void dispose() throws InterruptedException { stop(); Registry.unregister(this); }
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed if (sampler != null) { try { sampler.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); } Map<String, SampleNode> samples = sampler.getStackCollectionsAndReset(); for (Map.Entry<String, SampleNode> entry : samples.entrySet()) { try { setFrames(entry.getValue(), "self:" + entry.getKey()); } catch (IOException ex) { throw new UncheckedIOException(ex); } } } }//GEN-LAST:event_jMenuItem2ActionPerformed
@Override public void doRun() throws InterruptedException, IOException { sampler.stop(); sampler.dumpToFile(); sampler.dispose(); }
@Override @Nonnull public Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult ir) { try { SAMPLER.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); return Collections.EMPTY_LIST; } Map<String, SampleNode> c = SAMPLER.getStackCollectionsAndReset(); if (c.isEmpty()) { return Collections.EMPTY_LIST; } SampleNode collected = c.values().iterator().next(); try { return Collections.singletonList(new StackResult(collected, benchmarkParams.id(), true)); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
final IterationParams iterationParams, final IterationResult ir) { try { SAMPLER.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt();
@Test public void testSampler2() throws InterruptedException, IOException { Sampler sampler = Sampler.getSampler(5, 2000, new File(org.spf4j.base.Runtime.TMP_FOLDER), "test"); sampler.start(); File dumpToFile = sampler.dumpToFile("id"); LOG.debug("saved to file {}", dumpToFile); Assert.assertThat(dumpToFile.getAbsolutePath(), Matchers.not(Matchers.containsString(":"))); sampler.stop(); }
public Map<String, SampleNode> sampleTest(final Sampler sampler, final String filename) throws InterruptedException, IOException { sampler.registerJmx(); sampler.start(); MonitorTest.main(new String[]{}); final File serializedFile = File.createTempFile(filename, ".ssdump3"); Map<String, SampleNode> collected = sampler.getStackCollectionsAndReset(); Converter.saveLabeledDumps(serializedFile, collected); LOG.debug("Dumped to file {}", serializedFile); sampler.stop(); Map<String, SampleNode> loadedDumps = Converter.loadLabeledDumps(serializedFile); for (Map.Entry<String, SampleNode> entry : loadedDumps.entrySet()) { LOG.debug("Loaded {}", entry.getKey()); } return collected; } }
@Test public void testSampler() throws InterruptedException { Sampler sampler = Sampler.getSampler(5, 2000, new File(org.spf4j.base.Runtime.TMP_FOLDER), "test"); LogAssert expect = TestLoggers.sys() .expect(Sampler.class.getName(), Level.INFO, 5000, TimeUnit.MILLISECONDS, LogMatchers.hasFormat("Stack samples written to {}")); sampler.start(); LOG.debug("started sampling"); expect.assertObservation(); sampler.stop(); }
@Test public void testJmx() throws InterruptedException, IOException { Sampler sampler = new Sampler((t) -> new SimpleStackCollector(t)); sampler.registerJmx(); sampler.start(); main(new String[]{}); sampler.stop(); SampleNode original = sampler.getStackCollections().values().iterator().next(); File file = sampler.dumpToFile(); LOG.debug("Samples saved to {}", file); Assert.assertNotNull(file); Assert.assertTrue(file.exists()); SampleNode loaded = Converter.load(file); Assert.assertEquals(original, loaded); sampler.stop(); }
@SuppressFBWarnings("MDM_THREAD_YIELD") public static void main(final String[] args) throws InterruptedException, TimeoutException, SQLException, IOException { String connectionString = args[0]; String semaphoreName = args[1]; JdbcDataSource ds = new JdbcDataSource(); ds.setURL(connectionString); ds.setUser("sa"); ds.setPassword("sa"); Sampler s = new Sampler(5, 10000); s.registerJmx(); s.start(); LOG.info("started sampling"); JdbcSemaphore semaphore = new JdbcSemaphore(ds, semaphoreName, 3); for (int i = 0; i < 50; i++) { semaphore.acquire(1, 1L, TimeUnit.SECONDS); Thread.sleep((long) (Math.random() * 10) + 10); LOG.info("beat"); Thread.sleep((long) (Math.random() * 10) + 10); semaphore.release(); } semaphore.close(); File dumpToFile = s.dumpToFile(); LOG.info("stack samples dumped to {}", dumpToFile); s.stop(); System.exit(0); }
@Test(timeout = 60000) public void testLifoExecSQ() throws InterruptedException, IOException { LifoThreadPoolExecutorSQP executor = new LifoThreadPoolExecutorSQP("test", 2, 8, 20, 0); File destFolder = new File(org.spf4j.base.Runtime.TMP_FOLDER); Sampler s = Sampler.getSampler(20, 10000, destFolder, "lifeTest1"); s.start(); org.spf4j.base.Runtime.gc(5000); Thread.sleep(100); long time = CpuUsageSampler.getProcessCpuTimeNanos(); Thread.sleep(3000); long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time; File dumpToFile = s.dumpToFile(); Assert.assertEquals(destFolder.getCanonicalFile(), dumpToFile.getParentFile().getCanonicalFile()); LOG.info("Cpu profile saved to {}", dumpToFile); LOG.debug("CPU time = {} ns", cpuTime); s.stop(); Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000); // 6069497000 with bug 53945000/8035000/6000000 without bug without profiler, 119628000 with profiler executor.shutdown(); executor.awaitTermination(1, TimeUnit.SECONDS); }
@Test(timeout = 60000) public void testLifoExecSQ2() throws InterruptedException, IOException, ExecutionException { LifoThreadPoolExecutorSQP executor = new LifoThreadPoolExecutorSQP("test", 2, 8, 20, 0); File destFolder = new File(org.spf4j.base.Runtime.TMP_FOLDER); Sampler s = Sampler.getSampler(20, 10000, destFolder, "lifeTest1"); s.start(); org.spf4j.base.Runtime.gc(5000); List<Runnable> running = executor.shutdownNow(); Assert.assertTrue(running.isEmpty()); Thread.sleep(100); long time = CpuUsageSampler.getProcessCpuTimeNanos(); Thread.sleep(3000); long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time; File dumpToFile = s.dumpToFile(); Assert.assertEquals(destFolder.getCanonicalFile(), dumpToFile.getParentFile().getCanonicalFile()); LOG.info("Cpu profile saved to {}", dumpToFile); LOG.debug("CPU time = {} ns", cpuTime); s.stop(); Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000); // 3260523000 with bug 148672000 without bug with profiler executor.shutdown(); executor.awaitTermination(1, TimeUnit.SECONDS); }
@Test(timeout = 60000) public void testLifoExecSQ() throws InterruptedException, IOException, ExecutionException { LifoThreadPoolExecutorSQP executor = new LifoThreadPoolExecutorSQP("test", 2, 8, 20, 0); File destFolder = new File(org.spf4j.base.Runtime.TMP_FOLDER); Sampler s = Sampler.getSampler(20, 10000, destFolder, "lifeTest1"); s.start(); org.spf4j.base.Runtime.gc(5000); ArrayBlockingQueue<Thread> q = new ArrayBlockingQueue<>(1); Future<Object> f = executor.submit(() -> { q.put(Thread.currentThread()); return null; }); q.take().interrupt(); Assert.assertNull(f.get()); Thread.sleep(100); long time = CpuUsageSampler.getProcessCpuTimeNanos(); Thread.sleep(3000); long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time; File dumpToFile = s.dumpToFile(); Assert.assertEquals(destFolder.getCanonicalFile(), dumpToFile.getParentFile().getCanonicalFile()); LOG.info("Cpu profile saved to {}", dumpToFile); LOG.debug("CPU time = {} ns", cpuTime); s.stop(); Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000); // 3260523000 with bug 148672000 without bug with profiler executor.shutdown(); executor.awaitTermination(1, TimeUnit.SECONDS); }
} while (deadline > TimeSource.nanoTime()); semaphore.close(); s.stop(); LOG.debug("dumped samples to {}", s.dumpToFile()); } finally {