1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
8 *******************************************************************************/
9 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.segmentstore
.statistics
;
11 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
13 import java
.util
.HashMap
;
14 import java
.util
.Iterator
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.ISegmentStoreProvider
;
20 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
21 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import com
.google
.common
.collect
.ImmutableList
;
30 * Abstract analysis to build statistics data for a segment store
32 * @author Jean-Christian Kouame
34 public abstract class AbstractSegmentStatisticsAnalysis
extends TmfAbstractAnalysisModule
{
36 private @Nullable IAnalysisModule fSegmentStoreProviderModule
;
38 private @Nullable SegmentStoreStatistics fTotalStats
;
40 private @Nullable Map
<String
, SegmentStoreStatistics
> fPerSegmentTypeStats
;
43 protected Iterable
<IAnalysisModule
> getDependentAnalyses() {
44 ITmfTrace trace
= getTrace();
46 ISegmentStoreProvider provider
= getSegmentProviderAnalysis(trace
);
47 if (provider
instanceof IAnalysisModule
) {
48 fSegmentStoreProviderModule
= (IAnalysisModule
) provider
;
49 return ImmutableList
.of((IAnalysisModule
) provider
);
52 return super.getDependentAnalyses();
56 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
57 IAnalysisModule segmentStoreProviderModule
= fSegmentStoreProviderModule
;
58 ITmfTrace trace
= getTrace();
59 if (!(segmentStoreProviderModule
instanceof ISegmentStoreProvider
) || (trace
== null)) {
62 segmentStoreProviderModule
.waitForCompletion();
64 ISegmentStore
<ISegment
> segStore
= ((ISegmentStoreProvider
) segmentStoreProviderModule
).getSegmentStore();
66 if (segStore
!= null) {
68 boolean result
= calculateTotalManual(segStore
, monitor
);
74 result
= calculateTotalPerType(segStore
, monitor
);
82 private boolean calculateTotalManual(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
83 SegmentStoreStatistics total
= new SegmentStoreStatistics();
84 Iterator
<ISegment
> iter
= store
.iterator();
85 while (iter
.hasNext()) {
86 if (monitor
.isCanceled()) {
89 ISegment segment
= iter
.next();
90 total
.update(checkNotNull(segment
));
96 private boolean calculateTotalPerType(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
97 Map
<String
, SegmentStoreStatistics
> perSegmentTypeStats
= new HashMap
<>();
99 Iterator
<ISegment
> iter
= store
.iterator();
100 while (iter
.hasNext()) {
101 if (monitor
.isCanceled()) {
104 ISegment segment
= iter
.next();
105 String segmentType
= getSegmentType(segment
);
106 if (segmentType
!= null) {
107 SegmentStoreStatistics values
= perSegmentTypeStats
.get(segmentType
);
108 if (values
== null) {
109 values
= new SegmentStoreStatistics();
111 values
.update(segment
);
112 perSegmentTypeStats
.put(segmentType
, values
);
115 fPerSegmentTypeStats
= perSegmentTypeStats
;
120 * Get the type of a segment. Statistics per type will use this type as a
124 * the segment for which to get the type
125 * @return The type of the segment
127 protected abstract @Nullable String
getSegmentType(ISegment segment
);
130 * Find the segment store provider used for this analysis
135 * @return The segment store provider
137 protected abstract @Nullable ISegmentStoreProvider
getSegmentProviderAnalysis(ITmfTrace trace
);
140 protected void canceling() {
144 * The total statistics
146 * @return the total statistics
148 public @Nullable SegmentStoreStatistics
getTotalStats() {
153 * The per syscall statistics
155 * @return the per syscall statistics
157 public @Nullable Map
<String
, SegmentStoreStatistics
> getPerSegmentTypeStats() {
158 return fPerSegmentTypeStats
;