Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #294 from imotai/master
Browse files Browse the repository at this point in the history
add io dump tool
  • Loading branch information
imotai committed Jan 20, 2016
2 parents 6517f76 + b5baba2 commit 3b25dfa
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 114 deletions.
152 changes: 39 additions & 113 deletions build.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ else
echo "install boost done"
fi

if [ -f "Python-2.7.11.tgz" ]
then
echo "python exist"
else
echo "start download python"
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz > /dev/null
tar zxf Python-2.7.11.tgz >/dev/null
cd Python-2.7.11
./configure --prefix=${DEPS_PREFIX} --disable-shared >/dev/null
make -j4 && make install>/dev/null
echo "install python done"
cd -
fi

if [ -f "setuptools-19.2.tar.gz" ]
then
echo "setuptools exist"
else
echo "start download setuptools"
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz
tar -zxvf setuptools-19.2.tar.gz >/dev/null
cd setuptools-19.2
python setup.py install >/dev/null
echo "install setuptools done"
cd -
fi

if [ -d "rapidjson" ]
then
echo "rapid json exist"
Expand Down Expand Up @@ -56,6 +83,9 @@ else
make -j4 >/dev/null
make install
cd -
cd protobuf-2.6.1/python
python setup.py build && python setup.py install
cd -
echo "install protobuf done"
fi

Expand Down Expand Up @@ -92,28 +122,17 @@ else
echo "PROTOBUF_DIR=${DEPS_PREFIX}" >> depends.mk
echo "SNAPPY_DIR=${DEPS_PREFIX}" >> depends.mk
echo "PREFIX=${DEPS_PREFIX}" >> depends.mk
cd src
cd -
cd sofa-pbrpc-1.0.0/src
PROTOBUF_DIR=${DEPS_PREFIX} sh compile_proto.sh
cd ..
make -j4 >/dev/null
make install
cd ..
fi

if [ -f "zookeeper-3.4.6.tar.gz" ]
then
echo "zookeeper-3.4.6.tar.gz exist"
else
# zookeeper
wget http://apache.arvixe.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar zxf zookeeper-3.4.6.tar.gz
cd zookeeper-3.4.6/src/c
./configure ${DEPS_CONFIG} >/dev/null
cd -
cd sofa-pbrpc-1.0.0
make -j4 >/dev/null
make install
cd -
fi


if [ -f "CMake-3.2.1.tar.gz" ]
then
echo "CMake-3.2.1.tar.gz exist"
Expand Down Expand Up @@ -142,69 +161,6 @@ else
cd -
fi

if [ -f "glog-0.3.3.tar.gz" ]
then
echo "glog-0.3.3.tar.gz exist"
else
# glog
wget --no-check-certificate -O glog-0.3.3.tar.gz https://github.com/google/glog/archive/v0.3.3.tar.gz
tar zxf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure ${DEPS_CONFIG} CPPFLAGS=-I${DEPS_PREFIX}/include LDFLAGS=-L${DEPS_PREFIX}/lib >/dev/null
make -j4 >/dev/null
make install
cd -
fi

if [ -d "gtest_archive" ]
then
echo "gtest_archive exist"
else

