Search in sources :

Example 1 with SampleNode

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();
    }
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) URLDecoder(java.net.URLDecoder) TIntObjectMap(gnu.trove.map.TIntObjectMap) PushbackInputStream(java.io.PushbackInputStream) HashMap(java.util.HashMap) MemorizingBufferedInputStream(org.spf4j.io.MemorizingBufferedInputStream) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) BufferedOutputStream(java.io.BufferedOutputStream) Decoder(org.apache.avro.io.Decoder) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) SampleNode(org.spf4j.stackmonitor.SampleNode) Nullable(javax.annotation.Nullable) EncoderFactory(org.apache.avro.io.EncoderFactory) OutputStream(java.io.OutputStream) WillNotClose(javax.annotation.WillNotClose) Iterator(java.util.Iterator) Files(java.nio.file.Files) Methods(org.spf4j.base.Methods) BinaryDecoder(org.apache.avro.io.BinaryDecoder) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) Converters(org.spf4j.base.avro.Converters) UncheckedIOException(java.io.UncheckedIOException) Consumer(java.util.function.Consumer) BinaryEncoder(org.apache.avro.io.BinaryEncoder) URLEncoder(java.net.URLEncoder) Method(org.spf4j.base.avro.Method) StackSampleElement(org.spf4j.base.avro.StackSampleElement) GZIPOutputStream(java.util.zip.GZIPOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DecoderFactory(org.apache.avro.io.DecoderFactory) InputStream(java.io.InputStream) ProfileFileFormat(org.spf4j.stackmonitor.ProfileFileFormat) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter) BinaryEncoder(org.apache.avro.io.BinaryEncoder) SampleNode(org.spf4j.stackmonitor.SampleNode) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) HashMap(java.util.HashMap) Map(java.util.Map) StackSampleElement(org.spf4j.base.avro.StackSampleElement)

Example 2 with SampleNode

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) });
    }
}
Also used : SampleNode(org.spf4j.stackmonitor.SampleNode)

Example 3 with SampleNode

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));
        }
    }
}
Also used : SampleNode(org.spf4j.stackmonitor.SampleNode) SampleGraph(org.spf4j.stackmonitor.SampleGraph) AggSample(org.spf4j.stackmonitor.SampleGraph.AggSample) PriorityQueue(java.util.PriorityQueue) Point(java.awt.Point) HashSet(java.util.HashSet)

Example 4 with SampleNode

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();
    }
}
Also used : Sample(org.spf4j.stackmonitor.SampleGraph.Sample) AggSample(org.spf4j.stackmonitor.SampleGraph.AggSample) SampleNode(org.spf4j.stackmonitor.SampleNode) SampleKey(org.spf4j.stackmonitor.SampleGraph.SampleKey)

Example 5 with SampleNode

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;
}
Also used : Method(org.spf4j.base.avro.Method) SampleNode(org.spf4j.stackmonitor.SampleNode) Map(java.util.Map) Point(java.awt.Point) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SampleNode (org.spf4j.stackmonitor.SampleNode)19 Method (org.spf4j.base.avro.Method)9 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)5 StackSampleElement (org.spf4j.base.avro.StackSampleElement)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 Test (org.junit.Test)4 Point (java.awt.Point)3 File (java.io.File)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BufferedInputStream (java.io.BufferedInputStream)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 PushbackInputStream (java.io.PushbackInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 Nullable (javax.annotation.Nullable)2 BinaryDecoder (org.apache.avro.io.BinaryDecoder)2 Method (org.spf4j.base.Method)2