Package org.hyperic.sigar

Examples of org.hyperic.sigar.ProcMem


            if (allSwap.getTotal()>0) {
                assert allSwap.getTotal() > 1000000 : allSwap.getTotal();
                assert allSwap.getFree() > 0 : allSwap.getFree();
            }

            ProcMem processMemory = sigar.getProcMem(sigar.getPid());

            System.out.println("Process Memory:" + "\n  MinorFaults=" + nf.format(processMemory.getMinorFaults())
                + "\n  MajorFaults=" + nf.format(processMemory.getMajorFaults()) + "\n   PageFaults="
                + nf.format(processMemory.getPageFaults()) + "\n     Resident="
                + nf.format(processMemory.getResident()) + "\n        Share=" + nf.format(processMemory.getShare())
                + "\n         Size=" + nf.format(processMemory.getSize()));
            assert processMemory.getResident() > 0 : processMemory.getResident();
            assert processMemory.getSize() > 0 : processMemory.getSize();
        } finally {
            sigar.close();
        }
    }
View Full Code Here


        // just a side test - need to make sure this works
        assert SystemInfoFactory.getNativeSystemInfoVersion() != null;

        Mem allMemory = sysinfo.getMemoryInfo();
        ProcMem procMemory = sysinfo.getThisProcess().getMemory();

        assert allMemory != null;
        assert procMemory != null;
        assert allMemory.getUsed() > procMemory.getResident() : allMemory.getUsed() + "->" + procMemory.getSize();
    }
View Full Code Here

        if (systemInfo == null) {
            systemInfo = SystemInfoFactory.createSystemInfo();
            processInfo = systemInfo.getThisProcess();
        }

        ProcMem mem = processInfo.getMemory();
        return mem.getSize(); // I am assuming this size is BOTH resident and swap memory (i.e. total mem used)
    }
View Full Code Here

        } catch (SigarException e) {
            // ignore
        }

        try {
            ProcMem mem = sigar.getProcMem(sigar.getPid());
            stats.mem = new ProcessStats.Mem();
            stats.mem.totalVirtual = mem.getSize();
            stats.mem.resident = mem.getResident();
            stats.mem.share = mem.getShare();
        } catch (SigarException e) {
            // ignore
        }

        return stats;