# gtest
# wget --no-check-certificate https://googletest.googlecode.com/files/gtest-1.7.0.zip
git clone --depth=1 https://github.com/xupeilin/gtest_archive
mv gtest_archive/gtest-1.7.0.zip .
unzip gtest-1.7.0.zip
cd gtest-1.7.0
./configure ${DEPS_CONFIG} >/dev/null
make -j8 >/dev/null
cp -a lib/.libs/* ${DEPS_PREFIX}/lib
cp -a include/gtest ${DEPS_PREFIX}/include
cd -
fi

if [ -f "libunwind-0.99-beta.tar.gz" ]
then
echo "libunwind-0.99-beta.tar.gz exist"
else
# libunwind for gperftools
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz
tar zxf libunwind-0.99-beta.tar.gz
cd libunwind-0.99-beta
./configure ${DEPS_CONFIG} >/dev/null
make CFLAGS=-fPIC -j4 >/dev/null
make CFLAGS=-fPIC install
cd -
fi

if [ -d "gperftools" ]
then
echo "gperftools exist"
else

# gperftools (tcmalloc)
# wget --no-check-certificate https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.1.tar.gz
git clone --depth=1 https://github.com/00k/gperftools
mv gperftools/gperftools-2.2.1.tar.gz .
tar zxf gperftools-2.2.1.tar.gz
cd gperftools-2.2.1
./configure ${DEPS_CONFIG} CPPFLAGS=-I${DEPS_PREFIX}/include LDFLAGS=-L${DEPS_PREFIX}/lib >/dev/null
make -j4 >/dev/null
make install
cd -
fi

if [ -d "leveldb" ]
then
echo "leveldb exist"
Expand Down Expand Up @@ -239,37 +195,12 @@ else
export PATH=${DEPS_PREFIX}/bin:$PATH
export BOOST_PATH=${DEPS_PREFIX}/boost_1_57_0
export PBRPC_PATH=${DEPS_PREFIX}/
make -j4 ins >/dev/null && make -j4 install_sdk
make -j4 ins >/dev/null && make -j4 install_sdk >/dev/null && make python >/dev/null
mkdir -p output/bin && cp ins output/bin
cp -rf output/python/* ../../optools/
cd -
fi

if [ -d "tera" ]
then
echo "tera exist"
else

# tera
git clone https://github.com/baidu/tera
depends_file=depends.mk.template
cd tera
sed -i 's#^SOFA_PBRPC_PREFIX=.*#SOFA_PBRPC_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^PROTOBUF_PREFIX=.*#PROTOBUF_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^SNAPPY_PREFIX=.*#SNAPPY_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^ZOOKEEPER_PREFIX=.*#ZOOKEEPER_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^GFLAGS_PREFIX=.*#GFLAGS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^GLOG_PREFIX=.*#GLOG_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^GTEST_PREFIX=.*#GTEST_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^GPERFTOOLS_PREFIX=.*#GPERFTOOLS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -i 's#^BOOST_INCDIR=.*#BOOST_INCDIR='${DEPS_PREFIX}'\/boost_1_57_0#' ${depends_file}
sed -i 's#^INS_PREFIX=.*#INS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
sed -e '$ c -lgtest_main -lgtest -lglog -lgflags -ltcmalloc_minimal -lunwind' ${depends_file} > depends.mk.new
mv depends.mk.new depends.mk
make -j8 >/dev/null
cp -a build/lib/*.a ${DEPS_PREFIX}/lib
cp -a build/include/*.h ${DEPS_PREFIX}/include
cd -
fi

if [ -d "mdt" ]
then
Expand All @@ -282,16 +213,11 @@ else
sed -i 's/^SOFA_PBRPC_PREFIX=.*/SOFA_PBRPC_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^PROTOBUF_PREFIX=.*/PROTOBUF_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^SNAPPY_PREFIX=.*/SNAPPY_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^ZOOKEEPER_PREFIX=.*/ZOOKEEPER_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^GFLAGS_PREFIX=.*/GFLAGS_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^GLOG_PREFIX=.*/GLOG_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^GTEST_PREFIX=.*/GTEST_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^GPERFTOOLS_PREFIX=.*/GPERFTOOLS_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^BOOST_INCDIR=.*/BOOST_INCDIR=..\/..\/thirdparty\/boost_1_57_0/' depends.mk
sed -i 's/^INS_PREFIX=.*/INS_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i 's/^TERA_PREFIX=.*/TERA_PREFIX=..\/..\/thirdparty/' depends.mk
sed -i '/-lgtest_main/c -lgtest_main -lgtest -lglog -lgflags -ltcmalloc_minimal -lunwind' depends.mk
make -j8 >/dev/null
sed -i '/-lgtest_main/c -lglog -lgflags' depends.mk
make -j8 libftrace.a >/dev/null
cp src/ftrace/collector/logger.h ${DEPS_PREFIX}/include
cp libftrace.a ${DEPS_PREFIX}/lib
cd -
Expand Down
83 changes: 82 additions & 1 deletion optools/galaxy
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,90 @@
#
# processname: galaxy

