Skip to content

Commit

Permalink
Merge pull request kubernetes#18514 from gmarek/grab-profiles
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Dec 11, 2015
2 parents abf9a90 + a819367 commit db08e06
Showing 1 changed file with 83 additions and 15 deletions.
98 changes: 83 additions & 15 deletions hack/grab-profiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ function grab_profiles_from_component {
for profile in ${requested_profiles}; do
case ${profile} in
cpu)
go tool pprof "-pdf" "${binary}" "http://localhost:${tunnel_port}/${path}/profile" > "${output_prefix}-${profile}-profile-${timestamp}.pdf"
go tool pprof "-pdf" "${binary}" "http://localhost:${tunnel_port}${path}/debug/pprof/profile" > "${output_prefix}-${profile}-profile-${timestamp}.pdf"
;;
mem)
# There are different kinds of memory profiles that are available that
# had to be grabbed separately: --inuse-space, --inuse-objects,
# --alloc-space, --alloc-objects. We need to iterate over all requested
# kinds.
for flag in ${mem_pprof_flags}; do
go tool pprof "-${flag}" "-pdf" "${binary}" "http://localhost:${tunnel_port}/${path}/heap" > "${output_prefix}-${profile}-${flag}-profile-${timestamp}.pdf"
go tool pprof "-${flag}" "-pdf" "${binary}" "http://localhost:${tunnel_port}${path}/debug/pprof/heap" > "${output_prefix}-${profile}-${flag}-profile-${timestamp}.pdf"
done
;;
esac
Expand All @@ -53,22 +53,29 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
server_addr=""
kubelet_addreses=""
kubelet_binary=""
master_binary=""
scheduler_binary=""
scheduler_port="10251"
controller_manager_port="10252"
controller_manager_binary=""
requested_profiles=""
mem_pprof_flags=""
profile_components=""
output_dir="."
tunnel_port="${tunnel_port:-1234}"

args=$(getopt -o s:mho:k: -l server:,master,heapster,output:,kubelet:,help,inuse-space,inuse-objects,alloc-space,alloc-objects,cpu,kubelet-binary: -- "$@")
args=$(getopt -o s:mho:k:c -l server:,master,heapster,output:,kubelet:,scheduler,controller-manager,help,inuse-space,inuse-objects,alloc-space,alloc-objects,cpu,kubelet-binary:,master-binary:,scheduler-binary:,controller-manager-binary:,scheduler-port:,controller-manager-port: -- "$@")
if [[ $? -ne 0 ]]; then
>&2 echo "Error in getopt"
exit 1
fi

HEAPSTER_VERSION="v0.18.2"
MASTER_PPROF_PATH="debug/pprof"
HEAPSTER_PPROF_PATH="api/v1/proxy/namespaces/kube-system/services/monitoring-heapster/debug/pprof"
KUBELET_PPROF_PATH_PREFIX="api/v1/proxy/nodes"
MASTER_PPROF_PATH=""
HEAPSTER_PPROF_PATH="/api/v1/proxy/namespaces/kube-system/services/monitoring-heapster"
KUBELET_PPROF_PATH_PREFIX="/api/v1/proxy/nodes"
SCHEDULER_PPROF_PATH_PREFIX="/api/v1/proxy/namespaces/kube-system/pods/kube-scheduler"
CONTROLLER_MANAGER_PPROF_PATH_PREFIX="/api/v1/proxy/namespaces/kube-system/pods/kube-controller-manager"

eval set -- "${args}"

Expand All @@ -87,19 +94,19 @@ while true; do
shift
profile_components="master ${profile_components}"
;;
-h|--heapster)
shift
profile_components="heapster ${profile_components}"
;;
-o|--output)
--master-binary)
shift
if [ -z "$1" ]; then
>&2 echo "empty argument to --output flag"
>&2 echo "empty argumet to --master-binary flag"
exit 1
fi
output_dir=$1
master_binary=$1
shift
;;
-h|--heapster)
shift
profile_components="heapster ${profile_components}"
;;
-k|--kubelet)
shift
profile_components="kubelet ${profile_components}"
Expand All @@ -119,6 +126,59 @@ while true; do
kubelet_binary=$1
shift
;;
--scheduler)
shift
profile_components="scheduler ${profile_components}"
;;
--scheduler-binary)
shift
if [ -z "$1" ]; then
>&2 echo "empty argumet to --scheduler-binary flag"
exit 1
fi
scheduler_binary=$1
shift
;;
--scheduler-port)
shift
if [ -z "$1" ]; then
>&2 echo "empty argumet to --scheduler-port flag"
exit 1
fi
scheduler_port=$1
shift
;;
-c|--controller-manager)
shift
profile_components="controller-manager ${profile_components}"
;;
--controller-manager-binary)
shift
if [ -z "$1" ]; then
>&2 echo "empty argumet to --controller-manager-binary flag"
exit 1
fi
controller_manager_binary=$1
shift
;;
--controller-manager-port)
shift
if [ -z "$1" ]; then
>&2 echo "empty argumet to --controller-manager-port flag"
exit 1
fi
controller-managerr_port=$1
shift
;;
-o|--output)
shift
if [ -z "$1" ]; then
>&2 echo "empty argument to --output flag"
exit 1
fi
output_dir=$1
shift
;;
--inuse-space)
shift
requested_profiles="mem ${requested_profiles}"
Expand Down Expand Up @@ -202,7 +262,15 @@ for component in ${profile_components}; do
case ${component} in
master)
path=${MASTER_PPROF_PATH}
binary=""
binary=${master_binary}
;;
controller-manager)
path="${CONTROLLER_MANAGER_PPROF_PATH_PREFIX}-${server_addr}:${controller_manager_port}"
binary=${controller_manager_binary}
;;
scheduler)
path="${SCHEDULER_PPROF_PATH_PREFIX}-${server_addr}:${scheduler_port}"
binary=${scheduler_binary}
;;
heapster)
rm heapster
Expand All @@ -224,7 +292,7 @@ for component in ${profile_components}; do

if [[ "${component}" == "kubelet" ]]; then
for node in $(echo ${kubelet_addreses} | sed 's/[,;]/\n/g'); do
grab_profiles_from_component "${requested_profiles}" "${mem_pprof_flags}" "${binary}" "${tunnel_port}" "${path}/${node}/debug/pprof" "${output_dir}/${component}" "${timestamp}"
grab_profiles_from_component "${requested_profiles}" "${mem_pprof_flags}" "${binary}" "${tunnel_port}" "${path}/${node}" "${output_dir}/${component}" "${timestamp}"
done
else
grab_profiles_from_component "${requested_profiles}" "${mem_pprof_flags}" "${binary}" "${tunnel_port}" "${path}" "${output_dir}/${component}" "${timestamp}"
Expand Down

0 comments on commit db08e06

Please sign in to comment.