use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel in project tracecompass by tracecompass.
the class InputOutputDataProviderTest method testDiskActivity.
/**
* Test the data provider
*/
@Test
public void testDiskActivity() {
DisksIODataProvider provider = getProvider();
Collection<@NonNull DiskActivity> diskActivity = fTestCase.getDiskActivity();
for (DiskActivity test : diskActivity) {
Map<@NonNull String, @NonNull Object> parameters = test.getTimeQuery();
TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> response = provider.fetchTree(parameters, PROGRESS_MONITOR);
assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus());
TmfTreeModel<@NonNull TmfTreeDataModel> model = response.getModel();
assertNotNull(model);
parameters = test.getTimeQueryForModel(model);
TmfModelResponse<@NonNull ITmfXyModel> yResponse = provider.fetchXY(parameters, PROGRESS_MONITOR);
assertEquals(ITmfResponse.Status.COMPLETED, yResponse.getStatus());
ITmfXyModel yModel = yResponse.getModel();
assertNotNull(yModel);
Collection<@NonNull ISeriesModel> data = yModel.getSeriesData();
assertEquals(1, data.size());
ISeriesModel ySeries = data.iterator().next();
double[] expected = test.getActivity();
double[] actual = ySeries.getData();
for (int i = 0; i < expected.length; i++) {
assertTrue(String.format("No actual value at position %d for %s", i, test), actual.length > i);
assertEquals(String.format("Value at position %d for %s", i, test), expected[i], actual[i], 0.001);
}
assertEquals(String.format("More values than expected for %s", test), expected.length, actual.length);
}
}
use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel in project tracecompass by tracecompass.
the class CPUAnalysisBenchmark method benchmarkCPUModule.
@SuppressWarnings("restriction")
private static void benchmarkCPUModule(String testName, @NonNull LttngKernelTrace trace, int loopCount) throws TmfAnalysisException {
Performance perf = Performance.getDefault();
PerformanceMeter pmAnalysisExecution = perf.createPerformanceMeter(TEST_ID + testName + ": " + TEST_ANALYSIS_EXECUTION);
perf.tagAsSummary(pmAnalysisExecution, TEST_ANALYSIS_EXECUTION + '(' + testName + ')', Dimension.CPU_TIME);
PerformanceMeter pmQueryUsage = perf.createPerformanceMeter(TEST_ID + testName + ": " + TEST_ANALYSIS_QUERY);
perf.tagAsSummary(pmQueryUsage, TEST_ANALYSIS_QUERY + '(' + testName + ')', Dimension.CPU_TIME);
for (int i = 0; i < loopCount; i++) {
KernelCpuUsageAnalysis module = getModule(trace);
try {
pmAnalysisExecution.start();
TmfTestHelper.executeAnalysis(module);
pmAnalysisExecution.stop();
CpuUsageDataProvider dataProvider = CpuUsageDataProvider.create(trace);
assertNotNull(dataProvider);
// Query all CPU Usage for full time range, then 10 times 10%
// smaller ranges
int resolution = 1500;
long startTime = trace.getStartTime().toNanos();
long endTime = trace.getEndTime().toNanos();
pmQueryUsage.start();
for (int j = 0; j < 10; j++) {
// Query the tree for that range
TimeQueryFilter filter = new SelectedCpuQueryFilter(startTime, endTime, 2, Collections.emptyList(), Collections.emptySet());
@NonNull Map<@NonNull String, @NonNull Object> parameters = new HashMap<>();
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
parameters.put(DataProviderParameterUtils.REQUESTED_ITEMS_KEY, Collections.emptyList());
parameters.put("cpus", Collections.emptySet());
TmfModelResponse<@NonNull TmfTreeModel<@NonNull CpuUsageEntryModel>> response = dataProvider.fetchTree(parameters, NULL_MONITOR);
TmfTreeModel<@NonNull CpuUsageEntryModel> model = response.getModel();
assertNotNull(model);
List<CpuUsageEntryModel> entries = model.getEntries();
assertNotNull(entries);
// Add all entries to the list of selected
List<Long> selected = new ArrayList<>();
for (CpuUsageEntryModel entry : entries) {
selected.add(entry.getId());
}
// Get the usage for all threads
filter = new SelectedCpuQueryFilter(startTime, endTime, resolution, selected, Collections.emptySet());
parameters = new HashMap<>();
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
parameters.put(DataProviderParameterUtils.REQUESTED_ITEMS_KEY, selected);
parameters.put("cpus", Collections.emptySet());
TmfModelResponse<@NonNull ITmfXyModel> fetchXY = dataProvider.fetchXY(parameters, NULL_MONITOR);
ITmfXyModel model2 = fetchXY.getModel();
assertNotNull(model2);
// Reduce the time range
long step = (endTime - startTime) / 20;
startTime += step;
endTime -= step;
}
pmQueryUsage.stop();
} finally {
module.dispose();
}
}
pmAnalysisExecution.commit();
pmQueryUsage.commit();
}
use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel in project tracecompass by tracecompass.
the class XmlXyDataProviderTest method assertRows.
private static void assertRows(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, Map<Long, String> tree, List<String> expectedStrings) {
TmfModelResponse<@NonNull ITmfXyModel> rowResponse = xyProvider.fetchXY(FetchParametersUtils.selectionTimeQueryToMap(new SelectionTimeQueryFilter(1, 20, 20, tree.keySet())), null);
assertNotNull(rowResponse);
assertEquals(ITmfResponse.Status.COMPLETED, rowResponse.getStatus());
ITmfXyModel rowModel = rowResponse.getModel();
assertNotNull(rowModel);
Collection<@NonNull ISeriesModel> series = rowModel.getSeriesData();
ImmutableMap<Long, @NonNull ISeriesModel> data = Maps.uniqueIndex(series, ISeriesModel::getId);
for (int i = 0; i < expectedStrings.size(); i++) {
String expectedString = expectedStrings.get(i);
String[] split = expectedString.split(":");
String rowName = split[0];
Long rowId = null;
for (Entry<Long, String> entry : tree.entrySet()) {
if (entry.getValue().equals(rowName)) {
rowId = entry.getKey();
break;
}
}
assertNotNull(rowId);
ISeriesModel row = data.get(rowId);
assertNotNull(row);
String[] expectedData = split[1].split(",");
double[] actualData = row.getData();
for (int j = 0; j < expectedData.length; j++) {
assertTrue("Presence of data at position " + j + " for row " + rowName, actualData.length > j);
double expectedValue = Double.parseDouble(expectedData[j]);
assertEquals("Data at position " + j + " for row " + rowName, expectedValue, actualData[j], 0.001);
}
}
assertEquals("Same number of data", expectedStrings.size(), data.size());
}
use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel in project tracecompass by tracecompass.
the class TmfXyResponseFactory method create.
/**
* Create a {@link TmfModelResponse} for values with a common X axis values,
* with a either RUNNING or COMPLETED status. Model is not null, it's either
* partial or full.
*
* @param title
* Chart title
* @param xValues
* The x values requested by the viewer
* @param yModels
* Collection of IYModel
* @param isComplete
* Tells whether the computed model is complete or partial
* @return A {@link TmfModelResponse} with either a running status or a
* completed status
*/
public static TmfModelResponse<ITmfXyModel> create(String title, long[] xValues, Collection<IYModel> yModels, boolean isComplete) {
List<ISeriesModel> series = Lists.transform(new ArrayList<>(yModels), model -> {
SeriesModelBuilder builder = new SeriesModelBuilder(model.getId(), model.getName(), xValues, model.getData());
TmfXYAxisDescription yAxis = model.getYAxisDescription();
if (yAxis != null) {
builder.yAxisDescription(yAxis);
}
return builder.build();
});
ITmfXyModel model = new TmfXyModel(title, series);
if (isComplete) {
return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, Objects.requireNonNull(CommonStatusMessage.COMPLETED));
}
return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, Objects.requireNonNull(CommonStatusMessage.RUNNING));
}
use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel 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()));
}
}
Aggregations