View Full Code Here

  public void testInjectTestJPacketHandler() throws SigarException {

    start = ts = System.currentTimeMillis();
    Sigar sig = new Sigar();
    long pid = sig.getPid();
    ProcMem pm = new ProcMem();
    long base = 0;

    final JBuffer buf =
        new JBuffer(FormatUtils.toByteArray(""
            + "0007e914 78a20010 7b812445 080045c0"
            + "00280005 0000ff11 70e7c0a8 62dec0a8"
            + "65e906a5 06a50014 e04ac802 000c0002"
            + "00000002 00060000 00000000"
           
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//
//           
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
//            + "00000002 00060000 00000000 00000000"
           
        ));
    final PcapHeader header = new PcapHeader(buf.size(), buf.size());
    PcapPacket packet = new PcapPacket(header, buf);
   
    System.out.printf("injected packet size=%d bytes\n", buf.size());

    for (int i = 0; i < COUNT; i++) {
      PcapUtils.injectLoop(10000, JProtocol.ETHERNET_ID,
          new PcapPacketHandler<String>() {

            public void nextPacket(PcapPacket packet, String user) {
              assertNotNull(packet);

              count++;
              b += packet.size();
              h += packet.getState().getHeaderCount();

            }

          }, "", packet);

      /*
       * 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 / 10) == 0 && i != 0) {
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out.printf(
            "tot=%.1f packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
            ((double) total) / 1024 / 1024, count, ((double) count / delta),
            ((double) b / delta / 1024.), ((double) h / delta),
            1000000. / ((double) h / delta), pm.getResident() / (1024),
            ((double) pm.getResident() - base) / count, pm.getSize() / (1024));
        System.out.flush();

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

    });

    start = ts = System.currentTimeMillis();
    Sigar sig = new Sigar();
    long pid = sig.getPid();
    ProcMem pm = new ProcMem();
    long base = 0;

    for (int i = 0; i < COUNT; i++) {

      for (final String fname : files) {
        Pcap pcap = Pcap.openOffline(DIR.toString() + "/" + fname, errbuf);
        assertNotNull(errbuf.toString(), pcap);

        pcap.loop(Pcap.LOOP_INFINATE, new JPacketHandler<Pcap>() {

          public void nextPacket(JPacket packet, Pcap user) {
            assertNotNull(packet);

            count++;
            b += packet.size();
            // h += packet.getState().getHeaderCount();

          }

        }, pcap);

        pcap.close();
      }

      /*
       * 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 / 10) == 0 && i != 0) {
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out.printf(
            "tot=%.1f packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
            ((double) total) / 1024 / 1024, count, ((double) count / delta),
            ((double) b / delta / 1024.), ((double) h / delta),
            1000000. / ((double) h / delta), pm.getResident() / (1024),
            ((double) pm.getResident() - base) / count, pm.getSize() / (1024));
        System.out.flush();

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

    });

    start = ts = System.currentTimeMillis();
    Sigar sig = new Sigar();
    long pid = sig.getPid();
    ProcMem pm = new ProcMem();
    long base = 0;

    for (int i = 0; i < COUNT; i++) {
      for (final String fname : files) {
        Pcap pcap = Pcap.openOffline(DIR.toString() + "/" + fname, errbuf);
        assertNotNull(errbuf.toString(), pcap);

        pcap.loop(Pcap.LOOP_INFINATE, new JBufferHandler<Pcap>() {

          public void nextPacket(PcapHeader header, JBuffer buffer, Pcap user) {
            count++;
            b += buffer.size();
          }

        }, pcap);

        pcap.close();
      }

      /*
       * 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 / 10) == 0 && i != 0) {
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out.printf(
            "tot=%.1fMp packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
            ((double) total) / 1024 / 1024, count, ((double) count / delta),
            ((double) b / delta / 1024.), ((double) h / delta),
            1000000. / ((double) h / delta), pm.getResident() / (1024),
            ((double) pm.getResident() - base) / count, pm.getSize() / (1024));
        System.out.flush();

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

  public void testInjectTestJPacketHandler() throws SigarException {

    start = ts = System.currentTimeMillis();
    Sigar sig = new Sigar();
    long pid = sig.getPid();
    ProcMem pm = new ProcMem();
    long base = 0;

    final JBuffer buf =
        new JBuffer(FormatUtils.toByteArray(""
            + "0007e914 78a20010 7b812445 080045c0"
            + "00280005 0000ff11 70e7c0a8 62dec0a8"
            + "65e906a5 06a50014 e04ac802 000c0002"
            + "00000002 00060000 00000000"

        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        //
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        //
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        //
        //
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"
        // + "00000002 00060000 00000000 00000000"

            ));
    final PcapHeader header = new PcapHeader(buf.size(), buf.size());
    PcapPacket packet = new PcapPacket(header, buf);

    System.out.printf("injected packet size=%d bytes\n", buf.size());

    for (int i = 0; i < COUNT; i++) {
      PcapUtils.injectLoop(1000,
          JProtocol.ETHERNET_ID,
          new PcapPacketHandler<String>() {

            public void nextPacket(PcapPacket packet, String user) {
              assertNotNull(packet);

              count++;
              b += packet.size();
              h += packet.getState().getHeaderCount();

            }

          },
          "",
          packet);

      /*
       * 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 / LINES) == 0 && i != 0) {
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out
            .printf("tot=%.1f packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
                ((double) total) / 1024 / 1024,
                count,
                (count / delta),
                (b / delta / 1024.),
                (h / delta),
                1000000. / (h / delta),
                pm.getResident() / (1024),
                ((double) pm.getResident() - base) / count,
                pm.getSize() / (1024));
        System.out.flush();

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

    });

    start = ts = System.currentTimeMillis();
    Sigar sig = new Sigar();
    long pid = sig.getPid();
    ProcMem pm = new ProcMem();
    long base = 0;

    for (int i = 0; i < COUNT; i++) {

      for (final String fname : files) {
        Pcap pcap = Pcap.openOffline(DIR.toString() + "/" + fname, errbuf);
        assertNotNull(errbuf.toString(), pcap);

        pcap.loop(Pcap.LOOP_INFINATE, new JPacketHandler<Pcap>() {

          public void nextPacket(JPacket packet, Pcap user) {
            assertNotNull(packet);

            count++;
            b += packet.size();
            h += packet.getState().getHeaderCount();

          }

        }, pcap);

        pcap.close();
      }

      /*
       * 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 / LINES) == 0 && i != 0) {
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out
            .printf("tot=%.1fMpkts packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
                ((double) total) / (1000000),
                count,
                (count / delta),
                (b / delta / 1024.),
                (h / delta),
                1000000. / (h / delta),
                pm.getResident() / (1024),
                ((double) pm.getResident() - base) / count,
                pm.getSize() / (1024));
        System.out.flush();

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

    });

    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;
    for (int i = 0; i < COUNT; i++) {
      for (final String fname : files) {
        Pcap pcap = Pcap.openOffline(DIR.toString() + "/" + fname, errbuf);
        assertNotNull(errbuf.toString(), pcap);

        pcap.loop(Pcap.LOOP_INFINATE, new JBufferHandler<Pcap>() {

          public void nextPacket(PcapHeader header, JBuffer buffer, Pcap user) {
            count++;
            b += buffer.size();

            packet.peerAndScan(Ethernet.ID, header, buffer);
            h += packet.getState().getHeaderCount();
          }

        }, pcap);

        pcap.close();
      }

      /*
       * 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 / LINES) == 0 && i != 0) {
        loop++;
        te = System.currentTimeMillis();
        total += count;
        bytes += b;
        headers += h;
        double delta = ((double) te - (double) ts) / 1000.;

        pm.gather(sig, pid);

        System.out.printf("#%-2d %s: ",
            loop,
            new Time(System.currentTimeMillis()));
        System.out
            .printf("tot=%.1fMp packets=%d pps=%.0f bytes=%.0fMb/s hdr=%.0f/s "
                + "hdr=%.0fus rm=%.1fMb pm=%.1fb vm=%dKb\n",
                ((double) total) / 1000 / 1000, // Tot
                count, // packets
                (count / delta), // pps
                (b / delta / (1024. * 1024)), // bytes
                (h / delta), // hdr/s
                1000000. / (h / delta), // hdr us
                (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

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.