Changeset 8212d68


Ignore:
Timestamp:
Nov 9, 2017 5:39:14 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
43d496a
Parents:
f060287
Message:

Summary Bar: Use Rate instead of instantaneous value for used memory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java

    rf060287 r8212d68  
    301301        DecimalFormat integerFormatter = new DecimalFormat("###,###,##0");
    302302        long tot = SystemVersion.getMaxMemory();
    303         long free = Runtime.getRuntime().freeMemory();
    304         long used = (tot - free) / (1024*1024);
    305         //long usedPc = 100 - ((free * 100) / tot);
     303        // This reads much higher than the graph, possibly because it's right in
     304        // the middle of a console refresh... so get it from the Rate instead.
     305        //long free = Runtime.getRuntime().freeMemory();
     306        long used = (long) _context.statManager().getRate("router.memoryUsed").getRate(60*1000).getAvgOrLifetimeAvg();
     307        if (used <= 0) {
     308            long free = Runtime.getRuntime().freeMemory();
     309            used = tot - free;
     310        }
     311        used /= 1024*1024;
    306312        long total = tot / (1024*1024);
    307313        // long free = Runtime.getRuntime().freeMemory()/1024/1024;
     
    315321        DecimalFormat integerFormatter = new DecimalFormat("###,###,##0");
    316322        long tot = SystemVersion.getMaxMemory();
    317         long free = Runtime.getRuntime().freeMemory();
    318         long used = (tot - free) / (1024*1024);
    319         long usedPc = 100 - ((free * 100) / tot);
     323        // This reads much higher than the graph, possibly because it's right in
     324        // the middle of a console refresh... so get it from the Rate instead.
     325        //long free = Runtime.getRuntime().freeMemory();
     326        long used = (long) _context.statManager().getRate("router.memoryUsed").getRate(60*1000).getAvgOrLifetimeAvg();
     327        long usedPc;
     328        if (used <= 0) {
     329            long free = Runtime.getRuntime().freeMemory();
     330            usedPc = 100 - ((free * 100) / tot);
     331            used = (tot - free) / (1024*1024);
     332        } else {
     333            usedPc = used * 100 / tot;
     334            used /= 1024*1024;
     335        }
    320336        long total = tot / (1024*1024);
    321337        // long free = Runtime.getRuntime().freeMemory()/1024/1024;
Note: See TracChangeset for help on using the changeset viewer.