Search in sources :

Example 1 with TmfStatisticsModule

use of org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule in project tracecompass by tracecompass.

the class StatisticsAnalysisBenchmark method runTest.

private static void runTest(CtfTestTrace testTrace, String testName, Map<String, Long> testCases) {
    Performance perf = Performance.getDefault();
    PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
    perf.tagAsSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
    if (testTrace == CtfTestTrace.DJANGO_CLIENT || testTrace == CtfTestTrace.DJANGO_HTTPD) {
        /* Do not show all traces in the global summary */
        perf.tagAsGlobalSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
    }
    for (int i = 0; i < LOOP_COUNT; i++) {
        LttngKernelTrace trace = null;
        TmfStatisticsModule module = null;
        try {
            trace = new LttngKernelTrace();
            module = new TmfStatisticsModule();
            module.setId("test");
            // TODO Allow the utility method to return a LttngKernelTrace directly
            CtfTmfTrace ctfTmfTrace = CtfTmfTestTraceUtils.getTrace(testTrace);
            trace.initTrace(null, ctfTmfTrace.getPath(), CtfTmfEvent.class);
            module.setTrace(trace);
            pm.start();
            TmfTestHelper.executeAnalysis(module);
            pm.stop();
            ITmfStatistics stats = module.getStatistics();
            if (stats == null) {
                throw new IllegalStateException();
            }
            Map<String, Long> map = stats.getEventTypesTotal();
            /*
                 * Test each of the entries
                 */
            try {
                for (Entry<String, Long> entry : testCases.entrySet()) {
                    Long value = map.get(entry.getKey());
                    assertNotNull(value);
                    assertTrue(value.equals(entry.getValue()));
                }
            } catch (NullPointerException e) {
                fail(e.getMessage());
            }
            /*
                 * Delete the supplementary files, so that the next iteration
                 * rebuilds the state system.
                 */
            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
            for (File file : suppDir.listFiles()) {
                file.delete();
            }
        } catch (TmfAnalysisException | TmfTraceException e) {
            fail(e.getMessage());
        } finally {
            if (module != null) {
                module.dispose();
            }
            if (trace != null) {
                trace.dispose();
            }
        }
    }
    pm.commit();
    CtfTmfTestTraceUtils.dispose(testTrace);
}
Also used : LttngKernelTrace(org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace) TmfStatisticsModule(org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) PerformanceMeter(org.eclipse.test.performance.PerformanceMeter) Performance(org.eclipse.test.performance.Performance) File(java.io.File) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)

Example 2 with TmfStatisticsModule

use of org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule in project tracecompass by tracecompass.

the class HistogramDataProviderTest method testHelloLost.

/**
 * Test the {@link HistogramDataProvider} with the
 * {@link CtfTestTrace#HELLO_LOST} trace. Ensure that the expected tree and xy
 * models are returned
 *
 * @throws TmfAnalysisException
 *             if the trace is set more that once
 */
@Test
public void testHelloLost() throws TmfAnalysisException {
    CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.HELLO_LOST);
    TmfStatisticsModule module = new TmfStatisticsModule();
    module.setName("Statistics");
    assertTrue("Statistics Analysis should apply to this trace", module.setTrace(trace));
    assertEquals("Statistics Analysis shouls be schedulable", Status.OK_STATUS, module.schedule());
    assertTrue("Statistics Analysis should run successfully", module.waitForCompletion());
    try {
        HistogramDataProvider provider = new HistogramDataProvider(trace, module);
        TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> treeResponse = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(START, END, 2)), null);
        assertEquals("Response Status should be COMPLETED, as we waited for the analysis to complete", ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
        TmfTreeModel<@NonNull TmfTreeDataModel> treeModel = treeResponse.getModel();
        assertNotNull(treeModel);
        assertEquals(EXPECTED_FULL_PATHS, getFullPaths(treeModel.getEntries()));
        List<Long> ids = Lists.transform(treeModel.getEntries(), TmfTreeDataModel::getId);
        SelectionTimeQueryFilter selectionFilter = new SelectionTimeQueryFilter(START, END, 100, ids);
        TmfModelResponse<@NonNull ITmfXyModel> xyResponse = provider.fetchXY(FetchParametersUtils.selectionTimeQueryToMap(selectionFilter), null);
        assertEquals("Response Status should be COMPLETED, as we waited for the analysis to complete", ITmfResponse.Status.COMPLETED, xyResponse.getStatus());
        ITmfXyModel xyModel = xyResponse.getModel();
        assertNotNull(xyModel);
        assertEquals(EXPECTED_YDATA, Maps.uniqueIndex(xyModel.getSeriesData(), ISeriesModel::getId));
    } finally {
        module.dispose();
        CtfTmfTestTraceUtils.dispose(CtfTestTrace.HELLO_LOST);
    }
}
Also used : TmfStatisticsModule(org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule) HistogramDataProvider(org.eclipse.tracecompass.internal.tmf.core.histogram.HistogramDataProvider) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull) 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) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) Test(org.junit.Test)

Example 3 with TmfStatisticsModule

use of org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule in project tracecompass by tracecompass.

the class TmfStatisticsViewer method buildStatisticsTree.

/**
 * Requests all the data of the trace to the state system which contains
 * information about the statistics.
 *
 * Since the viewer may be listening to multiple traces, it may receive an
 * experiment rather than a single trace. The filtering is done with the
 * method {@link #isListeningTo(String trace)}.
 *
 * @param trace
 *            The trace for which a request must be done
 * @param timeRange
 *            The time range that will be requested to the state system
 * @param isGlobal
 *            Tells if the request is for the global event count or the
 *            partial one.
 */
private void buildStatisticsTree(final ITmfTrace trace, final TmfTimeRange timeRange, final boolean isGlobal) {
    final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
    if (statsData == null) {
        return;
    }
    Map<ITmfTrace, Job> updateJobs;
    if (isGlobal) {
        updateJobs = fUpdateJobsGlobal;
    } else {
        updateJobs = fUpdateJobsPartial;
    }
    for (ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) {
        if (!isListeningTo(aTrace)) {
            continue;
        }
        /* Retrieve the statistics object */
        final TmfStatisticsModule statsMod = TmfTraceUtils.getAnalysisModuleOfClass(aTrace, TmfStatisticsModule.class, TmfStatisticsModule.ID);
        if (statsMod == null) {
            /* No statistics module available for this trace */
            continue;
        }
        updateJobs.computeIfAbsent(aTrace, k -> {
            // $NON-NLS-1$
            Job job = new StatisticsUpdateJob("Statistics update", aTrace, isGlobal, timeRange, statsMod, this);
            job.setSystem(true);
            job.schedule();
            return job;
        });
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfStatisticsTree(org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree) TmfStatisticsModule(org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

TmfStatisticsModule (org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule)3 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)2 File (java.io.File)1 Job (org.eclipse.core.runtime.jobs.Job)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Performance (org.eclipse.test.performance.Performance)1 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)1 HistogramDataProvider (org.eclipse.tracecompass.internal.tmf.core.histogram.HistogramDataProvider)1 TmfStatisticsTree (org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree)1 LttngKernelTrace (org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace)1 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)1 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)1 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)1 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)1 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)1 ITmfStatistics (org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1 Test (org.junit.Test)1