feisty meow concerns codebase 2.140
MemoryFootprint.java
Go to the documentation of this file.
1package org.gffs.application;
2
3import org.apache.commons.logging.Log;
4import org.apache.commons.logging.LogFactory;
5
6import net.sourceforge.sizeof.SizeOf;
7
12public class MemoryFootprint
13{
14 static private Log _logger = LogFactory.getLog(MemoryFootprint.class);
15
16 // static SizeOf _sizeEstimater = new SizeOf();
17 static {
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);
22 }
23
28 public static long getFootprint(Object o)
29 {
30 if (!_logger.isDebugEnabled()) {
31 _logger.error("abusive memory footprint called when not in debug mode. a logging statement is wrong.");
32 return 0;
33 }
34 try {
35 return SizeOf.sizeOf(o);
36 } catch (Exception e) {
37 _logger.debug("error retrieving SizeOf object; is SizeOf.jar in javaagent?");
38 return 0;
39 }
40 }
41
45 public static long getDeepFootprint(Object o)
46 {
47 if (!_logger.isDebugEnabled()) {
48 _logger.error("abusive memory footprint called when not in debug mode. a logging statement is wrong.");
49 return 0;
50 }
51
52 try {
53 return SizeOf.deepSizeOf(o);
54 } catch (Exception e) {
55 _logger.debug("error retrieving SizeOf object; is SizeOf.jar in javaagent?");
56 return 0;
57 }
58 }
59}