Sampler { public Sampler() { this(10, 3600000, (t) -> new FastStackCollector(false, true, new Thread[]{t})); } Sampler();  Sampler(final int sampleTimeMillis);  Sampler(final int sampleTimeMillis, final SamplerSupplier collector);  Sampler(final SamplerSupplier collector); @SuppressFBWarnings("PATH_TRAVERSAL_IN")  Sampler(final int sampleTimeMillis, final int dumpTimeMillis); @SuppressFBWarnings("PATH_TRAVERSAL_IN")  Sampler(final int sampleTimeMillis, final int dumpTimeMillis, final SamplerSupplier collector); @SuppressFBWarnings("PATH_TRAVERSAL_IN")  Sampler(final int sampleTimeMillis, final int dumpTimeMillis, final SamplerSupplier collector,
          final String dumpFolder, final String dumpFilePrefix);  Sampler(final int sampleTimeMillis, final int dumpTimeMillis, final SamplerSupplier collector,
          final File dumpFolder, final String dumpFilePrefix);  Sampler(final int sampleTimeMillis, final int dumpTimeMillis, final SamplerSupplier collector,
          final File dumpFolder, final String dumpFilePrefix, final boolean compressDumps); @Override String toString(); static synchronized Sampler getSampler(final int sampleTimeMillis,
          final int dumpTimeMillis,
          final File dumpFolder, final String dumpFilePrefix); static synchronized Sampler getSampler(final int sampleTimeMillis,
          final int dumpTimeMillis, final SamplerSupplier collector,
          final File dumpFolder, final String dumpFilePrefix); void registerJmx(); @JmxExport(description = "start stack sampling") void start(); @JmxExport boolean isCompressDumps(); @JmxExport void setCompressDumps(final boolean compressDumps); @JmxExport(description = "save stack samples to file") @Nullable File dumpToFile(); @JmxExport(value = "dumpToSpecificFile", description = "save stack samples to file") @Nullable File dumpToFile(
          @JmxExport(value = "fileID", description = "the ID that will be part of the file name")
          @Nullable final String id); @Nullable @SuppressFBWarnings("PATH_TRAVERSAL_IN") // not possible the provided ID is validated for path separators. File dumpToFile(@Nonnull final File destinationFolder, final String pbaseFileName); @JmxExport(description = "stop stack sampling") void stop(); @JmxExport(description = "stack sample time in milliseconds") int getSampleTimeMillis(); @JmxExport void setSampleTimeMillis(final int sampleTimeMillis); @JmxExport(description = "is the stack sampling stopped") boolean isStopped(); @JmxExport(description = "clear in memory collected stack samples") void clear(); Map<String, SampleNode> getStackCollectionsAndReset(); Map<String, SampleNode> getStackCollections(); @PreDestroy void dispose(); @JmxExport(description = "interval in milliseconds to save stack stamples periodically") int getDumpTimeMillis(); @JmxExport void setDumpTimeMillis(final int dumpTimeMillis); @JmxExport String getFilePrefix(); @JmxExport String getDumpFolder(); @JmxExport @SuppressForbiden // need to use an openType Date getLastDumpTime(); static final String DEFAULT_SS_DUMP_FOLDER; static final String DEFAULT_SS_DUMP_FILE_NAME_PREFIX; }
@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.hasMessageWithPattern("Stack samples written to.*")); sampler.start(); LOG.debug("started sampling"); expect.assertObservation(); sampler.stop(); }