Monday, June 24, 2019

java - Ways to measure memory consumption while running JUnit tests



I need to measure how much of memory do my JUnit tests consume.




  1. So the most obvious (but not convinient) way is to run JVM with arguments like "-Xms128m -Xmx512m" and track when I'll get the OutOfMemory error.


  2. The second way is to request a heapdump after running all my tests and then use Memory Analyzer Tool. But it isn't useful to do this every time I'm running tests.





The desired way is, let's say, to log memory consumption into a file with such values as maximum memory consumption, average consumption, GC calls count etc. Or even draw a diagram which will show how memory was used.



And the question is, are there any tools, or methods, or instruments to do this? Or, maybe, my wishes are unreal and naive and there is no way to gather such data?



Tests are running under IntelliJ Idea with JUnit4. I'm free to use any other environment. Thanks in advance for any advice!


Answer



You can use JConsole,




http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html



It comes with your JDK


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...