Search in sources :

Example 1 with AggSample

use of org.spf4j.stackmonitor.SampleGraph.AggSample 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 2 with AggSample

use of org.spf4j.stackmonitor.SampleGraph.AggSample in project spf4j by zolyfarkas.

the class HotFlameStackPanel method getDetail.

@Override
@Nullable
public String getDetail(final Point location) {
    List<SampleKey> tips = search(location.x, location.y, 0, 0);
    if (tips.size() >= 1) {
        final SampleKey key = tips.get(0);
        final AggSample node = completeGraph.getAggNode(key);
        StringBuilder sb = new StringBuilder();
        sb.append(node).append('-').append(node.getNrSamples()).append("\n invoked from: ");
        appendEdgeInfo(completeGraph.getParents(node), sb);
        sb.append("\n invoking: ");
        appendEdgeInfo(completeGraph.getChildren(node), sb);
        return sb.toString();
    } else {
        return null;
    }
}
Also used : AggSample(org.spf4j.stackmonitor.SampleGraph.AggSample) SampleKey(org.spf4j.stackmonitor.SampleGraph.SampleKey) Nullable(javax.annotation.Nullable)

Example 3 with AggSample

use of org.spf4j.stackmonitor.SampleGraph.AggSample in project spf4j by zolyfarkas.

the class HotFlameStackPanel method getLocationSingleParent.

public Rectangle2D.Double getLocationSingleParent(final Set<AggSample> parents, final SampleGraph graph, final double rowHeight, final double pps, final AggSample sample) {
    // single parent, will be drawed attached.
    AggSample parent = parents.iterator().next();
    Rectangle2D pRect = methodLocations.get(parent.getKey());
    double px = pRect.getX();
    Set<AggSample> sibblings = graph.getChildren(parent);
    for (AggSample sibbling : sibblings) {
        if (graph.getParents(sibbling).size() == 1) {
            Rectangle2D l = methodLocations.get(sibbling.getKey());
            if (l != null) {
                double x = l.getX() + l.getWidth();
                if (x > px) {
                    px = x;
                }
            }
        }
    }
    return new Rectangle2D.Double(px, pRect.getY() + rowHeight, pps * sample.getNrSamples(), rowHeight);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) AggSample(org.spf4j.stackmonitor.SampleGraph.AggSample)

Example 4 with AggSample

use of org.spf4j.stackmonitor.SampleGraph.AggSample in project spf4j by zolyfarkas.

the class HotFlameStackPanel method drawMethod.

/**
 * method that draws an aggregate sample.
 * @param g2
 * @param sample
 * @param graph
 */
private void drawMethod(final Graphics2D g2, final AggSample sample, final SampleGraph graph, final double pps, final double rowHeight) {
    Set<AggSample> parents = graph.getParents(sample);
    Rectangle2D.Double location;
    final List<Point2D> fromLinks;
    if (parents.isEmpty()) {
        // this is the root node.
        location = new Rectangle2D.Double(0, 0, pps * sample.getNrSamples(), rowHeight);
        fromLinks = Collections.EMPTY_LIST;
    } else if (parents.size() == 1) {
        // single parent
        location = getLocationSingleParent(parents, graph, rowHeight, pps, sample);
        fromLinks = Collections.EMPTY_LIST;
    } else {
        // multiple parents
        fromLinks = new ArrayList<>(parents.size());
        Iterator<AggSample> iterator = parents.iterator();
        AggSample next = iterator.next();
        double x1 = 0, x2 = 0, y = 0;
        Rectangle2D pr = methodLocations.get(next.getKey());
        if (pr != null) {
            x1 = pr.getX();
            x2 = pr.getMaxX();
            y = pr.getMaxY();
            fromLinks.add(new Point2D.Float((float) pr.getCenterX(), (float) y));
        }
        while (iterator.hasNext()) {
            next = iterator.next();
            pr = methodLocations.get(next.getKey());
            if (pr != null) {
                fromLinks.add(new Point2D.Float((float) pr.getCenterX(), (float) pr.getMaxY()));
                x1 = Math.min(x1, pr.getX());
                x2 = Math.max(x2, pr.getMaxX());
                y = Math.max(y, pr.getMaxY());
            }
        }
        if (y <= 0) {
            throw new IllegalStateException("No parents for " + sample);
        }
        y += rowHeight;
        double width = pps * sample.getNrSamples();
        Double result = findEmptySpace(x1, y, width, x2);
        while (result == null) {
            // TODO: optimize this to increment with a better value
            y += rowHeight;
            result = findEmptySpace(x1, y, width, x2);
        }
        location = new Rectangle2D.Double(result.floatValue(), y, width, rowHeight);
    }
    Set<AggSample> children = graph.getChildren(sample);
    final List<Point2D> toLinks = new ArrayList<>(0);
    for (AggSample chs : children) {
        Rectangle2D ch = methodLocations.get(chs.getKey());
        if (ch != null) {
            toLinks.add(new Point2D.Float((float) ch.getCenterX(), (float) ch.getMaxY()));
        }
    }
    methodLocations.put(sample.getKey(), location);
    insert(location, sample.getKey());
    drawMethodRectangle(g2, location, sample, fromLinks, toLinks);
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AggSample(org.spf4j.stackmonitor.SampleGraph.AggSample)

Aggregations

AggSample (org.spf4j.stackmonitor.SampleGraph.AggSample)4 Rectangle2D (java.awt.geom.Rectangle2D)2 Point (java.awt.Point)1 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 PriorityQueue (java.util.PriorityQueue)1 Nullable (javax.annotation.Nullable)1 SampleGraph (org.spf4j.stackmonitor.SampleGraph)1 SampleKey (org.spf4j.stackmonitor.SampleGraph.SampleKey)1 SampleNode (org.spf4j.stackmonitor.SampleNode)1