The TmfGraphStatistics was keeping all duration values. Individual
values are not required to display summary statistics. Instead, this
patch updates the sum per IGraphWorker. Also, we introduce the fTotal
field and remove the special placeholder String key in the map, allowing
to rectify the keys type from Object to IGraphWorker.
* update v2:
* synchronize only on fWorkerStats
* make only one map lookup to update worker sum
Change-Id: I202945bdad6a0cb759b2fc4cbb791b3afef7c3cc
Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Reviewed-on: https://git.eclipse.org/r/55780
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
public void testGraphStatistics() {
TmfGraph graph = buildFullGraph();
TmfGraphStatistics stats = new TmfGraphStatistics();
public void testGraphStatistics() {
TmfGraph graph = buildFullGraph();
TmfGraphStatistics stats = new TmfGraphStatistics();
- stats.getGraphStatistics(graph, WORKER1);
+ stats.computeGraphStatistics(graph, WORKER1);
assertEquals(12, stats.getSum(WORKER1).longValue());
assertEquals(11, stats.getSum(WORKER2).longValue());
assertEquals(23, stats.getSum().longValue());
assertEquals(12, stats.getSum(WORKER1).longValue());
assertEquals(11, stats.getSum(WORKER2).longValue());
assertEquals(23, stats.getSum().longValue());
package org.eclipse.tracecompass.internal.analysis.graph.core.base;
package org.eclipse.tracecompass.internal.analysis.graph.core.base;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
import org.eclipse.tracecompass.analysis.graph.core.base.ITmfGraphVisitor;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
import org.eclipse.tracecompass.analysis.graph.core.base.ITmfGraphVisitor;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
/**
* Class that computes statistics on time spent in the elements (objects) of a
/**
* Class that computes statistics on time spent in the elements (objects) of a
*
* @author Francis Giraldeau
* @author Geneviève Bastien
*
* @author Francis Giraldeau
* @author Geneviève Bastien
+ * @author Matthew Khouzam
*/
public class TmfGraphStatistics implements ITmfGraphVisitor {
*/
public class TmfGraphStatistics implements ITmfGraphVisitor {
- private static final String STATS_TOTAL = "total"; //$NON-NLS-1$
-
- private final Multimap<Object, Long> fWorkerStats;
+ private final Map<IGraphWorker, Long> fWorkerStats;
+ private Long fTotal;
private @Nullable TmfGraph fGraph;
/**
* Constructor
*/
public TmfGraphStatistics() {
private @Nullable TmfGraph fGraph;
/**
* Constructor
*/
public TmfGraphStatistics() {
- fWorkerStats = NonNullUtils.checkNotNull(ArrayListMultimap.<Object, Long> create());
+ fWorkerStats = new HashMap<>();
+ fTotal = 0L;
* @param current
* The element from which to start calculations
*/
* @param current
* The element from which to start calculations
*/
- public void getGraphStatistics(TmfGraph graph, @Nullable IGraphWorker current) {
+ public void computeGraphStatistics(TmfGraph graph, @Nullable IGraphWorker current) {
if (current == null) {
return;
}
if (current == null) {
return;
}
fGraph = graph;
fGraph.scanLineTraverse(fGraph.getHead(current), this);
}
fGraph = graph;
fGraph.scanLineTraverse(fGraph.getHead(current), this);
}
TmfGraph graph = fGraph;
synchronized (fWorkerStats) {
if (horizontal && graph != null) {
TmfGraph graph = fGraph;
synchronized (fWorkerStats) {
if (horizontal && graph != null) {
- fWorkerStats.put(graph.getParentOf(edge.getVertexFrom()),
- edge.getVertexTo().getTs() - edge.getVertexFrom().getTs());
- fWorkerStats.put(STATS_TOTAL,
- edge.getVertexTo().getTs() - edge.getVertexFrom().getTs());
+ IGraphWorker worker = graph.getParentOf(edge.getVertexFrom());
+ Long duration = edge.getDuration();
+ Long currentTotal = fWorkerStats.get(worker);
+ if (currentTotal != null) {
+ duration += currentTotal;
+ }
+ fWorkerStats.put(worker, duration);
+ fTotal += edge.getDuration();
* The object to get the time spent for
* @return The sum of all durations
*/
* The object to get the time spent for
* @return The sum of all durations
*/
- public Long getSum(@Nullable Object worker) {
- long sum = 0L;
+ public Long getSum(@Nullable IGraphWorker worker) {
+ Long sum = 0L;
synchronized (fWorkerStats) {
synchronized (fWorkerStats) {
- for (long duration : fWorkerStats.get(worker)) {
- sum += duration;
+ Long elapsed = fWorkerStats.get(worker);
+ if (elapsed != null) {
+ sum += elapsed;
* @return The sum of all durations
*/
public Long getSum() {
* @return The sum of all durations
*/
public Long getSum() {
- return getSum(STATS_TOTAL);
+ synchronized (fWorkerStats) {
+ return fTotal;
+ }
* The object to get the percentage for
* @return The percentage time spent in this element
*/
* The object to get the percentage for
* @return The percentage time spent in this element
*/
- public Double getPercent(@Nullable Object worker) {
- if (getSum() == 0) {
- return 0D;
+ public Double getPercent(@Nullable IGraphWorker worker) {
+ synchronized (fWorkerStats) {
+ if (getSum() == 0) {
+ return 0D;
+ }
+ return (double) getSum(worker) / (double) getSum();
+ }
+ }
+
+ /**
+ * Clear statistics
+ */
+
+ public void clear() {
+ synchronized (fWorkerStats) {
+ fTotal = 0L;
+ fWorkerStats.clear();
- return (double) getSum(worker) / (double) getSum();