lttng: Add Lttng Execution Graph analysis benchmarks
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / execgraph / KernelExecutionGraphBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis.execgraph;
11
12 import static org.junit.Assert.fail;
13
14 import java.io.File;
15 import java.util.EnumSet;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.test.performance.Dimension;
19 import org.eclipse.test.performance.Performance;
20 import org.eclipse.test.performance.PerformanceMeter;
21 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.building.LttngKernelExecutionGraph;
22 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
23 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
24 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
25 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
26 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
27 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
28 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
29 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
30 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
31 import org.junit.Test;
32
33 /**
34 * Benchmarks the kernel execution graph
35 *
36 * @author Geneviève Bastien
37 */
38 public class KernelExecutionGraphBenchmark {
39
40 /**
41 * Test test ID for kernel analysis benchmarks
42 */
43 public static final String TEST_ID = "org.eclipse.tracecompass#Kernel Execution Graph#";
44 private static final String TEST_BUILD = "Building Graph (%s)";
45 private static final String TEST_MEMORY = "Memory Usage (%s)";
46
47 private static final int LOOP_COUNT = 25;
48
49 private interface RunMethod {
50 void execute(PerformanceMeter pm, IAnalysisModule module);
51 }
52
53 private RunMethod cpu = (pm, module) -> {
54 pm.start();
55 TmfTestHelper.executeAnalysis(module);
56 pm.stop();
57 };
58
59 private RunMethod memory = (pm, module) -> {
60 System.gc();
61 pm.start();
62 TmfTestHelper.executeAnalysis(module);
63 System.gc();
64 pm.stop();
65 };
66
67 private static final EnumSet<CtfTestTrace> fTraceSet = EnumSet.of(
68 CtfTestTrace.TRACE2,
69 CtfTestTrace.MANY_THREADS,
70 CtfTestTrace.DJANGO_HTTPD);
71
72 /**
73 * Run all benchmarks
74 */
75 @Test
76 public void runAllBenchmarks() {
77 for (CtfTestTrace trace : fTraceSet) {
78
79 runOneBenchmark(trace,
80 String.format(TEST_BUILD, trace.toString()),
81 cpu,
82 Dimension.CPU_TIME);
83
84 runOneBenchmark(trace,
85 String.format(TEST_MEMORY, trace.toString()),
86 memory,
87 Dimension.USED_JAVA_HEAP);
88 }
89 }
90
91 private static void runOneBenchmark(@NonNull CtfTestTrace testTrace, String testName, RunMethod method, Dimension dimension) {
92 Performance perf = Performance.getDefault();
93 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName);
94 perf.tagAsSummary(pm, "Execution graph " + testName, dimension);
95
96 for (int i = 0; i < LOOP_COUNT; i++) {
97 LttngKernelTrace trace = null;
98 IAnalysisModule module = null;
99
100 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
101
102 try {
103 trace = new LttngKernelTrace();
104 module = new LttngKernelExecutionGraph();
105 module.setId("test");
106 trace.initTrace(null, path, CtfTmfEvent.class);
107 module.setTrace(trace);
108
109 method.execute(pm, module);
110
111 /*
112 * Delete the supplementary files, so that the next iteration
113 * rebuilds the state system.
114 */
115 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
116 for (File file : suppDir.listFiles()) {
117 file.delete();
118 }
119
120 } catch (TmfAnalysisException | TmfTraceException e) {
121 fail(e.getMessage());
122 } finally {
123 if (module != null) {
124 module.dispose();
125 }
126 if (trace != null) {
127 trace.dispose();
128 }
129 }
130 }
131 pm.commit();
132 CtfTmfTestTraceUtils.dispose(testTrace);
133 }
134
135 }
This page took 0.055052 seconds and 5 git commands to generate.