use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class KernelMemoryUsageDataProvider method getYSeriesModels.
/**
* @since 2.5
*/
@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();
/**
* For a given time range, we plot lines representing the memory allocation for
* the total and the selected entries.
*/
double[] totalKernelMemoryValues = new double[xValues.length];
Map<Integer, IYModel> selectedSeries = initSeries(ss, filter);
List<Integer> threadQuarkList = ss.getSubAttributes(-1, false);
if (threadQuarkList.isEmpty()) {
return Collections.emptyList();
}
Collection<Long> times = getTimes(filter, ss.getStartTime(), currentEnd);
for (ITmfStateInterval interval : ss.query2D(threadQuarkList, times)) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
Object object = interval.getValue();
if (object instanceof Number) {
double value = ((Number) object).doubleValue();
int from = Arrays.binarySearch(xValues, interval.getStartTime());
from = (from >= 0) ? from : -1 - from;
int to = Arrays.binarySearch(xValues, from, xValues.length, interval.getEndTime());
to = (to >= 0) ? to + 1 : -1 - to;
/* We add the value of each thread to the total quantity */
for (int i = from; i < to; i++) {
totalKernelMemoryValues[i] += value;
}
IYModel selectedThreadValues = selectedSeries.get(interval.getAttribute());
if (selectedThreadValues != null) {
Arrays.fill(selectedThreadValues.getData(), from, to, value);
}
}
}
/**
* We shift the series up.
*/
List<ITmfStateInterval> endState = ss.queryFullState(Long.min(filter.getEnd(), currentEnd));
double d = extractTotalValueShift(ss, endState);
Arrays.setAll(totalKernelMemoryValues, i -> totalKernelMemoryValues[i] + d);
for (Entry<Integer, IYModel> entry : selectedSeries.entrySet()) {
int lowestMemoryQuark = ss.optQuarkRelative(entry.getKey(), KernelMemoryAnalysisModule.THREAD_LOWEST_MEMORY_VALUE);
if (lowestMemoryQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
Object value = endState.get(lowestMemoryQuark).getValue();
if (value instanceof Number) {
double[] threadValues = entry.getValue().getData();
double shift = ((Number) value).doubleValue();
Arrays.setAll(threadValues, i -> threadValues[i] - shift);
}
}
}
ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
String total = getTrace().getName() + MemoryUsageTreeModel.TOTAL_SUFFIX;
ySeries.add(new YModel(getId(ITmfStateSystem.ROOT_ATTRIBUTE), total, totalKernelMemoryValues));
ySeries.addAll(selectedSeries.values());
return ySeries.build();
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class KernelMemoryUsageDataProvider method initSeries.
/**
* Initialize a map of quark to primitive double array
*
* @param filter
* the query object
* @return a Map of quarks for the entries which exist for this provider to
* newly initialized primitive double arrays of the same length as the
* number of requested timestamps.
*/
private Map<Integer, IYModel> initSeries(ITmfStateSystem ss, SelectionTimeQueryFilter filter) {
int length = filter.getTimesRequested().length;
Map<Integer, IYModel> map = new HashMap<>();
for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
String selectedThreadName = getTrace().getName() + ':' + ss.getAttributeName(entry.getValue());
map.put(entry.getValue(), new YModel(entry.getKey(), selectedThreadName, new double[length]));
}
return map;
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class XYDataProviderBaseTest method extractModelFromChart.
/**
* From a SWT Chart, this method extract a {@link TmfCommonXAxisModel} that
* represents the chart. Since, we unfortunately have no mecanism to deserialize
* with GSON, we have to compare strings. So, once the model is extract from the
* Chart, we serialize it and compare with a string
*
* @param chart
* A SWT Chart
* @param otherSeries
* Name of other series to extract from Chart
* @return A {@link TmfCommonXAxisModel}
*/
protected TmfCommonXAxisModel extractModelFromChart(final Chart chart, String... otherSeries) {
String mainSeriesName = getMainSeriesName();
ISeries<Integer> mainSeries = chart.getSeriesSet().getSeries(mainSeriesName);
if (mainSeries == null) {
System.out.println("Main Series " + mainSeriesName + " not found in chart");
return null;
}
/* X and Y Values shown in chart */
double[] xMain = getXSeries(mainSeries);
double[] yMain = getYSeries(mainSeries);
Map<@NonNull String, @NonNull IYModel> yModels = new LinkedHashMap<>();
yModels.put(mainSeriesName, new YModel(-1, mainSeriesName, Objects.requireNonNull(yMain)));
for (String other : otherSeries) {
if (other != null) {
ISeries<Integer> series = chart.getSeriesSet().getSeries(other);
if (series == null) {
System.out.println("Series " + other + " not found in chart");
return null;
}
/* X and Y Values shown in chart */
double[] xSeries = getXSeries(series);
double[] ySeries = getYSeries(series);
/* Series should have the same x axis values, not finished updating all series*/
if (!Arrays.equals(xMain, xSeries)) {
System.out.println("Series don't currently have the same x axis values");
return null;
}
yModels.put(other, new YModel(-1, other, Objects.requireNonNull(ySeries)));
}
}
long[] x = Longs.toArray(Doubles.asList(xMain));
assertNotNull(x);
return new TmfCommonXAxisModel(getTitle(), x, yModels.values());
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class ExampleXYDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
ITmfStateSystem ss = getAnalysisModule().getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
Map<Integer, double[]> quarkToValues = new HashMap<>();
// Prepare the quarks to display
Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
if (selectedItems == null) {
// No selected items, take them all
selectedItems = fIDToDisplayQuark.keySet();
}
List<Long> times = getTimes(ss, DataProviderParameterUtils.extractTimeRequested(fetchParameters));
for (Long id : selectedItems) {
Integer quark = fIDToDisplayQuark.get(id);
if (quark != null) {
quarkToValues.put(quark, new double[times.size()]);
}
}
long[] nativeTimes = new long[times.size()];
for (int i = 0; i < times.size(); i++) {
nativeTimes[i] = times.get(i);
}
// Query the state system to fill the array of values
try {
for (ITmfStateInterval interval : ss.query2D(quarkToValues.keySet(), times)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
double[] row = quarkToValues.get(interval.getAttribute());
Object value = interval.getValue();
if (row != null && (value instanceof Number)) {
Double dblValue = ((Number) value).doubleValue();
for (int i = 0; i < times.size(); i++) {
Long time = times.get(i);
if (interval.getStartTime() <= time && interval.getEndTime() >= time) {
row[i] = dblValue;
}
}
}
}
} catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
List<IYModel> models = new ArrayList<>();
for (Entry<Integer, double[]> values : quarkToValues.entrySet()) {
models.add(new YModel(fIDToDisplayQuark.inverse().getOrDefault(values.getKey(), -1L), values.getValue()));
}
// $NON-NLS-1$
return new TmfModelResponse<>(new TmfCommonXAxisModel("Example XY data provider", nativeTimes, models), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.
the class DataDrivenXYDataProvider method initSeries.
private Map<DisplayElement, IYModel> initSeries(TimeQueryFilter filter) {
if (!(filter instanceof SelectionTimeQueryFilter)) {
return Collections.emptyMap();
}
fLock.readLock().lock();
try {
Map<DisplayElement, IYModel> map = new HashMap<>();
int length = filter.getTimesRequested().length;
for (Long id : ((SelectionTimeQueryFilter) filter).getSelectedItems()) {
DisplayElement displayElement = fIDToDisplayQuark.get(id);
if (displayElement != null) {
String name = String.valueOf(fIdToTitle.get(id));
map.put(displayElement, new YModel(id, name, new double[length]));
}
}
return map;
} finally {
fLock.readLock().unlock();
}
}
Aggregations