PROD_ADDR=ftp://xxxxxx/tmp/galaxy.tar.gz
PROD_ADDR=xxxxx
. /etc/rc.d/init.d/functions
AGENT_IP=`hostname -i`
AGENT_HOME=/home/galaxy/agent
RETVAL=0

netCards=$(/sbin/ifconfig | awk '/Ethernet/{a=$0; getline; b=$0; print a,b}' | grep "inet addr" | awk '{print $1}')

readd_mod() {
local DEV=$1
local IP=$(cat /etc/sysconfig/network-scripts/ifcfg-${DEV} | grep IPADDR | cut -d "=" -f 2)
local GATEWAY=$(ip route | grep ${DEV} | grep via | awk '{print $3}' | head -1)
if ! grep "GATEWAY" /etc/sysconfig/network-scripts/ifcfg-${DEV} > /dev/null; then
echo "GATEWAY=${GATEWAY}" >> /etc/sysconfig/network-scripts/ifcfg-${DEV}
fi
local ETH=${DEV}
local driver=`ethtool -i ${ETH} | grep driver | awk '{print $2}'`

if [[ ${driver} == "igb" ]] && ! grep "RSS=8,8" /etc/modprobe.conf | grep "igb" &>/dev/null ;then
sed -i '/options igb.*/d' /etc/modprobe.conf
sed -i '/^$/d' /etc/modprobe.conf
echo "options igb RSS=8,8" >> /etc/modprobe.conf

rmmod igb && modprobe igb && /etc/init.d/network start && /etc/rc.local
fi
}

set_affinity() {
MASK=$((1<<$VEC))
printf "%s mask=%X for /proc/irq/%d/smp_affinity\n" $DEV $MASK $IRQ 2>/dev/null
printf "%X" $MASK > /proc/irq/$IRQ/smp_affinity 2>/dev/null
#echo $DEV mask=$MASK for /proc/irq/$IRQ/smp_affinity
#echo $MASK > /proc/irq/$IRQ/smp_affinity
}

