how to tell memory useage of my app in a Mac

Posted on 2014-02-06
Last Modified: 2014-02-11
i am introducing caching to one of my apps (it calls various service methods to access data from DB), and i want to find out how much extra physical memory it takes.  i have tried the activity monitor and also this:

$ Ps -ef | grep dsp
716566150  3234  1070   0  5:41PM ttys000    1:43.18 /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -server -Xms128M -Xmx512M -XX:+HeapDumpOnOutOfMemoryError -XX:PermSize=128M -Ddsp-env=osgi -Djava.endorsed.dirs=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/endorsed:/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/lib/endorsed:/Users/212353126/GIA150/dsp-k-1.5.0/lib/endorsed -Djava.ext.dirs=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/ext:/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/lib/ext:/Users/212353126/GIA150/dsp-k-1.5.0/lib/ext -Dkaraf.instances=/Users/212353126/GIA150/dsp-k-1.5.0/instances -Dkaraf.home=/Users/212353126/GIA150/dsp-k-1.5.0 -Dkaraf.base=/Users/212353126/GIA150/dsp-k-1.5.0 -Djava.util.logging.config.file=/Users/212353126/GIA150/dsp-k-1.5.0/etc/ -Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true -classpath /Users/212353126/GIA150/dsp-k-1.5.0/lib/karaf-jaas-boot.jar:/Users/212353126/GIA150/dsp-k-1.5.0/lib/karaf.jar org.apache.karaf.main.Main
716566150  3408  3182   0  5:59PM ttys004    0:00.00 grep dsp

but i am not sure what all the results mean.  for example, what is the memory usage?  is it possible to break the usage down to a finer level, e.g. by thread or service call?  also is there a way to log the usage?
Question by:mmingfeilam
LVL 12

Assisted Solution

by:Phil Phillips
Phil Phillips earned 250 total points
ID: 39841247
I'm not aware of something that can show memory usage per thread, but you can see the usage of the JVM and its different memory spaces using jstat.

Here's the man page for OSX:
LVL 16

Accepted Solution

Valeri earned 250 total points
ID: 39841267
put this lines before operation and after operation an you will see:

long usedMB = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
System.out.println("memory usage" + usedMB);

for more information use VisualVM, it's much more better than jstat.
LVL 28

Expert Comment

ID: 39851604
If you just wanted %mem, you could just do that with ps.

ps -meo %mem -o command|more

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now