001 /* 002 * LAPIS lightweight structured text processing system 003 * 004 * Copyright (C) 1998-2002 Carnegie Mellon University, 005 * Copyright (C) 2003 Massachusetts Institute of Technology. 006 * All rights reserved. 007 * 008 * This library is free software; you can redistribute it 009 * and/or modify it under the terms of the GNU General 010 * Public License as published by the Free Software 011 * Foundation, version 2. 012 * 013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/ 014 */ 015 016 017 package lapisx.util; 018 019 public abstract class Mem { 020 021 public static long free () { 022 return Runtime.getRuntime ().freeMemory (); 023 } 024 025 public static long used () { 026 Runtime r = Runtime.getRuntime (); 027 return r.totalMemory() - r.freeMemory (); 028 } 029 030 public static long total () { 031 return Runtime.getRuntime ().totalMemory (); 032 } 033 034 public static String getReport () { 035 return "Memory: used " + (used()/1000) + "KB, free " 036 + (free()/1000) + "KB, total " + (total()/1000) + "KB"; 037 } 038 039 public static void gc () { 040 Runtime r = Runtime.getRuntime (); 041 r.runFinalization (); 042 r.gc (); 043 } 044 045 public static void dumpThreadInfo () { 046 ThreadGroup g = Thread.currentThread().getThreadGroup (); 047 Thread[] t = new Thread[g.activeCount ()]; 048 g.enumerate (t); 049 System.err.println ("Active threads in " + g); 050 for (int i=0; i<t.length; ++i) 051 System.err.println (t[i]); 052 } 053 054 }