use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class Converter method saveLabeledDumps.
public static void saveLabeledDumps(final File file, final Map<String, SampleNode> pcollected) throws IOException {
try (OutputStream bos = newOutputStream(file)) {
final SpecificDatumWriter<StackSampleElement> writer = new SpecificDatumWriter<>(StackSampleElement.SCHEMA$);
final BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder(bos, null);
encoder.writeMapStart();
final Map<String, SampleNode> collected = pcollected.entrySet().stream().filter((e) -> e.getValue() != null).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()));
encoder.setItemCount(collected.size());
for (Map.Entry<String, SampleNode> entry : collected.entrySet()) {
encoder.startItem();
encoder.writeString(entry.getKey());
encoder.writeArrayStart();
Converters.convert(Methods.ROOT, entry.getValue(), -1, 0, (final StackSampleElement object) -> {
try {
encoder.setItemCount(1L);
encoder.startItem();
writer.write(object, encoder);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
encoder.writeArrayEnd();
}
encoder.writeMapEnd();
encoder.flush();
}
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class ComparisonStackDumpJInternalFrame method updateSampleNode.
private void updateSampleNode() throws IOException {
SampleNode sampleNodeA = samplesSupplierA.getSamples((String) contextSelectorA.getSelectedItem(), (String) tagsSelectorA.getSelectedItem(), aSpinners.start.getDate().toInstant(), aSpinners.end.getDate().toInstant());
SampleNode sampleNodeB = samplesSupplierB.getSamples((String) contextSelectorB.getSelectedItem(), (String) tagsSelectorB.getSelectedItem(), bSpinners.start.getDate().toInstant(), bSpinners.end.getDate().toInstant());
this.samples = SampleNode.diffAnnotate(Methods.ROOT, sampleNodeA, sampleNodeB);
if (samples == null) {
this.samples = SampleNode.createSampleNode(new StackTraceElement[] { new StackTraceElement("NO SAMPLES", "", "", -1) });
}
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class HotFlameStackPanel method paintGraph.
private void paintGraph(final Graphics2D g2, final double areaWidth, final double rowHeight) {
SampleNode samples = getSamples();
if (samples == null) {
return;
}
final SampleGraph graph = new SampleGraph(getMethod(), samples);
this.completeGraph = graph;
AggSample aggRoot = graph.getAggRootVertex();
int rootSamples = aggRoot.getNrSamples();
// calculate pixe/sample
final double pps = (areaWidth - 1) / rootSamples;
methodLocations = new HashMap<>();
PriorityQueue<AggSample> traversal = new PriorityQueue<>(new SComparator(graph));
traversal.add(aggRoot);
Set<AggSample> drawed = new HashSet<>(graph.getAggNodesNr());
AggSample next;
while ((next = traversal.poll()) != null) {
if (drawed.add(next)) {
drawMethod(g2, next, graph, pps, rowHeight);
traversal.addAll(graph.getChildren(next));
}
}
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class HotFlameStackPanel method drill.
@Override
public void drill() {
List<SampleKey> tips = search(xx, yy, 0, 0);
if (tips.size() >= 1) {
SampleKey sample = tips.get(0);
Set<Sample> samples = completeGraph.getSamples(sample);
Iterator<SampleGraph.Sample> iterator = samples.iterator();
SampleNode agg = iterator.next().getNode();
while (iterator.hasNext()) {
agg = SampleNode.aggregate(agg, iterator.next().getNode());
}
updateSamples(sample.getMethod(), agg);
repaint();
}
}
use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.
the class FlameStackPanel method paintNode.
@SuppressFBWarnings("ISB_TOSTRING_APPENDING")
private int paintNode(final Method method, final SampleNode node, final Graphics2D g2, final int x, final int py, final int width, final int height, final int depth) {
if (node == null) {
return 0;
}
int y = py;
int sampleCount = node.getSampleCount();
String val = Methods.toString(method) + '-' + sampleCount;
setElementColor(depth, g2);
g2.setClip(x, y, width, height);
g2.fillRect(x, y, width, height);
insert(x, y, width, height, Pair.of(method, node));
g2.setPaint(Color.BLACK);
g2.drawString(val, x, y + height - 1);
g2.setClip(null);
g2.setPaint(LINK_COLOR);
g2.drawRect(x, y, width, height);
int result = height;
if (!node.isEmpty()) {
y += height;
int relX = x;
double scale = (double) width / sampleCount;
int maxY = 0;
for (Map.Entry<Method, SampleNode> entry : node.entrySet()) {
SampleNode cnode = entry.getValue();
// sampleCount -> width
// childSampleCount -> childWidth
int childWidth = (int) (scale * cnode.getSampleCount());
if (childWidth > 0) {
maxY = Math.max(maxY, paintNode(entry.getKey(), cnode, g2, relX, y, childWidth, height, depth + 1));
relX += childWidth;
}
}
result += maxY;
}
return result;
}
Aggregations