use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class CounterDataProvider method internalFetch.
@Nullable
private Collection<IYModel> internalFetch(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
SelectedCounterQueryFilter filter = createCounterQuery(fetchParameters);
if (filter == null) {
return null;
}
long stateSystemEndTime = ss.getCurrentEndTime();
Collection<Long> times = extractRequestedTimes(ss, filter, stateSystemEndTime);
Map<Long, Integer> entries = Maps.filterValues(getSelectedEntries(filter), q -> ss.getSubAttributes(q, false).isEmpty());
TreeMultimap<Integer, ITmfStateInterval> countersIntervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparingLong(ITmfStateInterval::getStartTime));
Iterable<@NonNull ITmfStateInterval> query2d = ss.query2D(entries.values(), times);
for (ITmfStateInterval interval : query2d) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
countersIntervals.put(interval.getAttribute(), interval);
}
ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
for (Entry<Long, Integer> entry : entries.entrySet()) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
int quark = entry.getValue();
double[] yValues = buildYValues(countersIntervals.get(quark), filter);
String seriesName = getTrace().getName() + '/' + ss.getFullAttributePath(quark);
ySeries.add(new YModel(entry.getKey(), seriesName, yValues));
}
return ySeries.build();
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class UstMemoryUsageDataProvider method getYSeriesModels.
/**
* @since 3.3
*/
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return null;
}
long[] xValues = filter.getTimesRequested();
long currentEnd = ss.getCurrentEndTime();
Map<Integer, IYModel> models = initYModels(ss, filter);
for (ITmfStateInterval interval : ss.query2D(models.keySet(), getTimes(filter, ss.getStartTime(), currentEnd))) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
IYModel model = models.get(interval.getAttribute());
Object value = interval.getValue();
if (model != null && value instanceof Number) {
int from = Arrays.binarySearch(xValues, interval.getStartTime());
from = (from >= 0) ? from : -1 - from;
int to = Arrays.binarySearch(xValues, interval.getEndTime());
to = (to >= 0) ? to + 1 : -1 - to;
Arrays.fill(model.getData(), from, to, ((Number) value).doubleValue());
}
}
return models.values();
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class UstMemoryUsageDataProvider method initYModels.
/**
* Get map of UST_MEMORY_MEMORY_ATTRIBUTE to relevant model
*
* @param ss
* the queried {@link ITmfStateSystem}
* @param filter
* the {@link TimeQueryFilter}
* @return a map of the UST_MEMORY_MEMORY_ATTRIBUTE attributes to the
* initialized model
*/
private Map<Integer, IYModel> initYModels(ITmfStateSystem ss, SelectionTimeQueryFilter filter) {
Map<Integer, IYModel> selectedSeries = new HashMap<>();
int length = filter.getTimesRequested().length;
for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
int tidQuark = entry.getValue();
int memoryAttribute = ss.optQuarkRelative(tidQuark, UstMemoryStrings.UST_MEMORY_MEMORY_ATTRIBUTE);
if (memoryAttribute != ITmfStateSystem.INVALID_ATTRIBUTE) {
String name = getTrace().getName() + ':' + ss.getAttributeName(tidQuark);
selectedSeries.put(memoryAttribute, new YModel(entry.getKey(), name, new double[length]));
}
}
return selectedSeries;
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class XmlXYDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
DataDrivenStateSystemPath display = fDisplay;
XmlXYEntry entry = fXmlEntry;
ITmfStateSystem ss = entry.getStateSystem();
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
long[] xValues = filter.getTimesRequested();
Map<Integer, IYModel> map = initSeries(fetchParameters);
if (map.isEmpty()) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
long currentEnd = ss.getCurrentEndTime();
try {
for (int i = 0; i < xValues.length; i++) {
if (monitor != null && monitor.isCanceled()) {
return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
}
long time = xValues[i];
if (time > currentEnd) {
break;
} else if (ss.getStartTime() <= time) {
List<@NonNull ITmfStateInterval> full = ss.queryFullState(time);
for (Entry<Integer, IYModel> series : map.entrySet()) {
int attributeQuark = display.getQuark(series.getKey(), entry);
if (attributeQuark >= 0 && attributeQuark < full.size()) {
Object value = full.get(attributeQuark).getValue();
series.getValue().getData()[i] = extractValue(value);
}
}
}
}
// Update the series value if delta is requested
for (Entry<Integer, IYModel> series : map.entrySet()) {
if (entry.getType().equals(DisplayType.DELTA)) {
getSeriesDelta(series.getValue().getData());
}
}
} catch (StateSystemDisposedException e) {
return TmfXyResponseFactory.createFailedResponse(e.getMessage());
}
boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
return TmfXyResponseFactory.create(TITLE, xValues, map.values(), complete);
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class XmlXYDataProvider method initSeries.
private Map<Integer, IYModel> initSeries(Map<String, Object> parameters) {
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(parameters);
if (filter == null) {
return Collections.emptyMap();
}
fLock.readLock().lock();
try {
Map<Integer, IYModel> map = new HashMap<>();
int length = filter.getTimesRequested().length;
for (Long id : filter.getSelectedItems()) {
Integer quark = fIdToQuark.get(id);
if (quark != null) {
String name = String.valueOf(fQuarkToString.get(quark));
map.put(quark, new YModel(id, name, new double[length]));
}
}
return map;
} finally {
fLock.readLock().unlock();
}
}
Aggregations