1 package org.gffs.application;
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
6 import net.sourceforge.sizeof.SizeOf;
9 * can retrieve the size of java objects to assist tuning of caches and memory usage. this requires the SizeOf jar and -javaagent setting to
10 * point at that jar. this is the project page: https://sourceforge.net/projects/sizeof/?source=typ_redirect
12 public class MemoryFootprint
14 static private Log _logger = LogFactory.getLog(MemoryFootprint.class);
16 // static SizeOf _sizeEstimater = new SizeOf();
18 // don't count statics in the memory size.
19 SizeOf.skipStaticField(true);
20 // only complain about large objects if they're bigger than the limit below.
21 SizeOf.setMinSizeToLog(5 * 1024 * 1024);
25 * can report the size of the object 'o' if instrumentation has been set up. if instrumentation is absent, all object sizes will be
28 public static long getFootprint(Object o)
30 if (!_logger.isDebugEnabled()) {
31 _logger.error("abusive memory footprint called when not in debug mode. a logging statement is wrong.");
35 return SizeOf.sizeOf(o);
36 } catch (Exception e) {
37 _logger.debug("error retrieving SizeOf object; is SizeOf.jar in javaagent?");
43 * reports the size of the object 'o' plus the size of all other objects reachable from it.
45 public static long getDeepFootprint(Object o)
47 if (!_logger.isDebugEnabled()) {
48 _logger.error("abusive memory footprint called when not in debug mode. a logging statement is wrong.");
53 return SizeOf.deepSizeOf(o);
54 } catch (Exception e) {
55 _logger.debug("error retrieving SizeOf object; is SizeOf.jar in javaagent?");