use of org.eclipse.tracecompass.tmf.core.model.YModel 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.YModel 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.YModel 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.YModel in project tracecompass by tracecompass.
the class HistogramDataProvider method getLostEvents.
private YModel getLostEvents(ITmfStateSystem ss, long[] times) throws StateSystemDisposedException {
int leEndQuark = ss.optQuarkAbsolute(Attributes.LOST_EVENTS);
// $NON-NLS-1$
int leCountQuark = ss.optQuarkAbsolute(Attributes.EVENT_TYPES, "Lost event");
long step = (times[times.length - 1] - times[0]) / times.length;
long lastTime = times[times.length - 1];
long firstTime = times[0];
double[] leY = new double[times.length];
long t = firstTime;
if (ss.getStartTime() <= t) {
List<ITmfStateInterval> sortedEndIntervals = Lists.newArrayList(ss.query2D(Collections.singleton(leEndQuark), firstTime, lastTime));
sortedEndIntervals.sort(Comparator.comparing(ITmfStateInterval::getStartTime));
List<ITmfStateInterval> sortedCountIntervals = Lists.newArrayList(ss.query2D(Collections.singleton(leCountQuark), firstTime, lastTime));
sortedCountIntervals.sort(Comparator.comparing(ITmfStateInterval::getStartTime));
Iterator<ITmfStateInterval> endTimeIter = sortedEndIntervals.iterator();
List<LostEventInterval> lostEventIntervals = new ArrayList<>();
ITmfStateInterval endTimeInterval = endTimeIter.next();
for (ITmfStateInterval lostCountInterval : sortedCountIntervals) {
while (!endTimeInterval.intersects(lostCountInterval.getStartTime())) {
if (!endTimeIter.hasNext()) {
throw new IllegalStateException();
}
endTimeInterval = endTimeIter.next();
}
Object endTime = endTimeInterval.getValue();
Object lostCount = lostCountInterval.getValue();
if (endTime instanceof Number && lostCount instanceof Number) {
lostEventIntervals.add(new LostEventInterval(endTimeInterval.getStartTime(), ((Number) endTime).longValue(), ((Number) lostCount).longValue()));
}
}
for (int i = 0; i < times.length - 2; i++) {
int intervalIndex;
boolean intersect = false;
for (intervalIndex = 0; intervalIndex < lostEventIntervals.size(); intervalIndex++) {
if (lostEventIntervals.get(intervalIndex).intersects(times[i], times[i + 1])) {
intersect = true;
break;
}
}
if (intersect) {
LostEventInterval lostEventInterval = lostEventIntervals.get(intervalIndex);
long prevCount = 0;
if (intervalIndex - 1 >= 0) {
prevCount = lostEventIntervals.get(intervalIndex - 1).getLostEventCount();
}
long lostEventCount = lostEventInterval.getLostEventCount();
double yValue = step * (double) (lostEventCount - prevCount) / (lostEventInterval.getEndTime() - lostEventInterval.getStartTime());
if (yValue > lostEventCount) {
yValue = (double) lostEventCount - prevCount;
}
leY[i] = yValue;
}
}
}
String lostName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Lost;
return new YModel(fLostId, lostName, leY);
}
use of org.eclipse.tracecompass.tmf.core.model.YModel 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);
}
Aggregations