Search in sources :

Example 1 with CpuUsageEntryModel

use of org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel 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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KernelCpuUsageAnalysis(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis) SelectedCpuQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter) CpuUsageDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider) NonNull(org.eclipse.jdt.annotation.NonNull) PerformanceMeter(org.eclipse.test.performance.PerformanceMeter) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Performance(org.eclipse.test.performance.Performance) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 2 with CpuUsageEntryModel

use of org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel in project tracecompass by tracecompass.

the class CpuUsageDataProvider method getTree.

/**
 * @since 2.5
 */
@Override
protected TmfTreeModel<CpuUsageEntryModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(parameters);
    if (filter == null) {
        return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
    }
    long end = filter.getEnd();
    List<CpuUsageEntryModel> entryList = new ArrayList<>();
    Set<Integer> cpus = extractCpuSet(parameters);
    Map<String, Long> cpuUsageMap = getAnalysisModule().getCpuUsageInRange(cpus, filter.getStart(), end);
    double timeRange = end - filter.getStart();
    long totalTime = cpuUsageMap.getOrDefault(KernelCpuUsageAnalysis.TOTAL, 0l);
    long totalId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
    entryList.add(new CpuUsageEntryModel(totalId, -1, ImmutableList.of(getTrace().getName(), String.valueOf(Messages.CpuUsageDataProvider_Total), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * totalTime / timeRange : (float) 0), TIME_FORMATTER.format(totalTime)), TOTAL_SERIES_TID, totalTime));
    for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
        /*
             * Process only entries representing the total of all CPUs and that
             * have time on CPU
             */
        String key = entry.getKey();
        if (entry.getValue() == 0 || !key.startsWith(KernelCpuUsageAnalysis.TOTAL)) {
            continue;
        }
        String[] strings = key.split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
        if (strings.length > 1) {
            int tid = Integer.parseInt(strings[1]);
            Long time = entry.getValue();
            if (tid != 0) {
                entryList.add(new CpuUsageEntryModel(getId(tid), totalId, ImmutableList.of(getProcessName(tid, strings[1], end), String.valueOf(tid), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * time / timeRange : (float) 0), TIME_FORMATTER.format(time)), tid, time));
            }
        }
    }
    return new TmfTreeModel<>(ImmutableList.of(String.valueOf(Messages.CpuUsageDataProvider_ColumnProcess), OsStrings.tid(), String.valueOf(Messages.CpuUsageDataProvider_ColumnPercent), String.valueOf(Messages.CpuUsageDataProvider_ColumnTime)), entryList);
}
Also used : ArrayList(java.util.ArrayList) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)

Example 3 with CpuUsageEntryModel

use of org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel 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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) SelectedCpuQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter) CpuUsageDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel) Test(org.junit.Test)

Example 4 with CpuUsageEntryModel

use of org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel in project tracecompass by tracecompass.

the class CpuUsageDataProviderTest method compareModel.

private static void compareModel(Map<Integer, Long> expected, TmfTreeModel<@NonNull CpuUsageEntryModel> model) {
    List<@NonNull CpuUsageEntryModel> entries = model.getEntries();
    // Compare the headers
    assertEquals("Size of headers", 4, model.getHeaders().size());
    assertEquals("Size of model entries", expected.size(), entries.size());
    Map<Integer, Long> actual = new HashMap<>();
    for (CpuUsageEntryModel entry : entries) {
        actual.put(entry.getTid(), entry.getTime());
        assertEquals("Size of labels array", model.getHeaders().size(), entry.getLabels().size());
    }
    assertEquals("model entries", expected, actual);
}
Also used : HashMap(java.util.HashMap) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)

Example 5 with CpuUsageEntryModel

use of org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel in project tracecompass by tracecompass.

the class CpuUsageTreeViewer method modelToTree.

@Override
protected ITmfTreeViewerEntry modelToTree(long start, long end, List<ITmfTreeDataModel> model) {
    double time = end - start;
    Map<Long, TmfTreeViewerEntry> map = new HashMap<>();
    // $NON-NLS-1$
    TmfTreeViewerEntry root = new TmfTreeViewerEntry("");
    map.put(-1L, root);
    for (CpuUsageEntryModel entryModel : Iterables.filter(model, CpuUsageEntryModel.class)) {
        // Add a total series to the presentation provider if the tid is < 0
        int tid = entryModel.getTid();
        if (tid < 0) {
            fPresentationProvider.addTotalSeries(entryModel.getId());
        }
        CpuUsageEntry cpuUsageEntry = new CpuUsageEntry(entryModel, entryModel.getTime() / time);
        map.put(entryModel.getId(), cpuUsageEntry);
        TmfTreeViewerEntry parent = map.get(entryModel.getParentId());
        if (parent != null) {
            parent.addChild(cpuUsageEntry);
        }
    }
    return root;
}
Also used : TmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) HashMap(java.util.HashMap) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)

Aggregations

CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)5 HashMap (java.util.HashMap)4 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)3 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)3 ArrayList (java.util.ArrayList)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 CpuUsageDataProvider (org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider)2 SelectedCpuQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Performance (org.eclipse.test.performance.Performance)1 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)1 KernelCpuUsageAnalysis (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis)1 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)1 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)1 ITmfTreeViewerEntry (org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry)1 TmfTreeViewerEntry (org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry)1 Test (org.junit.Test)1