lttng: Add System Call Analysis benchmarks
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / syscall / SystemCallAnalysisBenchmark.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.syscall;
11
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
14
15 import java.io.File;
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.analysis.os.linux.core.tid.TidAnalysisModule;
22 import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.SystemCallLatencyAnalysis;
23 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
24 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
25 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
26 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
28 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
29 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
30 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
31 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
32 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
33 import org.junit.Test;
34
35 /**
36 * Benchmarks the system call latency analysis
37 *
38 * @author Geneviève Bastien
39 */
40 public class SystemCallAnalysisBenchmark {
41
42 /**
43 * Test test ID for the system call analysis benchmarks
44 */
45 public static final String TEST_ID = "org.eclipse.tracecompass#System Call Analysis#";
46 private static final String TEST_BUILD = "Building Analysis (%s)";
47 private static final String TEST_MEMORY = "Memory Usage (%s)";
48
49 private static final int LOOP_COUNT = 25;
50
51 private interface RunMethod {
52 void execute(PerformanceMeter pm, IAnalysisModule module);
53 }
54
55 private RunMethod cpu = (pm, module) -> {
56 pm.start();
57 TmfTestHelper.executeAnalysis(module);
58 pm.stop();
59 };
60
61 private RunMethod memory = (pm, module) -> {
62 System.gc();
63 pm.start();
64 TmfTestHelper.executeAnalysis(module);
65 System.gc();
66 pm.stop();
67 };
68
69 /**
70 * Run the benchmark with "trace2"
71 */
72 @Test
73 public void testTrace2() {
74 runTest(CtfTestTrace.TRACE2, String.format(TEST_BUILD, "Trace2"), cpu, Dimension.CPU_TIME);
75 runTest(CtfTestTrace.TRACE2, String.format(TEST_MEMORY, "Trace2"), memory, Dimension.USED_JAVA_HEAP);
76 }
77
78 /**
79 * Run the benchmark with "many thread"
80 */
81 @Test
82 public void testManyThreads() {
83 runTest(CtfTestTrace.MANY_THREADS, String.format(TEST_BUILD, "Many threads"), cpu, Dimension.CPU_TIME);
84 runTest(CtfTestTrace.MANY_THREADS, String.format(TEST_MEMORY, "Many threads"), memory, Dimension.USED_JAVA_HEAP);
85 }
86
87 /**
88 * Run the benchmark with "django httpd"
89 */
90 @Test
91 public void testDjangoHttpd() {
92 runTest(CtfTestTrace.DJANGO_HTTPD, String.format(TEST_BUILD, "Django HTTPD"), cpu, Dimension.CPU_TIME);
93 runTest(CtfTestTrace.DJANGO_HTTPD, String.format(TEST_MEMORY, "Django HTTPD"), memory, Dimension.USED_JAVA_HEAP);
94 }
95
96 private static void runTest(@NonNull CtfTestTrace testTrace, String testName, RunMethod method, Dimension dimension) {
97 Performance perf = Performance.getDefault();
98 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName);
99 perf.tagAsSummary(pm, "Syscall " + testName, dimension);
100
101 for (int i = 0; i < LOOP_COUNT; i++) {
102 LttngKernelTrace trace = null;
103 IAnalysisModule module = null;
104
105 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
106
107 try {
108 // Make sure the TID analysis has run on this trace
109 trace = new LttngKernelTrace();
110 trace.initTrace(null, path, CtfTmfEvent.class);
111 trace.traceOpened(new TmfTraceOpenedSignal(trace, trace, null));
112 module = trace.getAnalysisModule(TidAnalysisModule.ID);
113 assertNotNull(module);
114 module.schedule();
115 module.waitForCompletion();
116
117 module = new SystemCallLatencyAnalysis();
118 module.setId("test");
119 module.setTrace(trace);
120
121 method.execute(pm, module);
122
123 /*
124 * Delete the supplementary files, so that the next iteration
125 * rebuilds the state system.
126 */
127 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
128 for (File file : suppDir.listFiles()) {
129 file.delete();
130 }
131
132 } catch (TmfAnalysisException | TmfTraceException e) {
133 fail(e.getMessage());
134 } finally {
135 if (module != null) {
136 module.dispose();
137 }
138 if (trace != null) {
139 trace.dispose();
140 }
141 }
142 }
143 pm.commit();
144 CtfTmfTestTraceUtils.dispose(testTrace);
145 }
146
147 }
This page took 0.037135 seconds and 5 git commands to generate.