1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.pcap
.core
.tests
.perf
.trace
;
15 import static org
.junit
.Assert
.fail
;
16 import static org
.junit
.Assume
.assumeTrue
;
18 import java
.io
.IOException
;
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
;
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.
35 * @author Vincent Perot
37 public class PcapReadBenchmark
{
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;
45 * Benchmark reading the pcap trace
48 public void testPcapTrace() {
49 readTrace(PcapTestTrace
.BENCHMARK_TRACE
, "trace-pcap", true);
52 private static void readTrace(PcapTestTrace testTrace
, String testName
, boolean inGlobalSummary
) {
53 assumeTrue(testTrace
.exists());
55 Performance perf
= Performance
.getDefault();
56 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
57 perf
.tagAsSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
59 if (inGlobalSummary
) {
60 perf
.tagAsGlobalSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
63 for (int loop
= 0; loop
< LOOP_COUNT
; loop
++) {
65 try (PcapFile trace
= testTrace
.getTrace();) {
66 for (int i
= 0; i
< RUN_BETWEEN_COMMIT_COUNT
; i
++) {
68 while (trace
.hasNextPacket()) {
69 Packet packet
= trace
.parseNextPacket();
71 fail("Test failed at iteration " + loop
+ '.' + i
+ ", at packet " + trace
.getCurrentRank());
74 /* Do something with the packet because we are awesome */
78 } catch (IOException
| BadPcapFileException
| BadPacketException e
) {
79 fail("Test failed at iteration " + loop
+ ':' + e
.getMessage());
This page took 0.034212 seconds and 6 git commands to generate.