use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class DataDrivenXYDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
long[] xValues = filter.getTimesRequested();
filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
Map<DisplayElement, IYModel> map = initSeries(filter);
if (map.isEmpty()) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
ITmfStateSystem ss = null;
for (DisplayElement de : map.keySet()) {
ss = de.fStateSystem;
}
if (ss == null) {
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<DisplayElement, IYModel> series : map.entrySet()) {
int attributeQuark = series.getKey().fQuark;
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<DisplayElement, IYModel> series : map.entrySet()) {
if (series.getKey().fDisplayType.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, ImmutableList.copyOf(map.values()), complete);
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel 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.xy.IYModel in project tracecompass by tracecompass.
the class AbstractTreeCommonXDataProvider method fetchXY.
@Override
public final TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
A module = getAnalysisModule();
// TODO server: Parameters validation should be handle separately. It
// can be either in the data provider itself or before calling it. It
// will avoid the creation of filters and the content of the map can be
// use directly.
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
TmfModelResponse<ITmfXyModel> res = verifyParameters(module, filter, monitor);
if (res != null) {
return res;
}
ITmfStateSystem ss = Objects.requireNonNull(module.getStateSystem(), // $NON-NLS-1$
"Statesystem should have been verified by verifyParameters");
long currentEnd = ss.getCurrentEndTime();
boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
try (FlowScopeLog scope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeXyDataProvider#fetchXY").setCategory(getClass().getSimpleName()).build()) {
Collection<IYModel> yModels = getYSeriesModels(ss, fetchParameters, monitor);
if (yModels == null) {
// getModels returns null if the query was cancelled.
return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
}
return TmfXyResponseFactory.create(getTitle(), filter.getTimesRequested(), ImmutableList.copyOf(yModels), complete);
} catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
return TmfXyResponseFactory.createFailedResponse(String.valueOf(e.getMessage()));
}
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class TmfTreeXYCompositeDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
/**
* <pre>
* Response status according to the provider's reponse statuses:
*
* * Cancelled -> The monitor is cancelled
* * Failed -> At least one provider has failed
* * Running -> At least one of the providers is running
* * Completed -> All providers have completed
* </pre>
*/
List<P> providers = getProviders();
// Get all the responses
Collection<TmfModelResponse<ITmfXyModel>> responses = getXyResponses(fetchParameters, monitor, providers);
if (monitor != null && monitor.isCanceled()) {
return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
}
// If one response is failed, return a failed response with a concatenation of the messages
String failedMsg = handleFailedStatus(responses);
if (failedMsg != null) {
return TmfXyResponseFactory.createFailedResponse(failedMsg);
}
boolean allCommon = Iterables.all(providers, ITmfCommonXAxisModel.class::isInstance);
// The query is considered complete if all providers are completed
boolean isComplete = Iterables.all(responses, response -> response.getStatus() == ITmfResponse.Status.COMPLETED);
if (allCommon) {
ImmutableList.Builder<IYModel> series = ImmutableList.builder();
responses.forEach(response -> {
ITmfCommonXAxisModel model = (ITmfCommonXAxisModel) response.getModel();
if (model != null) {
series.addAll(model.getYSeriesData());
}
});
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
return TmfXyResponseFactory.create(fTitle, filter.getTimesRequested(), series.build(), isComplete);
}
ImmutableList.Builder<ISeriesModel> series = ImmutableList.builder();
responses.forEach(response -> {
ITmfXyModel model = response.getModel();
if (model != null) {
series.addAll(model.getSeriesData());
}
});
return TmfXyResponseFactory.create(fTitle, series.build(), isComplete);
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel 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