1 /*******************************************************************************
2 * Copyright (c) 2015 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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.latency
.statistics
;
14 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
;
23 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCallLatencyAnalysis
;
24 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.segmentstore
.statistics
.SegmentStoreStatistics
;
25 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
26 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
33 import com
.google
.common
.collect
.ImmutableList
;
36 * Analysis module to calculate statistics of a latency analysis
38 * @author Bernd Hufmann
40 public class SystemCallLatencyStatisticsAnalysisModule
extends TmfAbstractAnalysisModule
{
42 /** The analysis module ID */
43 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$
45 private @Nullable SystemCallLatencyAnalysis fLatencyModule
;
47 private @Nullable SegmentStoreStatistics fTotalStats
;
49 private @Nullable Map
<String
, SegmentStoreStatistics
> fPerSyscallStats
;
52 protected Iterable
<IAnalysisModule
> getDependentAnalyses() {
53 ITmfTrace trace
= getTrace();
55 SystemCallLatencyAnalysis module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, SystemCallLatencyAnalysis
.class, checkNotNull(SystemCallLatencyAnalysis
.ID
));
57 fLatencyModule
= module
;
58 return checkNotNull(ImmutableList
.of((IAnalysisModule
) module
));
61 return super.getDependentAnalyses();
65 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
66 SystemCallLatencyAnalysis latency
= fLatencyModule
;
67 ITmfTrace trace
= getTrace();
68 if ((latency
== null) || (trace
== null)) {
71 latency
.waitForCompletion();
73 ISegmentStore
<ISegment
> store
= latency
.getResults();
77 boolean result
= calculateTotalManual(store
, monitor
);
83 result
= calculateTotalPerSyscall(store
, monitor
);
91 private boolean calculateTotalManual(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
92 SegmentStoreStatistics total
= new SegmentStoreStatistics();
93 Iterator
<ISegment
> iter
= store
.iterator();
94 while (iter
.hasNext()) {
95 if (monitor
.isCanceled()) {
98 ISegment segment
= iter
.next();
99 total
.update(checkNotNull(segment
));
105 private boolean calculateTotalPerSyscall(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
106 Map
<String
, SegmentStoreStatistics
> perSyscallStats
= new HashMap
<>();
108 Iterator
<ISegment
> iter
= store
.iterator();
109 while (iter
.hasNext()) {
110 if (monitor
.isCanceled()) {
113 ISegment segment
= iter
.next();
114 if (segment
instanceof SystemCall
) {
115 SystemCall syscall
= (SystemCall
) segment
;
116 SegmentStoreStatistics values
= perSyscallStats
.get(syscall
.getName());
117 if (values
== null) {
118 values
= new SegmentStoreStatistics();
120 values
.update(segment
);
121 perSyscallStats
.put(syscall
.getName(), values
);
124 fPerSyscallStats
= perSyscallStats
;
129 protected void canceling() {
133 * The total statistics
135 * @return the total statistics
137 public @Nullable SegmentStoreStatistics
getTotalStats() {
142 * The per syscall statistics
144 * @return the per syscall statistics
146 public @Nullable Map
<String
, SegmentStoreStatistics
> getPerSyscallStats() {
147 return fPerSyscallStats
;