pcap: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.pcap.core.tests / perf / org / eclipse / tracecompass / pcap / core / tests / perf / trace / PcapReadBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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 * Contributors:
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.pcap.core.tests.perf.trace;
14
15 import static org.junit.Assert.fail;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.io.IOException;
19
20 import org.eclipse.test.performance.Dimension;
21 import org.eclipse.test.performance.Performance;
22 import org.eclipse.test.performance.PerformanceMeter;
23 import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
24 import org.eclipse.tracecompass.internal.pcap.core.packet.Packet;
25 import org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException;
26 import org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile;
27 import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
28 import org.junit.Test;
29
30 /**
31 * Benchmark of the Pcap parser for reading a trace. Note: We should get a
32 * bigger trace. One that has WAYYYY more events since this current trace is
33 * just parsed too fast.
34 *
35 * @author Vincent Perot
36 */
37 public class PcapReadBenchmark {
38
39 private static final String TEST_SUITE_NAME = "Pcap Read Benchmark";
40 private static final String TEST_ID = "org.eclipse.linuxtools#" + TEST_SUITE_NAME;
41 private static final int LOOP_COUNT = 25;
42 private static final int RUN_BETWEEN_COMMIT_COUNT = 15;
43
44 /**
45 * Benchmark reading the pcap trace
46 */
47 @Test
48 public void testPcapTrace() {
49 readTrace(PcapTestTrace.BENCHMARK_TRACE, "trace-pcap", true);
50 }
51
52 private static void readTrace(PcapTestTrace testTrace, String testName, boolean inGlobalSummary) {
53 assumeTrue(testTrace.exists());
54
55 Performance perf = Performance.getDefault();
56 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
57 perf.tagAsSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME);
58
59 if (inGlobalSummary) {
60 perf.tagAsGlobalSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME);
61 }
62
63 for (int loop = 0; loop < LOOP_COUNT; loop++) {
64 pm.start();
65 try (PcapFile trace = testTrace.getTrace();) {
66 for (int i = 0; i < RUN_BETWEEN_COMMIT_COUNT; i++) {
67 trace.seekPacket(0);
68 while (trace.hasNextPacket()) {
69 Packet packet = trace.parseNextPacket();
70 if (packet == null) {
71 fail("Test failed at iteration " + loop + '.' + i + ", at packet " + trace.getCurrentRank());
72 return;
73 }
74 /* Do something with the packet because we are awesome */
75 packet.getPayload();
76 }
77 }
78 } catch (IOException | BadPcapFileException | BadPacketException e) {
79 fail("Test failed at iteration " + loop + ':' + e.getMessage());
80 }
81 pm.stop();
82 }
83 pm.commit();
84 }
85 }
This page took 0.04396 seconds and 5 git commands to generate.