use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class ConverterTest method test.
@Test
public void test() {
SampleNode testSample = testSample();
final List<StackSampleElement> samples = new ArrayList<>();
Converters.convert(Methods.ROOT, testSample, -1, 0, samples::add);
SampleNode back = Converter.convert(samples.iterator());
Assert.assertEquals(testSample, back);
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class ConverterTest method testSample.
private SampleNode testSample() {
StackTraceElement[] st1 = new StackTraceElement[3];
st1[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
st1[1] = new StackTraceElement("C1", "m2", "C1.java", 11);
st1[2] = new StackTraceElement("C1", "m3", "C1.java", 12);
SampleNode node = SampleNode.createSampleNode(st1);
StackTraceElement[] st2 = new StackTraceElement[1];
st2[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
SampleNode.addToSampleNode(node, st2);
StackTraceElement[] st3 = new StackTraceElement[3];
st3[0] = new StackTraceElement("C2", "m1", "C2.java", 10);
st3[1] = new StackTraceElement("C2", "m2", "C2.java", 11);
st3[2] = new StackTraceElement("C2", "m3", "C2.java", 12);
SampleNode.addToSampleNode(node, st3);
StackTraceElement[] st4 = new StackTraceElement[3];
st4[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
st4[1] = new StackTraceElement("C1", "m2", "C1.java", 11);
st4[2] = new StackTraceElement("C1", "m4", "C1.java", 14);
SampleNode.addToSampleNode(node, st4);
return node;
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class ConverterTest method testLoad.
@Test
public void testLoad() throws IOException {
Map<String, SampleNode> labeledDumps = Converter.loadLabeledDumps(new File("./src/test/resources/test.ssdump3"));
Assert.assertNotNull(labeledDumps);
LOG.debug("dumps", labeledDumps);
Assert.assertThat(labeledDumps.toString(), Matchers.containsString("getUnchecked@org.spf4j.concurrent.UnboundedLoadingCache"));
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class Converter method convert.
public static SampleNode convert(final Iterator<ASample> samples) {
TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
while (samples.hasNext()) {
ASample asmp = samples.next();
SampleNode sn = new SampleNode(asmp.count, new THashMap<Method, SampleNode>(4));
SampleNode parent = index.get(asmp.parentId);
if (parent != null) {
AMethod method = asmp.getMethod();
Method m = Method.getMethod(method.declaringClass, method.getName());
final Map<Method, SampleNode> subNodes = parent.getSubNodes();
if (subNodes == null) {
throw new IllegalStateException("Bug, state " + index + "; at node " + asmp);
}
subNodes.put(m, sn);
}
index.put(asmp.id, sn);
}
return index.get(0);
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class Converter method convert.
public static <E extends Exception> int convert(final Method method, final SampleNode node, final int parentId, final int id, final Handler<ASample, E> handler) throws E {
final Deque<TraversalNode> dq = new ArrayDeque<>();
dq.addLast(new TraversalNode(method, node, parentId));
int nid = id;
while (!dq.isEmpty()) {
TraversalNode first = dq.removeFirst();
Method m = first.getMethod();
ASample sample = new ASample();
sample.id = nid;
SampleNode n = first.getNode();
sample.count = n.getSampleCount();
AMethod am = new AMethod();
am.setName(m.getMethodName());
am.setDeclaringClass(m.getDeclaringClass());
sample.method = am;
sample.parentId = first.getParentId();
final TMap<Method, SampleNode> subNodes = n.getSubNodes();
final int pid = nid;
if (subNodes != null) {
subNodes.forEachEntry((a, b) -> {
dq.addLast(new TraversalNode(a, b, pid));
return true;
});
}
handler.handle(sample, parentId);
nid++;
}
return nid;
}
Aggregations