use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter 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.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class XmlXyDataProviderTest method assertAndGetTree.
private static Map<Long, String> assertAndGetTree(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, ITmfTrace trace, List<String> expectedStrings) {
TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> treeResponse = xyProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), MONITOR);
assertNotNull(treeResponse);
assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
TmfTreeModel<@NonNull ITmfTreeDataModel> treeModel = treeResponse.getModel();
assertNotNull(treeModel);
List<@NonNull ITmfTreeDataModel> treeEntries = treeModel.getEntries();
Map<Long, String> map = new HashMap<>();
for (int i = 0; i < expectedStrings.size(); i++) {
String expectedString = expectedStrings.get(i);
assertTrue("actual entry absent at " + i + ": " + expectedString, treeEntries.size() > i);
String[] split = expectedString.split(",");
ITmfTreeDataModel xmlXyEntry = treeEntries.get(i);
assertEquals("Checking entry name at " + i, split[0], xmlXyEntry.getName());
// Check the parent
long parentId = xmlXyEntry.getParentId();
if (parentId < 0) {
assertEquals("Checking empty parent at " + i, split[1], "null");
} else {
String parentName = map.get(parentId);
assertEquals("Checking parent at " + i, split[1], parentName);
}
map.put(xmlXyEntry.getId(), xmlXyEntry.getName());
}
assertEquals("Extra actual entries", expectedStrings.size(), treeEntries.size());
return map;
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class XmlXYDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
DataDrivenStateSystemPath display = fDisplay;
XmlXYEntry entry = fXmlEntry;
ITmfStateSystem ss = entry.getStateSystem();
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
long[] xValues = filter.getTimesRequested();
Map<Integer, IYModel> map = initSeries(fetchParameters);
if (map.isEmpty()) {
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<Integer, IYModel> series : map.entrySet()) {
int attributeQuark = display.getQuark(series.getKey(), entry);
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<Integer, IYModel> series : map.entrySet()) {
if (entry.getType().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, map.values(), complete);
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter 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.filters.TimeQueryFilter 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);
}
Aggregations