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
;
19 import java
.util
.LinkedList
;
20 import java
.util
.List
;
21 import java
.util
.Random
;
23 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.packet
.BadPacketException
;
24 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.trace
.BadPcapFileException
;
25 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.trace
.PcapFile
;
26 import org
.eclipse
.linuxtools
.pcap
.core
.tests
.shared
.PcapTestTrace
;
27 import org
.eclipse
.test
.performance
.Dimension
;
28 import org
.eclipse
.test
.performance
.Performance
;
29 import org
.eclipse
.test
.performance
.PerformanceMeter
;
30 import org
.junit
.Test
;
33 * Tests for performance regressions of the pcap reader. It only tests the pcap
34 * reader, not tmf. <br>
35 * This test runs in 3 passes.
37 * <li>first it opens a trace</li>
38 * <li>then it reads the trace completely</li>
39 * <li>then it randomly (seeded) seeks NB_SEEKS locations in the trace and reads
40 * one event at each position.</li>
42 * <li>Note: We should make more seeks, since the current number is just too
45 * @author Vincent Perot
47 public class PcapSeekBenchmark
{
49 private static final Random RND
= new Random(1000);
51 private static final int LOOP_COUNT
= 25;
52 private static final int NB_SEEKS
= 1000000;
53 private static final String TEST_SUITE_NAME
= "Pcap Read & Seek Benchmark (" + NB_SEEKS
+ " seeks)";
54 private static final String TEST_ID
= "org.eclipse.linuxtools#" + TEST_SUITE_NAME
;
57 * Run the benchmark scenario for the pcap trace.
60 public void testPcapTrace() {
61 readAndSeekTrace(PcapTestTrace
.BENCHMARK_TRACE
, "trace-pcap", true);
64 private static void readAndSeekTrace(PcapTestTrace testTrace
, String testName
, boolean inGlobalSummary
) {
65 assumeTrue(testTrace
.exists());
67 Performance perf
= Performance
.getDefault();
68 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
69 perf
.tagAsSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
71 if (inGlobalSummary
) {
72 perf
.tagAsGlobalSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
75 for (int loop
= 0; loop
< LOOP_COUNT
; loop
++) {
76 try (PcapFile trace
= testTrace
.getTrace()) {
79 /* Read the whole trace to find out the number of packets */
80 long nbPackets
= trace
.getTotalNbPackets();
82 /* Generate the timestamps we will seek to */
83 List
<Long
> seekTimestamps
= new LinkedList
<>();
84 final long range
= nbPackets
;
85 for (int i
= 0; i
< NB_SEEKS
; i
++) {
86 long rank
= (RND
.nextLong() % range
);
88 // This is needed since modulus can return a negative
92 seekTimestamps
.add(rank
);
95 /* Benchmark seeking to the generated timestamps */
97 for (Long rank
: seekTimestamps
) {
98 trace
.seekPacket(rank
);
99 trace
.parseNextPacket();
103 } catch (IOException
| BadPcapFileException
| BadPacketException e
) {
104 /* Should not happen if assumeTrue() passed above */
105 fail("Test failed at iteration " + loop
+ ':' + e
.getMessage());
This page took 0.032426 seconds and 5 git commands to generate.