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
.SystemCallLatencyAnalysis
;
23 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
;
24 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
25 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
32 import com
.google
.common
.collect
.ImmutableList
;
35 * Analysis module to calculate statistics of a latency analysis
37 * @author Bernd Hufmann
39 public class SystemCallLatencyStatisticsAnalysisModule
extends TmfAbstractAnalysisModule
{
41 /** The analysis module ID */
42 public static String ID
= "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$
44 private @Nullable SystemCallLatencyAnalysis fLatencyModule
;
46 private @Nullable LatencyStatistics fTotalStats
;
48 private @Nullable Map
<String
, LatencyStatistics
> fPerSyscallStats
;
51 protected Iterable
<IAnalysisModule
> getDependentAnalyses() {
52 ITmfTrace trace
= getTrace();
54 SystemCallLatencyAnalysis module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, SystemCallLatencyAnalysis
.class, checkNotNull(SystemCallLatencyAnalysis
.ID
));
56 fLatencyModule
= module
;
57 return checkNotNull(ImmutableList
.of((IAnalysisModule
) module
));
60 return super.getDependentAnalyses();
64 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
65 SystemCallLatencyAnalysis latency
= fLatencyModule
;
66 ITmfTrace trace
= getTrace();
67 if ((latency
== null) || (trace
== null)) {
70 latency
.waitForCompletion();
72 ISegmentStore
<ISegment
> store
= latency
.getResults();
76 boolean result
= calculateTotalManual(store
, monitor
);
82 result
= calculateTotalPerSyscall(store
, monitor
);
90 private boolean calculateTotalManual(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
91 LatencyStatistics total
= new LatencyStatistics();
92 Iterator
<ISegment
> iter
= store
.iterator();
93 while (iter
.hasNext()) {
94 if (monitor
.isCanceled()) {
97 ISegment segment
= iter
.next();
98 total
.update(checkNotNull(segment
));
104 private boolean calculateTotalPerSyscall(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
105 Map
<String
, LatencyStatistics
> perSyscallStats
= new HashMap
<>();
107 Iterator
<ISegment
> iter
= store
.iterator();
108 while (iter
.hasNext()) {
109 if (monitor
.isCanceled()) {
112 ISegment segment
= iter
.next();
113 if (segment
instanceof SystemCall
) {
114 SystemCall syscall
= (SystemCall
) segment
;
115 LatencyStatistics values
= perSyscallStats
.get(syscall
.getName());
116 if (values
== null) {
117 values
= new LatencyStatistics();
119 values
.update(segment
);
120 perSyscallStats
.put(syscall
.getName(), values
);
123 fPerSyscallStats
= perSyscallStats
;
128 protected void canceling() {
132 * The total statistics
134 * @return the total statistics
136 public @Nullable LatencyStatistics
getTotalStats() {
141 * The per syscall statistics
143 * @return the per syscall statistics
145 public @Nullable Map
<String
, LatencyStatistics
> getPerSyscallStats() {
146 return fPerSyscallStats
;