OSDN Git Service

Added programs using WALA/Soot
[soba/JavaAnalysisToolsDemo.git] / JavaAnalysisToolsDemo / src / demo / util / MemoryInfo.java
1 package demo.util;\r
2 \r
3 import java.text.DecimalFormat;\r
4 \r
5 public class MemoryInfo {\r
6 \r
7         public static String getMemoryInfo() {\r
8             DecimalFormat f1 = new DecimalFormat("#,###KB");\r
9             DecimalFormat f2 = new DecimalFormat("##.#");\r
10             long free = Runtime.getRuntime().freeMemory() / 1024;\r
11             long total = Runtime.getRuntime().totalMemory() / 1024;\r
12             long max = Runtime.getRuntime().maxMemory() / 1024;\r
13             long used = total - free;\r
14             double ratio = (used * 100 / (double)total);\r
15             String info = \r
16             "Java Memory: total=" + f1.format(total) + "\81A" +\r
17             "used=" + f1.format(used) + " (" + f2.format(ratio) + "%)\81A" +\r
18             "available="+f1.format(max);\r
19             return info;\r
20         }\r
21         \r
22 }\r