Search in sources :

Example 1 with GraphNode

use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.

the class StapGraph method drawAggregateView.

/**
 * Draws nodes according to the name of the function (not accounting for
 * call heirarchies). Uses colour to indicate the number of calls and size
 * to indicate the percentage time spent.
 */
private void drawAggregateView() {
    if (aggregateNodes == null) {
        aggregateNodes = new ArrayList<>();
    } else {
        aggregateNodes.clear();
    }
    // -------------Format numbers
    float percentage_time;
    float percentage_count;
    int maxTimesCalled = 0;
    final int colorLevels = 15;
    final int colorLevelDifference = 12;
    int primary;
    int secondary;
    NumberFormat num = NumberFormat.getInstance(Locale.CANADA);
    num.setMinimumFractionDigits(2);
    num.setMaximumFractionDigits(2);
    // FIND THE MOST TIMES A FUNCTION IS CALLED
    for (int val : aggregateCount.values()) {
        if (val > maxTimesCalled) {
            maxTimesCalled = val;
        }
    }
    // TEMPORARY STORAGE OF THE ENTRIES
    // IMPLEMENTS A COMPARATOR TO STORE BY ORDER OF THE VALUE
    TreeSet<Entry<String, Long>> sortedValues = new TreeSet<>(StapGraph.VALUE_ORDER);
    HashMap<String, Long> tempMap = new HashMap<>();
    tempMap.putAll(aggregateTime);
    for (String key : tempMap.keySet()) {
        long time = aggregateTime.get(key);
        while (time < 0) {
            time += endTime;
        }
        tempMap.put(key, time);
    }
    sortedValues.addAll(tempMap.entrySet());
    // -------------Draw nodes
    for (Entry<String, Long> ent : sortedValues) {
        String key = ent.getKey();
        GraphNode n = new GraphNode(this.getGraphModel(), SWT.NONE);
        aggregateNodes.add(n);
        percentage_count = (float) aggregateCount.get(key) / (float) maxTimesCalled;
        percentage_time = ((float) ent.getValue() / this.getTotalTime() * 100);
        n.setText(// $NON-NLS-1$
        key + "\n" + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$
        "\n" + aggregateCount.get(key) + // $NON-NLS-1$
        "\n");
        // $NON-NLS-1$
        n.setData("AGGREGATE_NAME", key);
        primary = (int) (percentage_count * colorLevels * colorLevelDifference);
        secondary = (colorLevels * colorLevelDifference) - (int) (percentage_count * colorLevels * colorLevelDifference);
        primary = Math.max(0, primary);
        secondary = Math.max(0, secondary);
        primary = Math.min(primary, 255);
        secondary = Math.min(secondary, 255);
        Color c = new Color(this.getDisplay(), primary, 0, secondary);
        n.setBackgroundColor(c);
        n.setHighlightColor(c);
        n.setForegroundColor(new Color(this.getDisplay(), 255, 255, 255));
        n.setTooltip(new Label(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("StapGraph.Func") + key + "\n" + Messages.getString("StapGraph.Time") + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "\n" + Messages.getString("StapGraph.NumOfCalls") + // $NON-NLS-1$
        aggregateCount.get(key)));
        n.setBorderWidth(2);
    }
    // Set layout to gridlayout
    this.setLayoutAlgorithm(new AggregateLayoutAlgorithm(LayoutStyles.NONE, sortedValues, this.getTotalTime(), this.getBounds().width), true);
}
Also used : HashMap(java.util.HashMap) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.draw2d.Label) GraphNode(org.eclipse.zest.core.widgets.GraphNode) Entry(java.util.Map.Entry) TreeSet(java.util.TreeSet) NumberFormat(java.text.NumberFormat)

Example 2 with GraphNode

use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.

the class StapGraph method clearSelection.

/**
 * Unhighlights all selected nodes and sets selection to null
 */
private void clearSelection() {
    List<GraphNode> list = this.getSelection();
    for (GraphNode n : list) {
        if (n != null) {
            n.unhighlight();
        }
    }
    this.setSelection(null);
}
Also used : GraphNode(org.eclipse.zest.core.widgets.GraphNode)

Example 3 with GraphNode

use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.

the class StapGraph method deleteAll.

/*
     * Level/node management
     */
/**
 * Delete all nodes except for the node with the specified nodeID
 *
 * @param exception
 *            - id of node NOT to delete (use -1 for 'no exceptions')
 */
private void deleteAll(int exception) {
    // -------------Delete aggregate nodes
    if (aggregateNodes != null) {
        for (GraphNode n : aggregateNodes) {
            n.dispose();
        }
        aggregateNodes.clear();
    }
    // -------------Save exception node's location
    int x = -1;
    int y = -1;
    if (exception != -1 && nodeMap.get(exception) != null) {
        x = nodeMap.get(exception).getLocation().x;
        y = nodeMap.get(exception).getLocation().y;
    }
    // -------------Delete all nodes
    for (StapNode node : nodeMap.values()) {
        if (node == null) {
            continue;
        }
        node.unhighlight();
        node.dispose();
    }
    nodeMap.clear();
    // -------------Recreate exception
    if (x != -1 && y != -1) {
        StapNode n = getNodeData(exception).makeNode(this);
        n.setLocation(x, y);
        n.highlight();
        nodeMap.put(exception, n);
    }
}
Also used : GraphNode(org.eclipse.zest.core.widgets.GraphNode)

Example 4 with GraphNode

use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.

the class StapGraphMouseListener method getAggregateNodeFromSelection.

private GraphNode getAggregateNodeFromSelection() {
    List<GraphNode> graphNodeList = graph.getSelection();
    if (graphNodeList.isEmpty() || graphNodeList.size() != 1) {
        graph.setSelection(null);
        return null;
    }
    GraphNode node = null;
    if (graphNodeList.get(0) != null) {
        node = graphNodeList.remove(0);
    } else {
        graph.setSelection(null);
        return null;
    }
    return node;
}
Also used : GraphNode(org.eclipse.zest.core.widgets.GraphNode)

Example 5 with GraphNode

use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.

the class StapGraphMouseListener method getNodeFromSelection.

private StapNode getNodeFromSelection() {
    List<GraphNode> stapNodeList = graph.getSelection();
    if (stapNodeList.isEmpty() || stapNodeList.size() != 1) {
        graph.setSelection(null);
        return null;
    }
    StapNode node = null;
    if (stapNodeList.get(0) instanceof StapNode) {
        node = (StapNode) stapNodeList.remove(0);
    } else {
        graph.setSelection(null);
        return null;
    }
    return node;
}
Also used : GraphNode(org.eclipse.zest.core.widgets.GraphNode) StapNode(org.eclipse.linuxtools.internal.callgraph.StapNode)

Aggregations

GraphNode (org.eclipse.zest.core.widgets.GraphNode)6 StapNode (org.eclipse.linuxtools.internal.callgraph.StapNode)2 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 Label (org.eclipse.draw2d.Label)1 Color (org.eclipse.swt.graphics.Color)1