Skip to content

Commit 42c3be2

Browse files
authored
Merge pull request #26 from arfio/fix-no-intervals
tmf: Fix statistics queries when there is no intervals
2 parents 2745b18 + c242fd0 commit 42c3be2

3 files changed

Lines changed: 44 additions & 21 deletions

File tree

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStateStatistics.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,40 +117,63 @@ public void dispose() {
117117
if (quark == ITmfStateSystem.INVALID_ATTRIBUTE) {
118118
return Collections.emptyList();
119119
}
120-
List<Long> times = new ArrayList<>();
120+
List<@NonNull Long> times = new ArrayList<>();
121121
for (int i = 0; i < timeRequested.length; i++) {
122+
/* create padding for every window of time before the start time */
122123
if (timeRequested[i] < fTotalsStats.getStartTime()) {
123-
times.add(fTotalsStats.getStartTime());
124-
} else if (timeRequested[i] < fTotalsStats.getCurrentEndTime()) {
125-
times.add(timeRequested[i]);
124+
list.add(0L);
126125
} else {
126+
if (!list.isEmpty()) {
127+
/* replace this bucket with the [start time, next time] */
128+
times.add(fTotalsStats.getStartTime());
129+
list.remove(list.size() - 1);
130+
}
131+
times.add(timeRequested[i]);
132+
}
133+
if (timeRequested[i] > fTotalsStats.getCurrentEndTime()) {
127134
times.add(fTotalsStats.getCurrentEndTime());
128135
break;
129136
}
130137
}
131138
try (FlowScopeLog log = new FlowScopeLogBuilder(LOGGER, Level.FINE, "StateStatistics:histogramQuery").build()) { //$NON-NLS-1$
139+
addHistogramValuesFromQuery2d(quark, times, list);
140+
/* Padding for after trace ends */
141+
for (int i = list.size(); i < timeRequested.length; i++) {
142+
list.add(0L);
143+
}
144+
return list;
145+
}
146+
}
147+
148+
private List<@NonNull Long> addHistogramValuesFromQuery2d(int quark, List<@NonNull Long> times, List<@NonNull Long> results) {
149+
try {
132150
Iterable<@NonNull ITmfStateInterval> intervals = fTotalsStats.query2D(Collections.singletonList(quark), times);
133151
List<@NonNull ITmfStateInterval> sortedIntervals = Lists.newArrayList(intervals);
152+
if (sortedIntervals.isEmpty()) {
153+
return results;
154+
}
134155
sortedIntervals.sort(Comparator.comparingLong(ITmfStateInterval::getStartTime));
135-
int j = 0;
136156
long previousTotal;
137-
if (!sortedIntervals.isEmpty() && fTotalsStats.getStartTime() != sortedIntervals.get(0).getStartTime()) {
138-
previousTotal = sortedIntervals.get(0).getValueInt();
157+
if (fTotalsStats.getStartTime() != sortedIntervals.get(0).getStartTime()) {
158+
previousTotal = sortedIntervals.get(0).getValueLong();
139159
} else {
140160
previousTotal = 0;
141161
}
142-
for (int i = 0; i < timeRequested.length; i++) {
143-
while (j < sortedIntervals.size() - 1 && sortedIntervals.get(j).getEndTime() < timeRequested[i]) {
162+
int j = 0;
163+
for (int i = 0; i < times.size(); i++) {
164+
while (j < sortedIntervals.size() - 1 && sortedIntervals.get(j).getEndTime() < times.get(i)) {
144165
j++;
145166
}
146-
long count = sortedIntervals.get(j).getValueInt() - previousTotal;
147-
list.add(count);
148-
previousTotal = sortedIntervals.get(j).getValueInt();
167+
long count = sortedIntervals.get(j).getValueLong() - previousTotal;
168+
results.add(count);
169+
previousTotal = sortedIntervals.get(j).getValueLong();
149170
}
150-
return list;
171+
return results;
151172
} catch (StateSystemDisposedException e) {
152-
/* Assume there is no events, nothing will be put in the histogram. */
153-
return Collections.emptyList();
173+
/*
174+
* Assume there is no events, nothing will be put in the histogram.
175+
*/
176+
return results;
154177
}
155178
}
156179

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsEventTypesModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class StatsProviderEventTypes extends AbstractTmfStateProvider {
101101
* Version number of this input handler. Please bump this if you modify the
102102
* contents of the generated state history in some way.
103103
*/
104-
private static final int VERSION = 3;
104+
private static final int VERSION = 4;
105105

106106
/**
107107
* Constructor
@@ -139,12 +139,12 @@ protected void eventHandle(ITmfEvent event) {
139139
ITmfLostEvent le = (ITmfLostEvent) event;
140140
quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
141141

142-
int curVal = ss.queryOngoingState(quark).unboxInt();
142+
long curVal = ss.queryOngoingState(quark).unboxLong();
143143
if (curVal == -1) {
144144
curVal = 0;
145145
}
146146

147-
ss.modifyAttribute(ts, (int) (curVal + le.getNbLostEvents()), quark);
147+
ss.modifyAttribute(ts, curVal + le.getNbLostEvents(), quark);
148148

149149
long lostEventsStartTime = le.getTimeRange().getStartTime().toNanos();
150150
long lostEventsEndTime = le.getTimeRange().getEndTime().toNanos();
@@ -160,7 +160,7 @@ protected void eventHandle(ITmfEvent event) {
160160

161161
/* Number of events of each type, globally */
162162
quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
163-
StateSystemBuilderUtils.incrementAttributeInt(ss, ts, quark, 1);
163+
StateSystemBuilderUtils.incrementAttributeLong(ss, ts, quark, 1);
164164
}
165165
}
166166
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsTotalsModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class StatsProviderTotals extends AbstractTmfStateProvider {
8585
* Version number of this input handler. Please bump this if you modify the
8686
* contents of the generated state history in some way.
8787
*/
88-
private static final int VERSION = 2;
88+
private static final int VERSION = 3;
8989

9090
/**
9191
* Constructor
@@ -122,7 +122,7 @@ protected void eventHandle(ITmfEvent event) {
122122

123123
/* Total number of events */
124124
int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
125-
StateSystemBuilderUtils.incrementAttributeInt(ss, ts, quark, 1);
125+
StateSystemBuilderUtils.incrementAttributeLong(ss, ts, quark, 1);
126126
}
127127
}
128128

0 commit comments

Comments
 (0)