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 org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.IGraphWorker
;
18 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.ITmfGraphVisitor
;
19 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfEdge
;
20 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfGraph
;
21 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
;
22 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
24 import com
.google
.common
.collect
.ArrayListMultimap
;
25 import com
.google
.common
.collect
.Multimap
;
28 * Class that computes statistics on time spent in the elements (objects) of a
31 * @author Francis Giraldeau
32 * @author Geneviève Bastien
34 public class TmfGraphStatistics
implements ITmfGraphVisitor
{
36 private static final String STATS_TOTAL
= "total"; //$NON-NLS-1$
38 private final Multimap
<Object
, Long
> fWorkerStats
;
39 private @Nullable TmfGraph fGraph
;
44 public TmfGraphStatistics() {
45 fWorkerStats
= NonNullUtils
.checkNotNull(ArrayListMultimap
.<Object
, Long
> create());
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 getGraphStatistics(TmfGraph graph
, @Nullable IGraphWorker current
) {
57 if (current
== null) {
61 fGraph
.scanLineTraverse(fGraph
.getHead(current
), this);
65 public void visitHead(TmfVertex node
) {
70 public void visit(TmfVertex node
) {
75 public void visit(TmfEdge edge
, boolean horizontal
) {
76 // Add the duration of the link only if it is horizontal
77 TmfGraph graph
= fGraph
;
78 synchronized (fWorkerStats
) {
79 if (horizontal
&& graph
!= null) {
80 fWorkerStats
.put(graph
.getParentOf(edge
.getVertexFrom()),
81 edge
.getVertexTo().getTs() - edge
.getVertexFrom().getTs());
82 fWorkerStats
.put(STATS_TOTAL
,
83 edge
.getVertexTo().getTs() - edge
.getVertexFrom().getTs());
89 * Get the total duration spent by one element of the graph
92 * The object to get the time spent for
93 * @return The sum of all durations
95 public Long
getSum(@Nullable Object worker
) {
97 synchronized (fWorkerStats
) {
98 for (long duration
: fWorkerStats
.get(worker
)) {
106 * Get the total duration of the graph vertices
108 * @return The sum of all durations
110 public Long
getSum() {
111 return getSum(STATS_TOTAL
);
115 * Get the percentage of time by one element of the graph
118 * The object to get the percentage for
119 * @return The percentage time spent in this element
121 public Double
getPercent(@Nullable Object worker
) {
125 return (double) getSum(worker
) / (double) getSum();
This page took 0.035928 seconds and 5 git commands to generate.