use of org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter 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.SelectedCpuQueryFilter 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();
}
use of org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter in project tracecompass by tracecompass.
the class CpuUsageDataProviderTest method testTree.
/**
* Test the
* {@link CpuUsageDataProvider#fetchTree(Map, IProgressMonitor)}
* method.
* <p>
*/
@Test
public void testTree() {
CpuUsageDataProvider dataProvider = fDataProvider;
IProgressMonitor monitor = new NullProgressMonitor();
/* This range should query the total range */
TimeQueryFilter filter = new SelectedCpuQueryFilter(0L, 30L, 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, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
TmfTreeModel<@NonNull CpuUsageEntryModel> model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
Map<Integer, Long> expected = new HashMap<>();
expected.put(1, 5L);
expected.put(2, 19L);
expected.put(3, 11L);
expected.put(4, 13L);
expected.put(-2, 48L);
compareModel(expected, model);
/* Verify a range when a process runs at the start */
filter = new SelectedCpuQueryFilter(22L, 25L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(3, 3L);
expected.put(4, 3L);
expected.put(-2, 6L);
compareModel(expected, model);
/* Verify a range when a process runs at the end */
filter = new SelectedCpuQueryFilter(1L, 4L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(2, 3L);
expected.put(3, 1L);
expected.put(4, 2L);
expected.put(-2, 6L);
compareModel(expected, model);
/* Verify a range when a process runs at start and at the end */
filter = new SelectedCpuQueryFilter(4L, 13L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(2, 9L);
expected.put(3, 5L);
expected.put(4, 4L);
expected.put(-2, 18L);
compareModel(expected, model);
}
Aggregations