if [[ ${#netCards} -eq 0 ]]; then
exit 1
fi
# check for irqbalance running
IRQBALANCE_ON=`ps ax | grep -v grep | grep -q irqbalance; echo $?`
if [ "$IRQBALANCE_ON" == "0" ] ; then
echo " WARNING: irqbalance is running and will"
echo " likely override this script's affinitization."
echo " Please stop the irqbalance service and/or execute"
echo " 'killall irqbalance'"
fi

for DEV in $(echo ${netCards}); do
#
# Set up the desired devices.
#
eth_interrputs=$(cat /proc/interrupts | grep "${DEV}" | wc -l )
if [[ ${eth_interrputs} -le 2 ]]; then
readd_mod ${DEV}
fi
for DIR in rx tx TxRx fp ''; do
MAX=`grep $DEV-$DIR /proc/interrupts | wc -l`
if [ "$MAX" == "0" ] ; then
MAX=`egrep -i "$DEV:.*$DIR" /proc/interrupts | wc -l`
fi
if [ "$MAX" == "0" ] ; then
echo no $DIR vectors found on $DEV
continue
#exit 1
fi
for VEC in `seq 0 1 $MAX`; do
if [ "x$DIR" = "x" ]; then
IRQ=`cat /proc/interrupts | grep -i $DEV-$DIR$VEC"$" | cut -d: -f1 | sed "s/ //g"`
else
IRQ=`cat /proc/interrupts | grep -i $DEV-$DIR-$VEC"$" | cut -d: -f1 | sed "s/ //g"`
fi

if [ -n "$IRQ" ]; then
set_affinity
else
IRQ=`cat /proc/interrupts | egrep -i $DEV:v$VEC-$DIR"$" | cut -d: -f1 | sed "s/ //g"`
if [ -n "$IRQ" ]; then
set_affinity
fi
fi
done
done
done

init() {
// config core dump dir
mkdir -p /home/disk2/coresave
Expand All @@ -34,6 +113,7 @@ init() {
mkdir -p $AGENT_HOME/gc_dir
mkdir -p $AGENT_HOME/log
echo 0 > /proc/sys/kernel/printk
ulimit -n 65536
}

download_pkg() {
Expand All @@ -48,6 +128,7 @@ download_pkg() {
echo "--agent_ip=$AGENT_IP" >> conf/galaxy.flag
df -h | grep ssd | awk '{print $6}' >> conf/mount_bind.template
df -h | grep disk | awk '{print $6}' >> conf/mount_bind.template
echo "/home/opt" >> conf/mount_bind.template
}

start() {
Expand Down
84 changes: 84 additions & 0 deletions optools/io_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding:utf-8 -*-
import os
import time
import datetime
import sys
# dump process_name io usage on device
class IoDump(object):
def __init__(self, process_name=[], top_size = 10):
self.process_data = {}
self.process_name = process_name

def readable(self, num):
for unit in ['','K','M','G','T','P','E','Z']:
if abs(num) < 1024.0:
return "%3.1f%s"%(num, unit)
num /= 1024.0
return "%.1f%s" % (num, 'Y')

def collect(self):
entries = os.listdir("/proc")
statistics = {}
for entry in entries:
try:
pid = int(entry)
exe_path = os.path.realpath("/proc/%d/exe"%pid)
offset = exe_path.rfind("/")
bin = exe_path[offset+1:]
if bin in self.process_name:
status, read_bytes_ps, write_bytes_ps = self.calc_process(pid)
if not status:
continue
stat = statistics.get(bin,{"read_bytes_ps":0, "write_bytes_ps":0})
stat["read_bytes_ps"] += read_bytes_ps
stat["write_bytes_ps"] += write_bytes_ps
statistics[bin] = stat
except Exception,e:
pass
stat_array = []
for key in statistics:
item = {"name":key}
item.update(statistics[key])
stat_array.append(item)
sorted_array = sorted(stat_array, key=lambda item : item["read_bytes_ps"], reverse = True)
output = []
now = time.time()
output.append("-------------------------------------------------")
output.append(datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S'))
for item in sorted_array:
output.append("%s read:%s/s write:%s/s"%(item["name"], self.readable(item["read_bytes_ps"]),
self.readable(item["write_bytes_ps"])))
print "\n".join(output)

def calc_process(self, pid):
data = {'read':0,
'write':0,
'cancell':0}
fd = open("/proc/%d/io"%pid, "r")
for line in fd.readlines():
parts = line.replace("\n","").split(":")
if parts[0] == "read_bytes":
data["read"] = int(parts[1][1:])
elif parts[0] == "write_bytes":
data["write"] = int(parts[1][1:])
elif parts[0] == "cancelled_write_bytes":
data["cancell"] = int(parts[1][1:])
fd.close()
if pid in self.process_data:
old_data = self.process_data[pid]
read_bytes_ps = data["read"] - old_data["read"]
write_bytes_ps = (data["write"] - data["cancell"]) - (old_data["write"] - old_data["cancell"])
self.process_data[pid] = data
return True, read_bytes_ps, write_bytes_ps
else:
self.process_data[pid] = data
return False, 0, 0

def main():
dump = IoDump(sys.argv)
while True:
dump.collect()
time.sleep(1)

if __name__ == "__main__":
main()
Loading

0 comments on commit 3b25dfa

Please sign in to comment.