tmf: Support trace-specific markers in AbstractTimeGraphView
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / latency / statistics / LatencyStatisticsAnalysisModule.java
CommitLineData
ce8319b6
BH
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
13
14import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
15
16import java.util.HashMap;
17import java.util.Iterator;
18import java.util.Map;
19
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.jdt.annotation.Nullable;
22import org.eclipse.tracecompass.analysis.os.linux.core.latency.LatencyAnalysis;
23import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall;
24import org.eclipse.tracecompass.segmentstore.core.ISegment;
25import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
26import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
27import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
31
32import com.google.common.collect.ImmutableList;
33
34/**
35 * Analysis module to calculate statistics of a latency analysis
36 *
37 * @author Bernd Hufmann
38 */
39public class LatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule {
40
41 /** The analysis module ID */
42 public static String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics"; //$NON-NLS-1$
43
44 private @Nullable LatencyAnalysis fLatencyModule;
45
46 private @Nullable LatencyStatistics fTotalStats;
47
48 private Map<String, LatencyStatistics> fPerSyscallStats = new HashMap<>();
49
50 @Override
51 protected Iterable<IAnalysisModule> getDependentAnalyses() {
52 ITmfTrace trace = getTrace();
53 if (trace != null) {
54 LatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, LatencyAnalysis.class, LatencyAnalysis.ID);
55 fLatencyModule = module;
56 return checkNotNull(ImmutableList.of((IAnalysisModule) module));
57 }
58 return super.getDependentAnalyses();
59 }
60
61 @Override
62 protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
63 LatencyAnalysis latency = fLatencyModule;
64 ITmfTrace trace = getTrace();
65 if ((latency == null) || (trace == null)) {
66 return false;
67 }
68 latency.waitForCompletion();
69
70 ISegmentStore<ISegment> store = latency.getResults();
71
72 if (store != null) {
73
74 boolean result = calculateTotalManual(store, monitor);
75
76 if (!result) {
77 return false;
78 }
79
80 result = calculateTotalPerSyscall(store, monitor);
81 if (!result) {
82 return false;
83 }
84 }
85 return true;
86 }
87
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()) {
93 return false;
94 }
95 ISegment segment = iter.next();
96 total.update(checkNotNull(segment));
97 }
98
99 fTotalStats = total;
100 return true;
101 }
102
103 private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
104 fPerSyscallStats = new HashMap<>();
105
106 Iterator<ISegment> iter = store.iterator();
107 while (iter.hasNext()) {
108 if (monitor.isCanceled()) {
109 return false;
110 }
111 ISegment segment = iter.next();
112 if (segment instanceof SystemCall) {
113 SystemCall syscall = (SystemCall) segment;
114 LatencyStatistics values = fPerSyscallStats.get(syscall.getName());
115 if (values == null) {
116 values = new LatencyStatistics();
117 }
118 values.update(segment);
119 fPerSyscallStats.put(syscall.getName(), values);
120 }
121 }
122
123 return true;
124 }
125
126 @Override
127 protected void canceling() {
128 }
129
130 /**
131 * The total statistics
132 *
133 * @return the total statistics
134 */
135 public @Nullable LatencyStatistics getTotalStats() {
136 return fTotalStats;
137 }
138
139 /**
140 * The per syscall statistics
141 *
142 * @return the per syscall statistics
143 */
144 public Map<String, LatencyStatistics> getPerSyscallStats() {
145 return fPerSyscallStats;
146 }
147
148 }
This page took 0.04198 seconds and 5 git commands to generate.