use of org.eclipse.tracecompass.tmf.core.model.YModel 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.YModel 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.YModel 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();
}
}
use of org.eclipse.tracecompass.tmf.core.model.YModel in project tracecompass by tracecompass.
the class HistogramDataProvider method fetchXY.
@Override
@NonNull
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
fModule.waitForInitialization();
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
long[] xValues = new long[0];
if (filter == null) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
xValues = filter.getTimesRequested();
Collection<Long> selected = filter.getSelectedItems();
int n = xValues.length;
ImmutableList.Builder<IYModel> builder = ImmutableList.builder();
final ITmfStatistics stats = Objects.requireNonNull(fModule.getStatistics());
if (selected.contains(fTotalId)) {
List<Long> values = stats.histogramQuery(filter.getTimesRequested());
double[] y = new double[n];
Arrays.setAll(y, values::get);
String totalName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Total;
builder.add(new YModel(fTotalId, totalName, y));
}
ITmfStateSystem eventsSs = fModule.getStateSystem(TmfStatisticsEventTypesModule.ID);
if (selected.contains(fLostId) && eventsSs != null) {
try {
YModel series = getLostEvents(eventsSs, xValues);
builder.add(series);
} catch (StateSystemDisposedException e) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.STATE_SYSTEM_FAILED);
}
}
boolean completed = eventsSs != null ? eventsSs.waitUntilBuilt(0) || eventsSs.getCurrentEndTime() >= filter.getEnd() : false;
return TmfXyResponseFactory.create(TITLE, xValues, builder.build(), completed);
}
use of org.eclipse.tracecompass.tmf.core.model.YModel in project tracecompass by tracecompass.
the class CpuUsageDataProvider method getYSeriesModels.
/**
* @since 2.5
*/
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
Set<Integer> cpus = Collections.emptySet();
SelectionTimeQueryFilter filter = createCpuQuery(fetchParameters);
if (filter == null) {
filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return null;
}
}
if (filter instanceof SelectedCpuQueryFilter) {
cpus = ((SelectedCpuQueryFilter) filter).getSelectedCpus();
}
long[] xValues = filter.getTimesRequested();
/* CPU usage values for total and selected thread */
double[] totalValues = new double[xValues.length];
Map<String, IYModel> selectedThreadValues = new HashMap<>();
for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
String name = Integer.toString(entry.getValue());
selectedThreadValues.put(name, new YModel(entry.getKey(), getTrace().getName() + ':' + name, new double[xValues.length]));
}
long prevTime = Math.max(getInitialPrevTime(filter), ss.getStartTime());
long currentEnd = ss.getCurrentEndTime();
for (int i = 0; i < xValues.length; i++) {
long time = xValues[i];
if (time < ss.getStartTime() || time > currentEnd) {
/* Leave empty if time xValue is out of bounds */
prevTime = time;
continue;
}
if (prevTime < time) {
Map<String, Long> cpuUsageMap = Maps.filterKeys(getAnalysisModule().getCpuUsageInRange(cpus, prevTime, time), key -> key.startsWith(KernelCpuUsageAnalysis.TOTAL));
/*
* Calculate the sum of all total entries, and add a data point to the selected
* one
*/
long totalCpu = 0;
for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
String threadName = extractThreadName(entry.getKey());
if (threadName != null) {
long cpuTime = entry.getValue();
totalCpu += cpuTime;
IYModel values = selectedThreadValues.get(threadName);
if (values != null) {
values.getData()[i] = normalize(prevTime, time, cpuTime);
}
}
}
totalValues[i] = normalize(prevTime, time, totalCpu);
} else if (i > 0) {
/* In case of duplicate time xValue copy previous yValues */
for (IYModel values : selectedThreadValues.values()) {
values.getData()[i] = values.getData()[i - 1];
}
totalValues[i] = totalValues[i - 1];
}
prevTime = time;
if (monitor != null && monitor.isCanceled()) {
return null;
}
}
ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
String key = TOTAL + getTrace().getName();
ySeries.add(new YModel(getId(ITmfStateSystem.ROOT_ATTRIBUTE), key, totalValues));
for (IYModel entry : selectedThreadValues.values()) {
ySeries.add(entry);
}
return ySeries.build();
}
Aggregations