01: package org.cougaar.core.qos.profile;
02:
03: import java.lang.reflect.*;
04: import java.io.*;
05: import java.text.*;
06: import java.util.*;
07: import java.util.regex.*;
08: import org.cougaar.core.agent.*;
09: import org.cougaar.core.component.*;
10: import org.cougaar.core.mts.*;
11: import org.cougaar.core.node.*;
12: import org.cougaar.core.qos.metrics.*;
13: import org.cougaar.core.service.*;
14: import org.cougaar.core.service.wp.*;
15: import org.cougaar.core.thread.*;
16: import org.cougaar.core.wp.resolver.*;
17: import org.cougaar.util.*;
18:
19: /**
20: * This component profiles the JVM heap size (used, free, total,
21: * max).
22: * <p>
23: * Example output:<pre>
24: * jvmheap - #used_bytes, free_bytes, total_bytes, max_bytes
25: * jvmheap - 5430096, 5084336, 10514432, 66650112
26: * </pre>
27: * In this example, the current JVM heap size is 5.18 mb.
28: *
29: * @see ProfilerCoordinator required coordinator component
30: */
31: public class JavaHeapSize extends ProfilerBase {
32: // 0.07 0.36 0.37 1/262 5191
33: private static final String[] FIELDS = new String[] { "used_bytes",
34: "free_bytes", "total_bytes", "max_bytes" };
35: private static final String HEADER = toHeader(FIELDS);
36:
37: public void run() {
38: log("org.cougaar.core.qos.profile.jvmheap", HEADER,
39: getJavaHeap());
40: }
41:
42: private String getJavaHeap() {
43: Runtime rt = Runtime.getRuntime();
44: long freeMemory = rt.freeMemory();
45: long totalMemory = rt.totalMemory();
46: long maxMemory = rt.maxMemory();
47: long usedMemory = totalMemory - freeMemory;
48: return usedMemory + ", " + freeMemory + ", " + totalMemory
49: + ", " + maxMemory;
50: }
51: }
|