size);
start = ts = System.currentTimeMillis();
Sigar sig = new Sigar();
long pid = sig.getPid();
ProcMem pm = new ProcMem();
long base = 0;
final PcapPacket packet = new PcapPacket(JMemory.POINTER);
final PcapPacket.State state = packet.getState();
final Tcp tcp = new Tcp();
// final TcpScanner tcpScanner = new TcpScanner();
final ByteBuffer byteBuffer = ByteBuffer.allocate(8 * 1024);
final ReferenceQueue<PcapPacket> refQueue =
new ReferenceQueue<PcapPacket>();
final TextFormatter out = new TextFormatter(DEV_NULL);
// Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
// Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
int loop = 0;
// DisposableGC.getDeault().stopCleanupThread();
DisposableGC.getDefault().startCleanupThread();
// JPacket.setFormatter(new TextFormatter(DEV_NULL));
final BlockingQueue<PcapPacket> queue =
new LinkedBlockingQueue<PcapPacket>(10);
final JBufferHandler<Object> handler = new JBufferHandler<Object>() {
public void nextPacket(PcapHeader header, JBuffer buffer, Object user) {
// final int size = buffer.size();
// long index = total + count;
// System.out.printf("#%d", index);
b += buffer.size();
PcapPacket pkt = new PcapPacket(header, buffer);
// pkt.scan(Ethernet.ID);
// h += pkt.getState().getHeaderCount();
// if (queue.remainingCapacity() == 0) {
// queue.clear();
// }
//
// try {
// queue.put(pkt);
// } catch (InterruptedException e) {
// }
// packet.peer(header, buffer);
// b += packet.transferHeaderAndDataFrom(header, buffer);
// new Object(){};
// tcpScanner.scan(buffer);
// h += tcpScanner.getHCount();
// if (tcpScanner.hasTcp()) {
// final int offset = tcpScanner.tcpPayloadOffset();
// final int length = tcpScanner.tcpPayloadLength();
//
// b += buffer.transferTo(byteBuffer, offset, length);
// byteBuffer.clear();
//
// }
// b += buffer.transferTo(byteBuffer, 0, size);
// byteBuffer.clear();
// packet.scan(Ethernet.ID);
// packet.peerAndScan(Ethernet.ID, header, buffer);
// try {out.format(packet);} catch (IOException e) {
// e.printStackTrace();}
// packet.peer(header, buffer);
// state.getFrameNumber();
// buffer.peer(packet);
// b += size + header.size();
count++;
// h += packet.getState().getHeaderCount();
// try {
// if (count % 20 == 0) {
// Thread.sleep(1);
// }
// } catch (InterruptedException e) {
// }
}
};
for (int i = 0; i < COUNT; i++) {
buffer.dispatchToJBuffeHandler(handler, null);
/*
* Skip 1 iteration to allow all the files to be opened and any allocated
* resources to end up as a memory base.
*/
if (i == 0) {
base = pm.getResident();
}
// if (i % (COUNT / 10000) == 0 && i != 0) {
// System.out.printf("=");
// System.out.flush();
// }
if (i % (COUNT / LINES) == 0 && i != 0) {
// System.out.println();
loop++;
te = System.currentTimeMillis();
pm.gather(sig, pid);
total += count;
bytes += b;
headers += h;
double delta = ((double) te - (double) ts) / 1000.;
double hps = (h / delta);
double bps = ((double) b * 8 / delta);
double sph = 1000000000. / (h / delta);
sph = ((Double.isInfinite(sph)) ? 0.0 : sph);
double rm = (pm.getResident() - base);
double vm = (pm.getSize());
System.out.printf("#%-2d %s: ",
loop,
new Time(System.currentTimeMillis()));
System.out.printf("tot=%3.2fMp "