aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Perot2014-05-07 09:45:56 (EDT)
committerAlexandre Montplaisir2014-05-26 14:47:30 (EDT)
commite7dd83af2bb897cbb44e8f28c357d5adf9b9b5d8 (patch)
tree17386edd03223dbccd32b5365dc03f985c9e201a
parent71b76c869b895ee6f1bad96e8a038cd454622053 (diff)
downloadorg.eclipse.linuxtools-e7dd83af2bb897cbb44e8f28c357d5adf9b9b5d8.zip
org.eclipse.linuxtools-e7dd83af2bb897cbb44e8f28c357d5adf9b9b5d8.tar.gz
org.eclipse.linuxtools-e7dd83af2bb897cbb44e8f28c357d5adf9b9b5d8.tar.bz2
tmf: Add percentage on Statistics viewrefs/changes/44/26144/22
Change-Id: I70a565611e230330bc147bb92575d6606aa89311 Signed-off-by: Vincent Perot <vincent.perot@ericsson.com> Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/26144 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java10
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java130
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseColumnDataProvider.java135
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsFormatter.java84
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java32
5 files changed, 317 insertions, 74 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java
index e8a07fa..f774433 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java
@@ -39,6 +39,7 @@ import org.junit.Test;
/**
* TmfBaseColumnDataProvider test cases.
+ *
*/
public class TmfBaseColumnDataProviderTest {
@@ -127,11 +128,11 @@ public class TmfBaseColumnDataProviderTest {
public void testGetColumnData() {
List<TmfBaseColumnData> columnsData = provider.getColumnData();
assertNotNull("getColumnData", columnsData);
- assertEquals("getColumnData", 3, columnsData.size());
+ assertEquals("getColumnData", 4, columnsData.size());
TmfStatisticsTreeNode parentNode = fStatsData.getNode(fTestName);
- TmfStatisticsTreeNode treeNode1 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
- TmfStatisticsTreeNode treeNode2 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName());
+ TmfStatisticsTreeNode treeNode1 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
+ TmfStatisticsTreeNode treeNode2 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName());
ViewerComparator vComp = null;
for (TmfBaseColumnData columnData : columnsData) {
assertNotNull("getColumnData", columnData);
@@ -143,7 +144,8 @@ public class TmfBaseColumnDataProviderTest {
if (columnData.getHeader().compareTo(LEVEL_COLUMN) == 0) {
assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(treeNode1.getName()));
} else if (columnData.getHeader().compareTo(EVENTS_COUNT_COLUMN) == 0) {
- assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(Long.toString(1)));
+ // might not work because of machine local number format
+ assertEquals("getColumnData", "1", labelProvider.getText(treeNode1));
}
// Testing comparator
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
index bfc967c..18dea7f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
@@ -38,6 +38,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewer;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsFormatter;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
@@ -333,7 +334,13 @@ public class TmfStatisticsViewer extends TmfViewer {
treeColumn.getColumn().setWidth(columnData.getWidth());
treeColumn.getColumn().setToolTipText(columnData.getTooltip());
- if (columnData.getComparator() != null) { // A comparator is defined.
+ // If is dummy column
+ if (columnData == columnDataList.get(TmfBaseColumnDataProvider.StatsColumn.DUMMY.getIndex())) {
+ treeColumn.getColumn().setResizable(false);
+ }
+
+ // A comparator is defined.
+ if (columnData.getComparator() != null) {
// Adds a listener on the columns header for sorting purpose.
treeColumn.getColumn().addSelectionListener(new SelectionAdapter() {
@@ -354,8 +361,8 @@ public class TmfStatisticsViewer extends TmfViewer {
if (fTreeViewer.getTree().getSortDirection() == SWT.UP
|| fTreeViewer.getTree().getSortColumn() != treeColumn.getColumn()) {
/*
- * Puts the descendant order if the old order was
- * up or if the selected column has changed.
+ * Puts the descendant order if the old order was up
+ * or if the selected column has changed.
*/
fTreeViewer.setComparator(columnData.getComparator());
fTreeViewer.getTree().setSortDirection(SWT.DOWN);
@@ -374,44 +381,84 @@ public class TmfStatisticsViewer extends TmfViewer {
treeColumn.setLabelProvider(columnData.getLabelProvider());
}
- // Handler that will draw the bar charts.
+ // Handler that will draw the percentages and the bar charts.
fTreeViewer.getTree().addListener(SWT.EraseItem, new Listener() {
@Override
public void handleEvent(Event event) {
if (columnDataList.get(event.index).getPercentageProvider() != null) {
+
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) event.item.getData();
- double percentage = columnDataList.get(event.index).getPercentageProvider().getPercentage(node);
- if (percentage == 0) { // No bar to draw
+ // If node is hidden, exit immediately.
+ if (TmfBaseColumnDataProvider.HIDDEN_FOLDER_LEVELS.contains(node.getName())) {
return;
}
- if ((event.detail & SWT.SELECTED) > 0) { // The item is selected.
- // Draws our own background to avoid overwritten the bar.
+ // Otherwise, get percentage and draw bar and text if applicable.
+ double percentage = columnDataList.get(event.index).getPercentageProvider().getPercentage(node);
+
+ // The item is selected.
+ if ((event.detail & SWT.SELECTED) > 0) {
+ // Draws our own background to avoid overwriting the bar.
event.gc.fillRectangle(event.x, event.y, event.width, event.height);
event.detail &= ~SWT.SELECTED;
}
- int barWidth = (int) ((fTreeViewer.getTree().getColumn(event.index).getWidth() - 8) * percentage);
- int oldAlpha = event.gc.getAlpha();
- Color oldForeground = event.gc.getForeground();
- Color oldBackground = event.gc.getBackground();
- /*
- * Draws a transparent gradient rectangle from the color of
- * foreground and background.
- */
- event.gc.setAlpha(64);
- event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_BLUE));
- event.gc.setBackground(event.item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
- event.gc.fillGradientRectangle(event.x, event.y, barWidth, event.height, true);
- event.gc.drawRectangle(event.x, event.y, barWidth, event.height);
- // Restores old values
- event.gc.setForeground(oldForeground);
- event.gc.setBackground(oldBackground);
- event.gc.setAlpha(oldAlpha);
- event.detail &= ~SWT.BACKGROUND;
+ // Drawing the percentage text
+ // if events are present in top node
+ // and the current node is not the top node
+ // and if is total or partial events column.
+ // If not, exit the method.
+ if (!((event.index == TmfBaseColumnDataProvider.StatsColumn.TOTAL.getIndex() || event.index == TmfBaseColumnDataProvider.StatsColumn.PARTIAL.getIndex())
+ && node != node.getTop())) {
+ return;
+ }
+
+ long eventValue = event.index == TmfBaseColumnDataProvider.StatsColumn.TOTAL.getIndex() ?
+ node.getTop().getValues().getTotal() : node.getTop().getValues().getPartial();
+
+ if (eventValue != 0) {
+
+ int oldAlpha = event.gc.getAlpha();
+ Color oldForeground = event.gc.getForeground();
+ Color oldBackground = event.gc.getBackground();
+
+ // Bar to draw
+ if (percentage != 0) {
+ /*
+ * Draws a transparent gradient rectangle from the
+ * color of foreground and background.
+ */
+ int barWidth = (int) ((fTreeViewer.getTree().getColumn(event.index).getWidth() - 8) * percentage);
+ event.gc.setAlpha(64);
+ event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_BLUE));
+ event.gc.setBackground(event.item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ event.gc.fillGradientRectangle(event.x, event.y, barWidth, event.height, true);
+ event.gc.drawRectangle(event.x, event.y, barWidth, event.height);
+
+ // Restore old values
+ event.gc.setBackground(oldBackground);
+ event.gc.setAlpha(oldAlpha);
+ event.detail &= ~SWT.BACKGROUND;
+
+ }
+
+ String percentageText = TmfStatisticsFormatter.toPercentageText(percentage);
+ String absoluteNumberText = TmfStatisticsFormatter.toColumnData(node, TmfBaseColumnDataProvider.StatsColumn.getColumn(event.index));
+
+ if (event.width > event.gc.stringExtent(percentageText).x + event.gc.stringExtent(absoluteNumberText).x) {
+ int textHeight = event.gc.stringExtent(percentageText).y;
+ event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
+ event.gc.drawText(percentageText, event.x, event.y + (event.height - textHeight) / 2, true);
+ }
+
+ // Restores old values
+ event.gc.setForeground(oldForeground);
+
+ }
}
}
+
});
// Initializes the comparator parameters
@@ -501,12 +548,12 @@ public class TmfStatisticsViewer extends TmfViewer {
* request.
*/
protected void modelIncomplete(boolean isGlobalRequest) {
- if (isGlobalRequest) { // Clean the global statistics
+ if (isGlobalRequest) { // Clean the global statistics
/*
* No need to reset the global number of events, since the index of
* the last requested event is known.
*/
- } else { // Clean the partial statistics
+ } else { // Clean the partial statistics
resetTimeRangeValue();
}
refresh();
@@ -538,11 +585,11 @@ public class TmfStatisticsViewer extends TmfViewer {
}
/**
- * Requests all the data of the trace to the state system which
- * contains information about the statistics.
+ * Requests all the data of the trace to the state system which contains
+ * information about the statistics.
*
- * Since the viewer may be listening to multiple traces, it may receive
- * an experiment rather than a single trace. The filtering is done with the
+ * Since the viewer may be listening to multiple traces, it may receive an
+ * experiment rather than a single trace. The filtering is done with the
* method {@link #isListeningTo(String trace)}.
*
* @param trace
@@ -606,17 +653,19 @@ public class TmfStatisticsViewer extends TmfViewer {
*/
ITmfStateSystem ss = statsMod.getStateSystem(TmfStatisticsEventTypesModule.ID);
if (ss == null) {
- /* It should be instantiated after the
- * statsMod.waitForInitialization() above. */
+ /*
+ * It should be instantiated after the
+ * statsMod.waitForInitialization() above.
+ */
throw new IllegalStateException();
}
/*
* Periodically update the statistics while they are
- * being built (or, if the back-end is already completely
- * built, it will skip over the while() immediately.
+ * being built (or, if the back-end is already
+ * completely built, it will skip over the while() immediately.
*/
- while(!ss.waitUntilBuilt(LIVE_UPDATE_DELAY)) {
+ while (!ss.waitUntilBuilt(LIVE_UPDATE_DELAY)) {
Map<String, Long> map = stats.getEventTypesInRange(start, end);
updateStats(aTrace, isGlobal, map);
}
@@ -637,13 +686,14 @@ public class TmfStatisticsViewer extends TmfViewer {
final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
if (statsData == null) {
- /* The stat tree has been disposed, abort mission. */
+ /* The stat tree has been disposed, abort mission. */
return;
}
Map<String, Long> map = eventsPerType;
String name = trace.getName();
+
/*
* "Global", "partial", "total", etc., it's all very confusing...
*
@@ -694,8 +744,8 @@ public class TmfStatisticsViewer extends TmfViewer {
}
/**
- * When the trace is loading the cursor will be different so the user
- * knows that the processing is not finished yet.
+ * When the trace is loading the cursor will be different so the user knows
+ * that the processing is not finished yet.
*
* Calls to this method are stacked.
*
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseColumnDataProvider.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseColumnDataProvider.java
index a2bb4b5..53fb004 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseColumnDataProvider.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseColumnDataProvider.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
+ * Vincent Perot - Add percentages to the label provider
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
@@ -31,7 +32,7 @@ import com.google.common.collect.ImmutableSet;
* Create a basic list of columns with providers.
*
* @author Mathieu Denis
- * @since 2.0
+ * @since 3.0
*/
public class TmfBaseColumnDataProvider {
@@ -61,8 +62,85 @@ public class TmfBaseColumnDataProvider {
// Class attributes
// ------------------------------------------------------------------------
- /** Level for which statistics should not be displayed. */
- private static final Set<String> HIDDEN_FOLDER_LEVELS = ImmutableSet.of("Event Types"); //$NON-NLS-1$
+ /**
+ * Level for which statistics should not be displayed.
+ *
+ * @since 3.0
+ */
+ public static final Set<String> HIDDEN_FOLDER_LEVELS = ImmutableSet.of("Event Types"); //$NON-NLS-1$
+
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Column index (Ideally, this should not be hardcoded).
+ // ------------------------------------------------------------------------
+
+ /**
+ * Possible columns in the view
+ *
+ * @since 3.0
+ */
+ public static enum StatsColumn {
+ /**
+ * Column index for the event type column.
+ */
+ EVENT(0),
+ /**
+ * Column index for the event total count column.
+ */
+ TOTAL(1),
+ /**
+ * Column index for the event partial count column.
+ */
+ PARTIAL(2),
+ /**
+ * Column index for the dummy column.
+ */
+ DUMMY(3);
+
+ private final int colIndex;
+
+ private StatsColumn(int index) {
+ colIndex = index;
+ }
+
+ /**
+ * Getter method for the column index.
+ *
+ * @return the index of the column
+ */
+ public int getIndex() {
+ return colIndex;
+ }
+
+ /**
+ * Method to get the column at a certain index.
+ *
+ * @param index the index of the column
+ *
+ * @return the column at the specified index
+ */
+ public static StatsColumn getColumn(int index) {
+ switch(index) {
+ case 0:
+ return EVENT;
+
+ case 1:
+ return TOTAL;
+
+ case 2:
+ return PARTIAL;
+
+ case 3:
+ return DUMMY;
+
+ // Other values are illegal.
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ }
+ }
// ------------------------------------------------------------------------
// Instance fields
@@ -115,16 +193,16 @@ public class TmfBaseColumnDataProvider {
builder.add(new TmfBaseColumnData(
EVENTS_COUNT_COLUMN,
140,
- SWT.LEFT,
+ SWT.RIGHT,
EVENTS_COUNT_COLUMN_TIP,
new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
if (!HIDDEN_FOLDER_LEVELS.contains(node.getName())) {
- return Long.toString(node.getValues().getTotal());
+ return TmfStatisticsFormatter.toColumnData(node, StatsColumn.TOTAL);
}
- return ""; //$NON-NLS-1$
+ return EMPTY_STRING;
}
},
new ViewerComparator() {
@@ -139,15 +217,9 @@ public class TmfBaseColumnDataProvider {
new ITmfColumnPercentageProvider() {
@Override
public double getPercentage(TmfStatisticsTreeNode node) {
- TmfStatisticsTreeNode parent = node;
- do {
- parent = parent.getParent();
- } while (parent != null && parent.getValues().getTotal() == 0);
-
- if (parent == null) {
- return 0;
- }
- return (double) node.getValues().getTotal() / parent.getValues().getTotal();
+ TmfStatisticsTreeNode top = node.getTop();
+ return (top == null || top.getValues().getTotal() == 0) ?
+ 0 : (double) (node.getValues().getTotal()) / top.getValues().getTotal();
}
}));
@@ -155,17 +227,18 @@ public class TmfBaseColumnDataProvider {
builder.add(new TmfBaseColumnData(
PARTIAL_EVENTS_COUNT_COLUMN,
140,
- SWT.LEFT,
+ SWT.RIGHT,
PARTIAL_COUNT_COLUMN_TIP,
new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
if (!HIDDEN_FOLDER_LEVELS.contains(node.getName())) {
- return Long.toString(node.getValues().getPartial());
+ return TmfStatisticsFormatter.toColumnData(node, StatsColumn.PARTIAL);
}
- return ""; //$NON-NLS-1$
+ return EMPTY_STRING;
}
+
},
new ViewerComparator() {
@Override
@@ -179,15 +252,25 @@ public class TmfBaseColumnDataProvider {
new ITmfColumnPercentageProvider() {
@Override
public double getPercentage(TmfStatisticsTreeNode node) {
- TmfStatisticsTreeNode parent = node;
- do {
- parent = parent.getParent();
- } while (parent != null && parent.getValues().getPartial() == 0);
+ TmfStatisticsTreeNode top = node.getTop();
+ return (top == null || top.getValues().getPartial() == 0) ?
+ 0 : (double) (node.getValues().getPartial()) / top.getValues().getPartial();
+ }
+ }));
- if (parent == null) {
- return 0;
- }
- return (double) node.getValues().getPartial() / parent.getValues().getPartial();
+ /* Dummy column used to "fix" the display on Linux (using GTK) */
+ builder.add(new TmfBaseColumnData(EMPTY_STRING, 1, SWT.RIGHT, EMPTY_STRING,
+ new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return EMPTY_STRING;
+ }
+ },
+ new ViewerComparator(),
+ new ITmfColumnPercentageProvider() {
+ @Override
+ public double getPercentage(TmfStatisticsTreeNode node) {
+ return 0;
}
}));
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsFormatter.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsFormatter.java
new file mode 100644
index 0000000..7ac6da0
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsFormatter.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Perot - Add percentages to the label provider
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider.StatsColumn;
+
+/**
+ * Class that format data for cells in the statistics view.
+ *
+ * @author Vincent Perot
+ * @since 3.0
+ */
+public final class TmfStatisticsFormatter {
+
+ /**
+ * Formatter for the column data
+ */
+ private static final NumberFormat FORMATTER = NumberFormat.getNumberInstance(Locale.getDefault());
+
+ TmfStatisticsFormatter() {
+ // Nothing to construct.
+ }
+
+ /**
+ * Generate the string for display in a cell.
+ *
+ * @param node
+ * Current node.
+ * @param config
+ * Configuration between total and partial.
+ * @return The formatted string ready for display.
+ */
+ public static String toColumnData(TmfStatisticsTreeNode node, StatsColumn config) {
+
+ long eventValue = 0;
+
+ switch (config) {
+
+ case TOTAL:
+ eventValue = node.getValues().getTotal();
+ break;
+
+ case PARTIAL:
+ eventValue = node.getValues().getPartial();
+ break;
+
+ // Other values are illegal.
+ // $CASES-OMITTED$
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ return FORMATTER.format(eventValue);
+ }
+
+ /**
+ * Format the percentage according to user settings.
+ *
+ * @param percentage
+ * the percentage to format
+ * @return The formated percentage as a string.
+ */
+ public static String toPercentageText(double percentage) {
+
+ // The cast to long is needed because the formatter cannot truncate the number.
+ double truncPercentage = ((long) (1000.0 * percentage)) / 10.0;
+
+ String percentageString = String.format("%s%s%s", " ", FORMATTER.format(truncPercentage), " % "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return percentageString;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
index a04e653..a43bcbe 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
@@ -49,6 +49,11 @@ public class TmfStatisticsTreeNode {
private final TmfStatisticsValues fValues;
/**
+ * Return the node at the top of the branch
+ */
+ private final TmfStatisticsTreeNode fTopNode;
+
+ /**
* Constructor.
*
* @param tree
@@ -60,8 +65,10 @@ public class TmfStatisticsTreeNode {
*/
public TmfStatisticsTreeNode(TmfStatisticsTree tree,
TmfStatisticsTreeNode parent, final String... path) {
- /* The path must not contain any null element, or else we won't be
- * able to walk the tree. */
+ /*
+ * The path must not contain any null element, or else we won't be able
+ * to walk the tree.
+ */
for (String elem : path) {
if (elem == null) {
throw new IllegalArgumentException();
@@ -73,6 +80,13 @@ public class TmfStatisticsTreeNode {
fParent = parent;
fChildren = new ConcurrentHashMap<>();
fValues = new TmfStatisticsValues();
+
+ /* calculating top node */
+ TmfStatisticsTreeNode topNode = this;
+ while (topNode.getParent() != null && topNode.getParent().getParent() != null) {
+ topNode = topNode.getParent();
+ }
+ fTopNode = topNode;
}
/**
@@ -157,6 +171,16 @@ public class TmfStatisticsTreeNode {
}
/**
+ * Return the top node.
+ *
+ * @return Top node.
+ * @since 3.0
+ */
+ public TmfStatisticsTreeNode getTop() {
+ return fTopNode;
+ }
+
+ /**
* Get the path of the node.
*
* @return The path of the node.
@@ -194,8 +218,8 @@ public class TmfStatisticsTreeNode {
}
/**
- * Resets the global number of events. It doesn't remove any node
- * and doesn't modify the partial event count. Works recursively.
+ * Resets the global number of events. It doesn't remove any node and
+ * doesn't modify the partial event count. Works recursively.
*
* @since 2.0
*/