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);
}
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);
}
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;
}
Aggregations