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); }
@Override public void doRun() throws InterruptedException, IOException { sampler.stop(); sampler.dumpToFile(); sampler.dispose(); }
@Override public void collect(final StackTraceElement[] stackTrace) { if (samples == null) { samples = SampleNode.createSampleNode(stackTrace); } else { SampleNode.addToSampleNode(samples, stackTrace); } }
public static SampleNode clone(final SampleNode node) { if (node.subNodes == null) { return new SampleNode(node.sampleCount, null); } final TMap<Method, SampleNode> newSubNodes = new MethodMap<>(node.subNodes.size()); node.subNodes.forEachEntry((final Method a, final SampleNode b) -> { newSubNodes.put(a, SampleNode.clone(b)); return true; }); return new SampleNode(node.sampleCount, newSubNodes); }
@Override public void testRunFinished(final Result result) throws InterruptedException { sampler.stop(); }
@Test public void testDumpDefault() throws InterruptedException, IOException { Sampler sampler = new Sampler(1); sampleTest(sampler, "stackSample"); }
public int getNrNodes() { if (samples == null) { return 0; } else { return samples.getNrNodes(); } }
public ThreadStackSampler(final int maxSampledThreads, final Supplier<Iterable<Thread>> threadSupplier) { requestFor = new Thread[maxSampledThreads]; this.threadSupplier = threadSupplier; this.collector = new StackCollectorImpl(); }
public static void traverse(final Method m, final SampleNode node, final Invocation handler, final boolean breadthFirst) { traverse(m, node, handler, breadthFirst ? Deque<TraversalData>::pollFirst : Deque<TraversalData>::pollLast); }
public Map<String, SampleNode> getStackCollections() { synchronized (sync) { return stackCollector.getCollections(); } }
public Map<String, SampleNode> getStackCollectionsAndReset() { synchronized (sync) { return stackCollector.getCollectionsAndReset(); } }
@Override public ProfiledExecutionContext start(final String name, final CharSequence id, final ExecutionContext parent, final ExecutionContext.Relation relation, final long startTimeNanos, final long deadlineNanos) { return new ProfiledExecutionContext(name, id, parent, relation, startTimeNanos, deadlineNanos); }
@Override public void add(final StackSamples samples) { synchronized (sync) { if (sampleNode == null) { sampleNode = (SampleNode) samples; } else { sampleNode.add((SampleNode) samples); } } }
public FastStackCollector(final boolean collectRunnableThreadsOnly, final boolean collectForMain, final Thread[] ignored, final String... xtraIgnoredThreads) { this(createNameBasedFilter(collectRunnableThreadsOnly, collectForMain, ignored, xtraIgnoredThreads), DEFAULT_MAX_NR_SAMPLED_THREADS); }
@Override protected Aggregator<StackResult> getIterationAggregator() { return new StackAggregator(); }
@Override protected Aggregator<NoResult> getIterationAggregator() { return new NoResultAggregator(); }
@Override public void add(final StackTraceElement[] sample) { synchronized (sync) { if (sampleNode == null) { sampleNode = SampleNode.createSampleNode(sample); } else { SampleNode.addToSampleNode(sampleNode, sample); } } }
/** * @param threadFilter when returns true the thread is being ignored */ public FastStackCollector(final Predicate<Thread> threadFilter, final int maxNrSampledThreads) { this.threadFilter = threadFilter; this.collector = new StackCollectorImpl(); this.maxNrSampledThreads = maxNrSampledThreads; }
public SimpleStackCollector(final Thread ignore) { this.ignore = ignore; this.collector = new StackCollectorImpl(); }
public MxStackCollector(final Thread ignore) { this.ignore = ignore; this.collector = new StackCollectorImpl(); }