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
));
55 fLatencyModule
= module
;
56 return checkNotNull(ImmutableList
.of((IAnalysisModule
) module
));
58 return super.getDependentAnalyses();
62 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
63 SystemCallLatencyAnalysis latency
= fLatencyModule
;
64 ITmfTrace trace
= getTrace();
65 if ((latency
== null) || (trace
== null)) {
68 latency
.waitForCompletion();
70 ISegmentStore
<ISegment
> store
= latency
.getResults();
74 boolean result
= calculateTotalManual(store
, monitor
);
80 result
= calculateTotalPerSyscall(store
, monitor
);
88 private boolean calculateTotalManual(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
89 LatencyStatistics total
= new LatencyStatistics();
90 Iterator
<ISegment
> iter
= store
.iterator();
91 while (iter
.hasNext()) {
92 if (monitor
.isCanceled()) {
95 ISegment segment
= iter
.next();
96 total
.update(checkNotNull(segment
));
102 private boolean calculateTotalPerSyscall(ISegmentStore
<ISegment
> store
, IProgressMonitor monitor
) {
103 Map
<String
, LatencyStatistics
> perSyscallStats
= new HashMap
<>();
105 Iterator
<ISegment
> iter
= store
.iterator();
106 while (iter
.hasNext()) {
107 if (monitor
.isCanceled()) {
110 ISegment segment
= iter
.next();
111 if (segment
instanceof SystemCall
) {
112 SystemCall syscall
= (SystemCall
) segment
;
113 LatencyStatistics values
= perSyscallStats
.get(syscall
.getName());
114 if (values
== null) {
115 values
= new LatencyStatistics();
117 values
.update(segment
);
118 perSyscallStats
.put(syscall
.getName(), values
);
121 fPerSyscallStats
= perSyscallStats
;
126 protected void canceling() {
130 * The total statistics
132 * @return the total statistics
134 public @Nullable LatencyStatistics
getTotalStats() {
139 * The per syscall statistics
141 * @return the per syscall statistics
143 public @Nullable Map
<String
, LatencyStatistics
> getPerSyscallStats() {
144 return fPerSyscallStats
;