1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francis Giraldeau - Initial implementation and API
11 * Geneviève Bastien - Initial implementation and API
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.analysis
.graph
.core
.base
;
16 import java
.util
.HashMap
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.IGraphWorker
;
21 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.ITmfGraphVisitor
;
22 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfEdge
;
23 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfGraph
;
24 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
;
27 * Class that computes statistics on time spent in the elements (objects) of a
30 * @author Francis Giraldeau
31 * @author Geneviève Bastien
32 * @author Matthew Khouzam
34 public class TmfGraphStatistics
implements ITmfGraphVisitor
{
36 private final Map
<IGraphWorker
, Long
> fWorkerStats
;
38 private @Nullable TmfGraph fGraph
;
43 public TmfGraphStatistics() {
44 fWorkerStats
= new HashMap
<>();
49 * Compute the statistics for a graph
52 * The graph on which to calculate statistics
54 * The element from which to start calculations
56 public void computeGraphStatistics(TmfGraph graph
, @Nullable IGraphWorker current
) {
57 if (current
== null) {
62 fGraph
.scanLineTraverse(fGraph
.getHead(current
), this);
66 public void visitHead(TmfVertex node
) {
71 public void visit(TmfVertex node
) {
76 public void visit(TmfEdge edge
, boolean horizontal
) {
77 // Add the duration of the link only if it is horizontal
78 TmfGraph graph
= fGraph
;
79 synchronized (fWorkerStats
) {
80 if (horizontal
&& graph
!= null) {
81 IGraphWorker worker
= graph
.getParentOf(edge
.getVertexFrom());
82 Long duration
= edge
.getDuration();
83 Long currentTotal
= fWorkerStats
.get(worker
);
84 if (currentTotal
!= null) {
85 duration
+= currentTotal
;
87 fWorkerStats
.put(worker
, duration
);
88 fTotal
+= edge
.getDuration();
94 * Get the total duration spent by one element of the graph
97 * The object to get the time spent for
98 * @return The sum of all durations
100 public Long
getSum(@Nullable IGraphWorker worker
) {
102 synchronized (fWorkerStats
) {
103 Long elapsed
= fWorkerStats
.get(worker
);
104 if (elapsed
!= null) {
112 * Get the total duration of the graph vertices
114 * @return The sum of all durations
116 public Long
getSum() {
117 synchronized (fWorkerStats
) {
123 * Get the percentage of time by one element of the graph
126 * The object to get the percentage for
127 * @return The percentage time spent in this element
129 public Double
getPercent(@Nullable IGraphWorker worker
) {
130 synchronized (fWorkerStats
) {
134 return (double) getSum(worker
) / (double) getSum();
142 public void clear() {
143 synchronized (fWorkerStats
) {
145 fWorkerStats
.clear();
This page took 0.066623 seconds and 5 git commands to generate.