patric-r / jvmtop

Java monitoring for the command-line, profiler included
GNU General Public License v2.0
1.22k stars 252 forks source link

cant delay first iteration #84

Open cbrdy opened 7 years ago

cbrdy commented 7 years ago

From the jvmtop usage, I can see delay can be set between the iterations but I can not have the delay set for the first iteration itself. The reason I'm asking for this is when I run the jvmtop.sh for the first time, it shows higher values of %cpu for jvmtop as well as other jvms running. I wanted to have the correct %cpu after certain time lets say 5 sec.

mskadu commented 7 years ago

I hit the same problem. However, as a stop gap arrangement - I skip the first couple of readings (i poll every 2 seconds) before starting to log the CPU. I am sure it's easy to work out how ;-)

Hope this helps.

cbrdy commented 7 years ago

yeah, but I'm sending this data to splunk so you can see the issue here.

mskadu commented 7 years ago

Haven't really worked with splunk, so any more information would be useful in making suggestions. My use-case was that I generated a CSV from jvmtop runs that was used as a data source.

patric-r commented 7 years ago

As a rough guess, the initial higher cpu usage might be caused by the attach mechanism itself. Additionally, the remote jvm needs to load additional classes (and may JIT them afterwards) beforehand for the communication with jvmtop. All of this does cost cpu time, of course.

That's why I suspect the higher indicated cpu time within the first seconds after attaching to be correct (and you're free to skip those readings, as mskadu suggested).

cbrdy commented 7 years ago

Yes, that's what I have decided. I have updated jvmtop.sh to my requirements.

#!/bin/sh
# jvmtop - java monitoring for the command-line 
# launch script
#
# author: Markus Kolb
# 

DEFAULT="-help"
PARAM=${@-$DEFAULT}

DIR=`cd "\`dirname "$0"\`" && pwd`

if [ -z "$JAVA_HOME" ] ; then
        JAVA_HOME=`readlink -f \`which java 2>/dev/null\` 2>/dev/null | \
        sed 's/\/bin\/java//'`
fi

TOOLSJAR="$JAVA_HOME/lib/tools.jar"

if [ ! -f "$TOOLSJAR" ] ; then
        echo "$JAVA_HOME seems to be no JDK!" >&2
        exit 1
fi

"$JAVA_HOME"/bin/java $JAVA_OPTS -cp "$DIR/jvmtop.jar:$TOOLSJAR" \
com.jvmtop.JvmTop ${PARAM} |  awk '/load avg/ {c=1; a=$0;next} c>=0{c=c+1;a=a"\n"$0}END{print a}'
exit $?