Hello Juan Hernandez,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/17470
to review the following change.
Change subject: tools: Add script to dump heap
......................................................................
tools: Add script to dump heap
This change adds the engine-heap-dump.sh script that generates an
histogram of the use of memory and a heap dump. These files can be
manually generated using the jmap tool, the script just simplifies
it a bit.
Change-Id: Ic337441123a7129d71c0a90aa4b12c8ec49c03c7
Signed-off-by: Juan Hernandez <[email protected]>
Signed-off-by: Liran Zelkha <[email protected]>
Signed-off-by: Alon Bar-Lev <[email protected]>
---
A packaging/bin/engine-heap-dump.sh
1 file changed, 89 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/17470/1
diff --git a/packaging/bin/engine-heap-dump.sh
b/packaging/bin/engine-heap-dump.sh
new file mode 100755
index 0000000..0f768aa
--- /dev/null
+++ b/packaging/bin/engine-heap-dump.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+. "$(dirname "$(readlink -f "$0")")"/engine-prolog.sh
+
+if [ "$(id -u)" = 0 ]; then
+ exec su - "${ENGINE_USER}" -c "$0" "$@"
+ die "Cannot su into root."
+fi
+
+warn() {
+ local m="$1"
+ echo "WARNING: ${m}"
+}
+
+dump() {
+ local prefix="$1"
+ local pid="$2"
+
+ local histo="${prefix}histo.${pid}.txt"
+ local dump="${prefix}dump.${pid}.bin"
+ local heap="${prefix}heap.${pid}.txt"
+
+ "${JMAP}" -histo -F ${PID} > "${histo}" \
+ || warn "Cannot dump histogram"
+ "${JMAP}" -heap ${PID} > "${heap}" \
+ || warn "Cannot dump heap"
+ "${JMAP}" -F -dump:format=b,file="${dump}" ${PID} \
+ || warn "Cannot dump memory"
+
+ cat << __EOF__
+Dumps are ready:
+Histogram: ${histo}
+Heap: ${heap}
+Dump: ${dump}
+__EOF__
+}
+
+usage() {
+ cat << __EOF__
+Usage: $0 [OPTIONS]
+Generate Java heap dump.
+
+ --outdir=dir directory to write files into, default tmpdir.
+ --prefix=prefix files' prefix, default current date.
+ --pid=pid pid to dump, default ovirt-engine service.
+__EOF__
+}
+
+JDK_HOME="${JDK_HOME:-/usr}"
+JMAP="${JMAP:-${JDK_HOME}/bin/jmap}"
+OUTDIR="${TMPDIR:-/tmp}"
+PREFIX="$(date +"%Y%m%d%H%M%S")-"
+PID=
+
+while [ -n "$1" ]; do
+ x="$1"
+ v="${x#*=}"
+ shift
+ case "${x}" in
+ --outdir=*)
+ OUTDIR="${v}"
+ ;;
+ --prefix=*)
+ PREFIX="${v}"
+ ;;
+ --pid=*)
+ PID="${v}"
+ ;;
+ --help)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+[ -x "${JMAP}" ] \
+ || die "The jmap tool is not available. Please install a JDK (inplace
of a JRE)"
+
+if [ -z "${PID}" ]; then
+ PID="$(pidof ovirt-engine)" || die "The engine is not running"
+fi
+
+dump "${OUTDIR}/${PREFIX}" "${PID}"
+
+exit 0
--
To view, visit http://gerrit.ovirt.org/17470
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic337441123a7129d71c0a90aa4b12c8ec49c03c7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
Gerrit-Reviewer: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches