예제 #1
0
 public static String memoryToString() {
   DecimalFormat fmt = new DecimalFormat("0.0");
   return "Memory: "
       + fmt.format(RUNTIME.maxMemory() / 1048576D)
       + "MByte maximum, "
       + fmt.format(RUNTIME.totalMemory() / 1048576D)
       + "MByte total, "
       + fmt.format(RUNTIME.totalMemory() / 1048576D)
       + "MByte free";
 }
예제 #2
0
 public static String getMemoryInformation() {
   Runtime rt = Runtime.getRuntime();
   DecimalFormat df = new DecimalFormat("###,###,###,###");
   return "used = "
       + df.format(rt.totalMemory() - rt.freeMemory())
       + " free = "
       + rt.freeMemory()
       + " total = "
       + rt.totalMemory()
       + " max = "
       + rt.maxMemory();
 }
예제 #3
0
파일: _.java 프로젝트: GoWarp/pysonar2
    public static String getGCStats() {
        long totalGC = 0;
        long gcTime = 0;

        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            long count = gc.getCollectionCount();

            if (count >= 0) {
                totalGC += count;
            }

            long time = gc.getCollectionTime();

            if (time >= 0) {
                gcTime += time;
            }
        }

        StringBuilder sb = new StringBuilder();

        sb.append(banner("memory stats"));
        sb.append("\n- total collections: " + totalGC);
        sb.append("\n- total collection time: " + formatTime(gcTime));

        Runtime runtime = Runtime.getRuntime();
        sb.append("\n- total memory: " + _.printMem(runtime.totalMemory()));

        return sb.toString();
    }
  private void createRuntimeProps(MemberStateImpl memberState) {
    Runtime runtime = Runtime.getRuntime();
    ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean();
    MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemory = memoryMxBean.getHeapMemoryUsage();
    MemoryUsage nonHeapMemory = memoryMxBean.getNonHeapMemoryUsage();

    Map<String, Long> map = new HashMap<String, Long>();
    map.put(
        "runtime.availableProcessors", Integer.valueOf(runtime.availableProcessors()).longValue());
    map.put("date.startTime", runtimeMxBean.getStartTime());
    map.put("seconds.upTime", runtimeMxBean.getUptime());

    map.put("memory.maxMemory", runtime.maxMemory());
    map.put("memory.freeMemory", runtime.freeMemory());
    map.put("memory.totalMemory", runtime.totalMemory());
    map.put("memory.heapMemoryMax", heapMemory.getMax());
    map.put("memory.heapMemoryUsed", heapMemory.getUsed());
    map.put("memory.nonHeapMemoryMax", nonHeapMemory.getMax());
    map.put("memory.nonHeapMemoryUsed", nonHeapMemory.getUsed());
    map.put("runtime.totalLoadedClassCount", clMxBean.getTotalLoadedClassCount());
    map.put(
        "runtime.loadedClassCount", Integer.valueOf(clMxBean.getLoadedClassCount()).longValue());
    map.put("runtime.unloadedClassCount", clMxBean.getUnloadedClassCount());
    map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount());
    map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue());
    map.put(
        "runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue());
    map.put(
        "runtime.daemonThreadCount",
        Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue());
    memberState.setRuntimeProps(map);
  }
예제 #5
0
 public static void fullGC(boolean verbose) {
   if (verbose)
     System.out.print(
         new Date().toString()
             + ' '
             + String.valueOf((RUNTIME.totalMemory() - RUNTIME.freeMemory()) / 1024L)
             + "Kb used");
   long isFree = RUNTIME.freeMemory();
   long wasFree;
   do {
     wasFree = isFree;
     RUNTIME.runFinalization();
     RUNTIME.gc();
     isFree = RUNTIME.freeMemory();
   } while (isFree > wasFree);
   if (verbose)
     System.out.println(
         " --> "
             + String.valueOf((RUNTIME.totalMemory() - RUNTIME.freeMemory()) / 1024L)
             + "Kb used");
 }
예제 #6
0
 public double memoryUse(Environmental E, int number) {
   double s = -1.0;
   try {
     int n = number;
     Object[] objs = new Object[n];
     Environmental cl = E;
     Runtime rt = Runtime.getRuntime();
     long m0 = rt.totalMemory() - rt.freeMemory();
     System.gc();
     Thread.sleep(500);
     for (int i = 0; i < n; ++i) objs[i] = E = (Environmental) cl.copyOf();
     System.gc();
     Thread.sleep(1000);
     long m1 = rt.totalMemory() - rt.freeMemory();
     long dm = m1 - m0;
     s = (double) dm / (double) n;
     if (s < 0.0) return memoryUse(E, number);
   } catch (Exception e) {
     return -1;
   }
   return s;
 }
예제 #7
0
  private void doClean(timerEvent ev) {
    // Cleaner event
    if (VERBOSE) System.err.println("-- Cleaning up packetTable");

    // Might cause some recent packets to be dropped
    packetTable.clear();

    if (VERBOSE) {
      Runtime r = Runtime.getRuntime();
      System.err.println(
          "TOTAL: " + r.totalMemory() / 1024 + "KB FREE: " + r.freeMemory() / 1024 + "KB");
    }

    // Reregister timer event
    timer.registerEvent(CLEAN_TIMER_FREQUENCY, ev, mySink);
  }
예제 #8
0
  void rootdraw(GLState.Applier state, UI ui, BGL gl) {
    GLState.Buffer ibuf = new GLState.Buffer(state.cfg);
    gstate.prep(ibuf);
    ostate.prep(ibuf);
    GOut g = new GOut(gl, state.cgl, state.cfg, state, ibuf, new Coord(w, h));
    state.set(ibuf);

    g.state(ostate);
    g.apply();
    gl.glClearColor(0, 0, 0, 1);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    synchronized (ui) {
      ui.draw(g);
    }

    if (Config.dbtext) {
      int y = h - 150;
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "FPS: %d (%d%%, %d%% idle)",
          fps,
          (int) (uidle * 100.0),
          (int) (ridle * 100.0));
      Runtime rt = Runtime.getRuntime();
      long free = rt.freeMemory(), total = rt.totalMemory();
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "Mem: %,011d/%,011d/%,011d/%,011d",
          free,
          total - free,
          total,
          rt.maxMemory());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "Tex-current: %d", TexGL.num());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "GL progs: %d", g.st.numprogs());
      GameUI gi = ui.root.findchild(GameUI.class);
      if ((gi != null) && (gi.map != null)) {
        try {
          FastText.aprintf(
              g, new Coord(10, y -= 15), 0, 1, "MV pos: %s (%s)", gi.map.getcc(), gi.map.camera);
        } catch (Loading e) {
        }
        if (gi.map.rls != null)
          FastText.aprintf(
              g,
              new Coord(10, y -= 15),
              0,
              1,
              "Rendered: %,d+%,d(%,d)",
              gi.map.rls.drawn,
              gi.map.rls.instanced,
              gi.map.rls.instancified);
      }
      if (Resource.remote().qdepth() > 0)
        FastText.aprintf(
            g,
            new Coord(10, y -= 15),
            0,
            1,
            "RQ depth: %d (%d)",
            Resource.remote().qdepth(),
            Resource.remote().numloaded());
    }
    Object tooltip;
    try {
      synchronized (ui) {
        tooltip = ui.root.tooltip(mousepos, ui.root);
      }
    } catch (Loading e) {
      tooltip = "...";
    }
    Tex tt = null;
    if (tooltip != null) {
      if (tooltip instanceof Text) {
        tt = ((Text) tooltip).tex();
      } else if (tooltip instanceof Tex) {
        tt = (Tex) tooltip;
      } else if (tooltip instanceof Indir<?>) {
        Indir<?> t = (Indir<?>) tooltip;
        Object o = t.get();
        if (o instanceof Tex) tt = (Tex) o;
      } else if (tooltip instanceof String) {
        if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex();
      }
    }
    if (tt != null) {
      Coord sz = tt.sz();
      Coord pos = mousepos.add(sz.inv());
      if (pos.x < 0) pos.x = 0;
      if (pos.y < 0) pos.y = 0;
      g.chcolor(244, 247, 21, 192);
      g.rect(pos.add(-3, -3), sz.add(6, 6));
      g.chcolor(35, 35, 35, 192);
      g.frect(pos.add(-2, -2), sz.add(4, 4));
      g.chcolor();
      g.image(tt, pos);
    }
    ui.lasttip = tooltip;
    Resource curs = ui.root.getcurs(mousepos);
    if (curs != null) {
      if (cursmode == "awt") {
        if (curs != lastcursor) {
          try {
            setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc));
            lastcursor = curs;
          } catch (Exception e) {
            cursmode = "tex";
          }
        }
      } else if (cursmode == "tex") {
        Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv());
        g.image(curs.layer(Resource.imgc), dc);
      }
    }
    state.clean();
    GLObject.disposeall(state.cgl, gl);
  }
  public static void main(String[] args) throws Exception {
    // See : http://patorjk.com/software/taag/#p=display&f=Slant&t=Flamingo%20Collector
    System.out.println(
        "   _  __              ____                  _      _             _                _____                          \n"
            + "  | |/ /__  ____     / __ \\_________ _   __(_)____(_)___  ____  (_)___  ____ _   / ___/___  ______   _____  _____\n"
            + "  |   / _ \\/ __ \\   / /_/ / ___/ __ \\ | / / / ___/ / __ \\/ __ \\/ / __ \\/ __ `/   \\__ \\/ _ \\/ ___/ | / / _ \\/ ___/\n"
            + " /   /  __/ / / /  / ____/ /  / /_/ / |/ / (__  ) / /_/ / / / / / / / / /_/ /   ___/ /  __/ /   | |/ /  __/ /    \n"
            + "/_/|_\\___/_/ /_/  /_/   /_/   \\____/|___/_/____/_/\\____/_/ /_/_/_/ /_/\\__, /   /____/\\___/_/    |___/\\___/_/     \n"
            + "                                                                     /____/                                      \n");

    ////////////////////////////////////////////////////////////////////////////////////

    StringBuilder builder = new StringBuilder();
    printHeader(builder, "Application Information");

    Properties appProps = new Properties();
    Properties systemProperties = System.getProperties();
    appProps.put(
        "Java Version",
        systemProperties.getProperty("java.version", UNKNOWN)
            + " - "
            + systemProperties.getProperty("java.vendor", UNKNOWN));
    appProps.put("Current Working Directory", systemProperties.getProperty("user.dir", UNKNOWN));

    print(builder, appProps);

    Properties memPros = new Properties();
    final Runtime rt = Runtime.getRuntime();
    final long maxMemory = rt.maxMemory() / MEGA_BYTES;
    final long totalMemory = rt.totalMemory() / MEGA_BYTES;
    final long freeMemory = rt.freeMemory() / MEGA_BYTES;
    final long usedMemory = totalMemory - freeMemory;

    memPros.put("Maximum Allowable Memory", maxMemory + "MB");
    memPros.put("Total Memory", totalMemory + "MB");
    memPros.put("Free Memory", freeMemory + "MB");
    memPros.put("Used Memory", usedMemory + "MB");

    print(builder, memPros);

    printHeader(builder, "Java System Properties");
    Properties sysProps = new Properties();
    for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
      sysProps.put(entry.getKey(), entry.getValue());
    }

    print(builder, sysProps);

    printHeader(builder, "System Environments");
    Map<String, String> getenv = System.getenv();
    Properties envProps = new Properties();
    Set<String> strings = getenv.keySet();
    for (String key : strings) {
      String message = getenv.get(key);
      envProps.put(key, message);
    }

    print(builder, envProps);

    System.out.println(builder.toString());

    ////////////////////////////////////////////////////////////////////////////////////

    NativeLoader.loadSigarNative();

    ////////////////////////////////////////////////////////////////////////////////////

    SpringApplication app = new SpringApplication(Application.class);
    app.setShowBanner(false);
    ApplicationContext ctx = app.run(args);

    try {
      LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
      for (Logger LOGGER : context.getLoggerList()) {
        if (LOGGER instanceof ch.qos.logback.classic.Logger) {
          ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) LOGGER;
          for (Iterator<Appender<ILoggingEvent>> index = logbackLogger.iteratorForAppenders();
              index.hasNext(); ) {
            Appender<ILoggingEvent> appender = index.next();
            if ("FILE".equals(appender.getName())
                && appender instanceof ch.qos.logback.core.rolling.RollingFileAppender) {
              ch.qos.logback.core.rolling.RollingFileAppender logbackAppender =
                  (ch.qos.logback.core.rolling.RollingFileAppender) appender;
              logger.info("Log file is {}", logbackAppender.getFile());
            }
          }
        }
      }
    } catch (Exception ex) {
    }
  }
예제 #10
0
 public String toString() {
   String result = "f=" + (runtime.freeMemory() / MEGA) + "/";
   result += "t=" + (runtime.totalMemory() / MEGA) + "/";
   result += "m=" + (runtime.maxMemory() / MEGA) + "Mb";
   return result;
 }
예제 #11
0
 public static String getAllocatedMemory() {
   Runtime rt = Runtime.getRuntime();
   return getFormattedMemorySize(rt.totalMemory());
 }
예제 #12
0
 public static long getUsedMemory() {
   Runtime rt = Runtime.getRuntime();
   return rt.totalMemory() - rt.freeMemory();
 }
예제 #13
0
파일: JREInfo.java 프로젝트: khatkar/jdd
 public static long totalMemory() {
   return rt.totalMemory();
 }
예제 #14
0
파일: JREInfo.java 프로젝트: khatkar/jdd
 public static long usedMemory() {
   return rt.totalMemory() - rt.freeMemory();
 }