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
.linuxtools
.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
.linuxtools
.pcap
.core
.packet
.BadPacketException
;
21 import org
.eclipse
.linuxtools
.pcap
.core
.packet
.Packet
;
22 import org
.eclipse
.linuxtools
.pcap
.core
.tests
.shared
.PcapTestTrace
;
23 import org
.eclipse
.linuxtools
.pcap
.core
.trace
.BadPcapFileException
;
24 import org
.eclipse
.linuxtools
.pcap
.core
.trace
.PcapFile
;
25 import org
.eclipse
.test
.performance
.Dimension
;
26 import org
.eclipse
.test
.performance
.Performance
;
27 import org
.eclipse
.test
.performance
.PerformanceMeter
;
28 import org
.junit
.Test
;
32 * Benchmark of the Pcap parser for reading a trace. Note: We should get a bigger trace. One
33 * that has WAYYYY more events since this current trace is 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;
44 * Benchmark reading the pcap trace
47 public void testPcapTrace() {
48 readTrace(PcapTestTrace
.MOSTLY_UDP
, "trace-pcap", true);
51 private static void readTrace(PcapTestTrace testTrace
, String testName
, boolean inGlobalSummary
) {
52 assumeTrue(testTrace
.exists());
54 Performance perf
= Performance
.getDefault();
55 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
56 perf
.tagAsSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
58 if (inGlobalSummary
) {
59 perf
.tagAsGlobalSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
62 for (int loop
= 0; loop
< LOOP_COUNT
; loop
++) {
64 try (PcapFile trace
= testTrace
.getTrace();) {
66 while (trace
.hasNextPacket()) {
67 Packet packet
= trace
.parseNextPacket();
69 fail("Test failed at iteration " + loop
+ " packet " + trace
.getCurrentRank());
72 /* Do something with the packet because we are awesome */
76 } catch (IOException
| BadPcapFileException
| BadPacketException e
) {
77 fail("Test failed at iteration " + loop
+ ':' + e
.getMessage());
This page took 0.034053 seconds and 5 git commands to generate.