Showing just topten of amount of memory
authorjtulach@netbeans.org
Tue, 13 Nov 2007 08:29:18 +0000
changeset 2690957a10546bee
parent 2689 caf9e7ad1608
child 2691 d29b2c8cfb5e
Showing just topten of amount of memory
logger/uihandlerserver/src/java/org/netbeans/server/uihandler/statistics/Memory.java
logger/uihandlerserver/web/graph/memory.jsp
     1.1 --- a/logger/uihandlerserver/src/java/org/netbeans/server/uihandler/statistics/Memory.java	Tue Nov 13 08:06:51 2007 +0000
     1.2 +++ b/logger/uihandlerserver/src/java/org/netbeans/server/uihandler/statistics/Memory.java	Tue Nov 13 08:29:18 2007 +0000
     1.3 @@ -40,7 +40,10 @@
     1.4  import java.util.List;
     1.5  import java.util.Map;
     1.6  import java.util.Set;
     1.7 +import java.util.SortedMap;
     1.8 +import java.util.SortedSet;
     1.9  import java.util.TreeMap;
    1.10 +import java.util.TreeSet;
    1.11  import java.util.logging.LogRecord;
    1.12  
    1.13  /** Computes how much physical memory is used.
    1.14 @@ -50,11 +53,12 @@
    1.15  public final class Memory extends Statistics<Map<Long,Set<String>>> {
    1.16      private final static String TEMP_ID = "temporaryID";
    1.17      
    1.18 -    public static List<MemBean> convertToDataset(Map<Long, Set<String>> logs) {
    1.19 -        List<MemBean> result = new ArrayList<MemBean>();
    1.20 +    public static Set<MemBean> convertToDataset(Map<Long, Set<String>> logs) {
    1.21 +        SortedMap<MemBean,Integer> result = new TreeMap<MemBean,Integer>();
    1.22 +        int fullCount = 0;
    1.23          for (Map.Entry<Long, Set<String>> entry: logs.entrySet()) {
    1.24 -            MemBean mb = new MemBean();
    1.25              long mem = entry.getKey();
    1.26 +            MemBean mb = new MemBean(mem);
    1.27              String memLabel = "";
    1.28              if (mem > 1024 * 1024 * 1024) {
    1.29                  memLabel = MessageFormat.format("{0,number,###0.###} GB", mem / 1024.0 / 1024.0 / 1024.0);
    1.30 @@ -66,9 +70,31 @@
    1.31              mb.setMemory(memLabel);
    1.32              entry.getValue().remove(TEMP_ID);
    1.33              mb.setCount(entry.getValue().size());
    1.34 -            result.add(mb);
    1.35 +            result.put(mb, mb.getCount());
    1.36 +            fullCount += mb.getCount();
    1.37          }
    1.38 -        return result;
    1.39 +        
    1.40 +        return groupResults(result, fullCount / 20);
    1.41 +    }
    1.42 +    
    1.43 +    private static SortedSet<MemBean> groupResults(SortedMap<MemBean,Integer> map, int minCount) {
    1.44 +        int nowCount = 0;
    1.45 +        SortedSet<MemBean> mem = new TreeSet<Memory.MemBean>();
    1.46 +        MemBean last = null;
    1.47 +        for (Map.Entry<MemBean, Integer> entry : map.entrySet()) {
    1.48 +            nowCount += entry.getValue();
    1.49 +            if (nowCount >= minCount) {
    1.50 +                MemBean mb = entry.getKey();
    1.51 +                mb.setCount(nowCount);
    1.52 +                nowCount = 0;
    1.53 +                mem.add(mb);
    1.54 +            }
    1.55 +        }
    1.56 +        if (last != null) {
    1.57 +            last.setCount(nowCount);
    1.58 +            mem.add(last);
    1.59 +        }
    1.60 +        return mem;
    1.61      }
    1.62      
    1.63      public Memory() {
    1.64 @@ -151,18 +177,20 @@
    1.65          page.setAttribute(name, convertToDataset(data));
    1.66      }
    1.67  
    1.68 -    public static class MemBean {
    1.69 -
    1.70 +    public static class MemBean implements Comparable<MemBean> {
    1.71 +        private long mem;
    1.72          private int count;
    1.73          private String memory;
    1.74          
    1.75 -        public MemBean() {}
    1.76 +        public MemBean(long mem) {
    1.77 +            this.mem = mem;
    1.78 +        }
    1.79          
    1.80          public String getMemory() { return memory; }
    1.81 -        public void setMemory(String mem) { memory = mem; }
    1.82 +        void setMemory(String mem) { memory = mem; }
    1.83          
    1.84          public int getCount() { return count; }
    1.85 -        public void setCount(int count) { this.count = count; }
    1.86 +        void setCount(int count) { this.count = count; }
    1.87          
    1.88          public String getSerie() { return ""; }
    1.89  
    1.90 @@ -170,6 +198,13 @@
    1.91          public String toString() {
    1.92              return "Memory: "+memory+" # of users: "+count;
    1.93          }
    1.94 +
    1.95 +        public int compareTo(MemBean o) {
    1.96 +            if (mem == o.mem) {
    1.97 +                return 0;
    1.98 +            }
    1.99 +            return mem < o.mem ? -1 : 1;
   1.100 +        }
   1.101      }
   1.102  }
   1.103      
     2.1 --- a/logger/uihandlerserver/web/graph/memory.jsp	Tue Nov 13 08:06:51 2007 +0000
     2.2 +++ b/logger/uihandlerserver/web/graph/memory.jsp	Tue Nov 13 08:29:18 2007 +0000
     2.3 @@ -26,13 +26,14 @@
     2.4          
     2.5          <p>
     2.6              Amount of physical memory is important for runtime performance of
     2.7 -            NetBeans. 
     2.8 +            NetBeans and that is why here is a graph of the amount of memory
     2.9 +            various users of the NetBeans IDE have.
    2.10          </p>
    2.11      </div>
    2.12      
    2.13          <table width="100%">
    2.14          <% 
    2.15 -        java.util.List all= (java.util.List)
    2.16 +        java.util.Collection all= (java.util.Collection)
    2.17                  pageContext.getAttribute("globalMemory");
    2.18                  
    2.19          if (all != null && !all.isEmpty()) {