KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dappit > Dapper > parser > profiler > SimpleMemoryProfiler


1 /**
2  *
3  */

4 package com.dappit.Dapper.parser.profiler;
5
6 /**
7  * @author Ohad Serfaty
8  *
9  * this class is not working properly. please try another way...
10  *
11  */

12 @SuppressWarnings JavaDoc("unused")
13 public class SimpleMemoryProfiler extends SimpleProfiler {
14
15     
16     
17     private long startFreeMem;
18     
19     private long startTotalMem;
20     private long startMaxMemory;
21
22     /* (non-Javadoc)
23      * @see com.dappit.Dapper.parser.profiler.SimpleProfiler#report(java.lang.String)
24      */

25     @Override JavaDoc
26     public double report(String JavaDoc reportPrefix) {
27         System.gc();
28         long currentFreeMem = Runtime.getRuntime().freeMemory();
29         long currentTotalMem = Runtime.getRuntime().totalMemory();
30         long currentMaxMemory = Runtime.getRuntime().maxMemory();
31         
32         System.out.println("free :" + currentFreeMem);
33 // System.out.println("total : " + currentTotalMem);
34
// System.out.println("max : " + currentMaxMemory);
35
if (reportPrefix != null)
36             System.err.println(reportPrefix +": " + (currentFreeMem - startFreeMem));
37         return currentFreeMem - startFreeMem;
38     }
39
40     /* (non-Javadoc)
41      * @see com.dappit.Dapper.parser.profiler.SimpleProfiler#start()
42      */

43     @Override JavaDoc
44     public void start()
45     {
46         System.gc();
47         startFreeMem = Runtime.getRuntime().freeMemory();
48         startTotalMem = Runtime.getRuntime().totalMemory();
49         startMaxMemory = Runtime.getRuntime().maxMemory();
50         
51         System.out.println("free :" + startFreeMem);
52 // System.out.println("total : " + startTotalMem);
53
// System.out.println("max : " + startMaxMemory);
54
}
55
56 }
57
Popular Tags