码迷,mamicode.com
首页 > 编程语言 > 详细

java.sizeOf

时间:2014-08-05 15:19:29      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:http   java   io   strong   for   art   ar   cti   

Introduction

With java.SizeOf you can measure the real memory size of your Java objects. Download it here


The project is a little java agent what use the package java.lang.Instrument introduced in Java 5 and is released under GPL license.


java.sizeOf is in early stage of development but it‘s quite usable and it was very useful for us to know the memory size of our HttpSession‘s objects. The best use of the library is inside an aspect to avoid dependencies in your code.

Quickstart

1. include sizeOf.jar in the classpath of your application and use it in your code like this:

 import net.sourceforge.sizeof
 ...
 SizeOf.skipStaticField(true); //java.sizeOf will not compute static fields
 SizeOf.skipFinalField(true); //java.sizeOf will not compute final fields
 SizeOf.skipFlyweightObject(true); //java.sizeOf will not compute well-known flyweight objects
 System.out.println(SizeOf.deepSizeOf(<your object>)); //this will print the object size in bytes

You can dump object‘s size setting the min size to log (if you don‘t specify an output stream standard out is used):

 SizeOf.setMinSizeToLog(1024); //min object size to log in bytes
 SizeOf.setLogOutputStream(new FileOutputStream("<your log file>"));

Use the humanReadable() method to get the object size in byte, kilo or mega (if you need giga your in trouble guy!):

 SizeOf.humanReadable(SizeOf.deepSizeOf(<your object>));

2. start your application with the following JVM parameter:

 -javaagent:/path_to/sizeOf.jar

3. have fun!


Please use SourceForge forum for reporting any bug, comment or suggestion.

http://sizeof.sourceforge.net/

java.sizeOf,布布扣,bubuko.com

java.sizeOf

标签:http   java   io   strong   for   art   ar   cti   

原文地址:http://www.cnblogs.com/softidea/p/3892129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!