Package org.hyperic.sigar

Examples of org.hyperic.sigar.ProcMem


        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);
    int loop = 0;
    final Tcp tcp = new Tcp();

    final JBufferHandler<Object> handler = new JBufferHandler<Object>() {

      public void nextPacket(PcapHeader header, JBuffer buffer, Object user) {

        packet.peerAndScan(Ethernet.ID, header, buffer);

        h += packet.getState().getHeaderCount();

        // if (packet.hasHeader(tcp)) {
        // System.out.printf("#%d: ", packet.getFrameNumber());
        // System.out.println(packet.toString());
        // }
      }

    };

    for (int i = 0; i < COUNT; i++) {
      b += size;
      count += 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.getSize();
      }

      // 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();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;
        double hps = (h / delta);
        double sph = 1000000000. / (h / delta);

        pm.gather(sig, pid);

        System.out.printf("#%-2d %s: ",
            loop,
            new Time(System.currentTimeMillis()));
        System.out.printf("tot=%.1fMp " + "packets=%d " + "pps=%.0f(%.1fus) "
            + "hps=%.0f(%.0fns) " + "bytes=%.0fMb/s " + "rm=%.1fMb "
            + "pm=%.1fb " + "vm=%dKb" + "%n",

        ((double) total) / 1000 / 1000, // Tot
            count, // packets
            (count / delta), // pps
            delta * 1000000. / count,
            hps, // hdr/s
            ((Double.isInfinite(sph)) ? 0.0 : sph), // hdr ns
            (b / delta / (1024. * 1024)), // bytes
            (double) pm.getResident() / (1024 * 1024), // rm
            ((double) pm.getResident() - base) / count, // pm
            pm.getSize() / (1024)); // vm
        System.out.flush();

        ts = te;
        count = 0;
        b = 0;
View Full Code Here


        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 "
View Full Code Here

        MultiProcCpu cpu = this.proxy.getMultiProcCpu(query);
        println("Number of processes: " + cpu.getProcesses());
        println("Cpu usage: " + CpuPerc.format(cpu.getPercent()));
        println("Cpu time: "  + Ps.getCpuTime(cpu.getTotal()));

        ProcMem mem = this.proxy.getMultiProcMem(query);
        println("Size: " + Sigar.formatSize(mem.getSize()));
        println("Resident: " + Sigar.formatSize(mem.getResident()));
        println("Share: " + Sigar.formatSize(mem.getShare()));
    }
View Full Code Here

        long pid = Long.parseLong(args[0]);

        long lastTime = System.currentTimeMillis();

        ProcMem last = sigar.getProcMem(pid);

        while (true) {
            ProcMem cur = sigar.getProcMem(pid);
           
            StringBuffer diff = diff(last, cur);

            if (diff.length() == 0) {
                System.out.println("no change " +
                                   "(size=" +
                                   Sigar.formatSize(cur.getSize()) +
                                   ")");
            }
            else {
                long curTime = System.currentTimeMillis();
                long timeDiff = curTime - lastTime;
View Full Code Here

        } catch (SigarException e) {
            info.add(unknown);
        }

        try {
            ProcMem mem = sigar.getProcMem(pid);
            info.add(Sigar.formatSize(mem.getSize()));
            info.add(Sigar.formatSize(mem.getRss()));
            info.add(Sigar.formatSize(mem.getShare()));
        } catch (SigarException e) {
            info.add(unknown);
        }

        info.add(String.valueOf(state.getState()));
View Full Code Here

        } catch (SigarException e) {
        }

        // get process memory related information
        try {
            ProcMem mem = sigar.getProcMem(pid);
            pObj.setMemorySize(mem.getSize());
            pObj.setRssSize(mem.getRss());
            pObj.setSharedMemory(mem.getShare());
            pObj.setResident(mem.getResident());
        } catch (SigarException e) {
        }

        pObj.setProcessState(String.valueOf(state.getState()));
View Full Code Here

    public TestProcMem(String name) {
        super(name);
    }

    private void traceMem(Sigar sigar, long pid) throws Exception {
        ProcMem procMem;

        try {
            procMem = sigar.getProcMem(pid);
        } catch (SigarException e) {
            traceln("pid " + pid + ": " + e.getMessage());
            return;
        }

        traceln("Pid=" + pid);
        traceln("Size=" + Sigar.formatSize(procMem.getSize()));
        traceln("Resident=" + Sigar.formatSize(procMem.getResident()));
        traceln("Share=" + Sigar.formatSize(procMem.getShare()));
        traceln("MinorFaults=" + procMem.getMinorFaults());
        traceln("MajorFaults=" + procMem.getMajorFaults());
        traceln("PageFaults=" + procMem.getPageFaults());
        //assertTrue(procMem.getSize() > 0);
        // XXX vsize, resident, share, rss
    }
View Full Code Here

    public TestProcMem(String name) {
        super(name);
    }

    private void traceMem(Sigar sigar, long pid) throws Exception {
        ProcMem procMem;

        try {
            procMem = sigar.getProcMem(pid);
        } catch (SigarException e) {
            traceln("pid " + pid + ": " + e.getMessage());
            return;
        }

        traceln("Pid=" + pid);
        traceln("Size=" + Sigar.formatSize(procMem.getSize()));
        traceln("Resident=" + Sigar.formatSize(procMem.getResident()));
        traceln("Share=" + Sigar.formatSize(procMem.getShare()));
        traceln("MinorFaults=" + procMem.getMinorFaults());
        traceln("MajorFaults=" + procMem.getMajorFaults());
        traceln("PageFaults=" + procMem.getPageFaults());
        //assertTrue(procMem.getSize() > 0);
        // XXX vsize, resident, share, rss
    }
View Full Code Here

        } catch (SigarException e) {
            info.add(unknown);
        }

        try {
            ProcMem mem = sigar.getProcMem(pid);
            info.add(Sigar.formatSize(mem.getSize()));
            info.add(Sigar.formatSize(mem.getRss()));
            info.add(Sigar.formatSize(mem.getShare()));
        } catch (SigarException e) {
            info.add(unknown);
        }

        info.add(String.valueOf(state.getState()));
View Full Code Here

        long pid = Long.parseLong(args[0]);

        long lastTime = System.currentTimeMillis();

        ProcMem last = sigar.getProcMem(pid);

        while (true) {
            ProcMem cur = sigar.getProcMem(pid);
           
            StringBuffer diff = diff(last, cur);

            if (diff.length() == 0) {
                System.out.println("no change " +
                                   "(size=" +
                                   Sigar.formatSize(cur.getSize()) +
                                   ")");
            }
            else {
                long curTime = System.currentTimeMillis();
                long timeDiff = curTime - lastTime;
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.ProcMem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.