private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed try { sampler = Sampler.getSampler(10, 100000, new File("."), "dump"); sampler.start(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); } }//GEN-LAST:event_jMenuItem1ActionPerformed
public static synchronized Sampler getSampler(final int sampleTimeMillis, final int dumpTimeMillis, final File dumpFolder, final String dumpFilePrefix) throws InterruptedException { return getSampler(sampleTimeMillis, dumpTimeMillis, (t) -> new FastStackCollector(false, true, new Thread[]{t}), dumpFolder, dumpFilePrefix); }
@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(); }
@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(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 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); }
@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); }