Commit | Line | Data |
---|---|---|
a1d21447 VP |
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 | ||
71f2817f | 13 | package org.eclipse.tracecompass.pcap.core.tests.perf.trace; |
a1d21447 VP |
14 | |
15 | import static org.junit.Assert.fail; | |
16 | import static org.junit.Assume.assumeTrue; | |
17 | ||
18 | import java.io.IOException; | |
19 | ||
a1d21447 VP |
20 | import org.eclipse.test.performance.Dimension; |
21 | import org.eclipse.test.performance.Performance; | |
22 | import org.eclipse.test.performance.PerformanceMeter; | |
71f2817f AM |
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; | |
a1d21447 VP |
28 | import org.junit.Test; |
29 | ||
a1d21447 | 30 | /** |
82983c92 VP |
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. | |
a1d21447 VP |
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; | |
82983c92 | 42 | private static final int RUN_BETWEEN_COMMIT_COUNT = 15; |
a1d21447 VP |
43 | |
44 | /** | |
45 | * Benchmark reading the pcap trace | |
46 | */ | |
47 | @Test | |
48 | public void testPcapTrace() { | |
82983c92 | 49 | readTrace(PcapTestTrace.BENCHMARK_TRACE, "trace-pcap", true); |
a1d21447 VP |
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();) { | |
82983c92 VP |
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(); | |
a1d21447 | 76 | } |
a1d21447 | 77 | } |
a1d21447 VP |
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 | } |