Search in sources :

Example 1 with ITmfStatistics

use of org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics 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 ITmfStatistics

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

the class HistogramDataProvider method fetchXY.

@Override
@NonNull
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fModule.waitForInitialization();
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    long[] xValues = new long[0];
    if (filter == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    xValues = filter.getTimesRequested();
    Collection<Long> selected = filter.getSelectedItems();
    int n = xValues.length;
    ImmutableList.Builder<IYModel> builder = ImmutableList.builder();
    final ITmfStatistics stats = Objects.requireNonNull(fModule.getStatistics());
    if (selected.contains(fTotalId)) {
        List<Long> values = stats.histogramQuery(filter.getTimesRequested());
        double[] y = new double[n];
        Arrays.setAll(y, values::get);
        String totalName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Total;
        builder.add(new YModel(fTotalId, totalName, y));
    }
    ITmfStateSystem eventsSs = fModule.getStateSystem(TmfStatisticsEventTypesModule.ID);
    if (selected.contains(fLostId) && eventsSs != null) {
        try {
            YModel series = getLostEvents(eventsSs, xValues);
            builder.add(series);
        } catch (StateSystemDisposedException e) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.STATE_SYSTEM_FAILED);
        }
    }
    boolean completed = eventsSs != null ? eventsSs.waitUntilBuilt(0) || eventsSs.getCurrentEndTime() >= filter.getEnd() : false;
    return TmfXyResponseFactory.create(TITLE, xValues, builder.build(), completed);
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) ImmutableList(com.google.common.collect.ImmutableList) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 3 with ITmfStatistics

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

the class StatisticsUpdateJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    IStatus st = fStatsMod.schedule();
    if (!st.isOK()) {
        return st;
    }
    /* Wait until the analysis is ready to be queried */
    if (!fStatsMod.waitForInitialization()) {
        return Status.CANCEL_STATUS;
    }
    ITmfStatistics stats = fStatsMod.getStatistics();
    if (stats == null) {
        /* It should have worked, but didn't */
        throw new IllegalStateException();
    }
    /*
         * TODO Eventually this could be exposed through the
         * TmfStateSystemAnalysisModule directly.
         */
    ITmfStateSystem ss = fStatsMod.getStateSystem(TmfStatisticsEventTypesModule.ID);
    if (ss == null) {
        /*
             * It should be instantiated after the
             * statsMod.waitForInitialization() above.
             */
        throw new IllegalStateException();
    }
    /*
         * Periodically update the statistics while they are being built (or, if
         * the back-end is already completely built, it will skip over the
         * while() immediately.
         */
    long start = 0;
    long end = 0;
    boolean finished = false;
    do {
        /* This model update is done every second */
        if (monitor.isCanceled()) {
            fViewer.removeFromJobs(fIsGlobal, fJobTrace);
            return Status.CANCEL_STATUS;
        }
        finished = ss.waitUntilBuilt(LIVE_UPDATE_DELAY);
        TmfTimeRange localtimeRange = fTimerange;
        /*
             * The generic statistics are stored in nanoseconds, so we must make
             * sure the time range is scaled correctly.
             */
        start = localtimeRange.getStartTime().toNanos();
        end = localtimeRange.getEndTime().toNanos();
        Map<String, Long> map = stats.getEventTypesInRange(start, end);
        updateStats(map);
    } while (!finished);
    /* Query one last time for the final values */
    Map<String, Long> map = stats.getEventTypesInRange(start, end);
    updateStats(map);
    fViewer.refreshPieCharts(fIsGlobal, !fIsGlobal);
    /*
         * Remove job from map so that new range selection updates can be
         * processed.
         */
    fViewer.removeFromJobs(fIsGlobal, fJobTrace);
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

ITmfStatistics (org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IStatus (org.eclipse.core.runtime.IStatus)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Performance (org.eclipse.test.performance.Performance)1 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)1 LttngKernelTrace (org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace)1 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)1 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)1 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)1 YModel (org.eclipse.tracecompass.tmf.core.model.YModel)1 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)1 IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)1 TmfStatisticsModule (org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule)1 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)1