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

Commit 3b25dfa

Browse files
committed
Merge pull request #294 from imotai/master
add io dump tool
2 parents 6517f76 + b5baba2 commit 3b25dfa

File tree

4 files changed

+307
-114
lines changed

4 files changed

+307
-114
lines changed

build.sh

100755100644
Lines changed: 39 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ else
2929
echo "install boost done"
3030
fi
3131

32+
if [ -f "Python-2.7.11.tgz" ]
33+
then
34+
echo "python exist"
35+
else
36+
echo "start download python"
37+
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz > /dev/null
38+
tar zxf Python-2.7.11.tgz >/dev/null
39+
cd Python-2.7.11
40+
./configure --prefix=${DEPS_PREFIX} --disable-shared >/dev/null
41+
make -j4 && make install>/dev/null
42+
echo "install python done"
43+
cd -
44+
fi
45+
46+
if [ -f "setuptools-19.2.tar.gz" ]
47+
then
48+
echo "setuptools exist"
49+
else
50+
echo "start download setuptools"
51+
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz
52+
tar -zxvf setuptools-19.2.tar.gz >/dev/null
53+
cd setuptools-19.2
54+
python setup.py install >/dev/null
55+
echo "install setuptools done"
56+
cd -
57+
fi
58+
3259
if [ -d "rapidjson" ]
3360
then
3461
echo "rapid json exist"
@@ -56,6 +83,9 @@ else
5683
make -j4 >/dev/null
5784
make install
5885
cd -
86+
cd protobuf-2.6.1/python
87+
python setup.py build && python setup.py install
88+
cd -
5989
echo "install protobuf done"
6090
fi
6191

@@ -92,28 +122,17 @@ else
92122
echo "PROTOBUF_DIR=${DEPS_PREFIX}" >> depends.mk
93123
echo "SNAPPY_DIR=${DEPS_PREFIX}" >> depends.mk
94124
echo "PREFIX=${DEPS_PREFIX}" >> depends.mk
95-
cd src
125+
cd -
126+
cd sofa-pbrpc-1.0.0/src
96127
PROTOBUF_DIR=${DEPS_PREFIX} sh compile_proto.sh
97-
cd ..
98-
make -j4 >/dev/null
99-
make install
100-
cd ..
101-
fi
102-
103-
if [ -f "zookeeper-3.4.6.tar.gz" ]
104-
then
105-
echo "zookeeper-3.4.6.tar.gz exist"
106-
else
107-
# zookeeper
108-
wget http://apache.arvixe.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
109-
tar zxf zookeeper-3.4.6.tar.gz
110-
cd zookeeper-3.4.6/src/c
111-
./configure ${DEPS_CONFIG} >/dev/null
128+
cd -
129+
cd sofa-pbrpc-1.0.0
112130
make -j4 >/dev/null
113131
make install
114132
cd -
115133
fi
116134

135+
117136
if [ -f "CMake-3.2.1.tar.gz" ]
118137
then
119138
echo "CMake-3.2.1.tar.gz exist"
@@ -142,69 +161,6 @@ else
142161
cd -
143162
fi
144163

145-
if [ -f "glog-0.3.3.tar.gz" ]
146-
then
147-
echo "glog-0.3.3.tar.gz exist"
148-
else
149-
# glog
150-
wget --no-check-certificate -O glog-0.3.3.tar.gz https://github.com/google/glog/archive/v0.3.3.tar.gz
151-
tar zxf glog-0.3.3.tar.gz
152-
cd glog-0.3.3
153-
./configure ${DEPS_CONFIG} CPPFLAGS=-I${DEPS_PREFIX}/include LDFLAGS=-L${DEPS_PREFIX}/lib >/dev/null
154-
make -j4 >/dev/null
155-
make install
156-
cd -
157-
fi
158-
159-
if [ -d "gtest_archive" ]
160-
then
161-
echo "gtest_archive exist"
162-
else
163-
164-
# gtest
165-
# wget --no-check-certificate https://googletest.googlecode.com/files/gtest-1.7.0.zip
166-
git clone --depth=1 https://github.com/xupeilin/gtest_archive
167-
mv gtest_archive/gtest-1.7.0.zip .
168-
unzip gtest-1.7.0.zip
169-
cd gtest-1.7.0
170-
./configure ${DEPS_CONFIG} >/dev/null
171-
make -j8 >/dev/null
172-
cp -a lib/.libs/* ${DEPS_PREFIX}/lib
173-
cp -a include/gtest ${DEPS_PREFIX}/include
174-
cd -
175-
fi
176-
177-
if [ -f "libunwind-0.99-beta.tar.gz" ]
178-
then
179-
echo "libunwind-0.99-beta.tar.gz exist"
180-
else
181-
# libunwind for gperftools
182-
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz
183-
tar zxf libunwind-0.99-beta.tar.gz
184-
cd libunwind-0.99-beta
185-
./configure ${DEPS_CONFIG} >/dev/null
186-
make CFLAGS=-fPIC -j4 >/dev/null
187-
make CFLAGS=-fPIC install
188-
cd -
189-
fi
190-
191-
if [ -d "gperftools" ]
192-
then
193-
echo "gperftools exist"
194-
else
195-
196-
# gperftools (tcmalloc)
197-
# wget --no-check-certificate https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.1.tar.gz
198-
git clone --depth=1 https://github.com/00k/gperftools
199-
mv gperftools/gperftools-2.2.1.tar.gz .
200-
tar zxf gperftools-2.2.1.tar.gz
201-
cd gperftools-2.2.1
202-
./configure ${DEPS_CONFIG} CPPFLAGS=-I${DEPS_PREFIX}/include LDFLAGS=-L${DEPS_PREFIX}/lib >/dev/null
203-
make -j4 >/dev/null
204-
make install
205-
cd -
206-
fi
207-
208164
if [ -d "leveldb" ]
209165
then
210166
echo "leveldb exist"
@@ -239,37 +195,12 @@ else
239195
export PATH=${DEPS_PREFIX}/bin:$PATH
240196
export BOOST_PATH=${DEPS_PREFIX}/boost_1_57_0
241197
export PBRPC_PATH=${DEPS_PREFIX}/
242-
make -j4 ins >/dev/null && make -j4 install_sdk
198+
make -j4 ins >/dev/null && make -j4 install_sdk >/dev/null && make python >/dev/null
243199
mkdir -p output/bin && cp ins output/bin
200+
cp -rf output/python/* ../../optools/
244201
cd -
245202
fi
246203

247-
if [ -d "tera" ]
248-
then
249-
echo "tera exist"
250-
else
251-
252-
# tera
253-
git clone https://github.com/baidu/tera
254-
depends_file=depends.mk.template
255-
cd tera
256-
sed -i 's#^SOFA_PBRPC_PREFIX=.*#SOFA_PBRPC_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
257-
sed -i 's#^PROTOBUF_PREFIX=.*#PROTOBUF_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
258-
sed -i 's#^SNAPPY_PREFIX=.*#SNAPPY_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
259-
sed -i 's#^ZOOKEEPER_PREFIX=.*#ZOOKEEPER_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
260-
sed -i 's#^GFLAGS_PREFIX=.*#GFLAGS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
261-
sed -i 's#^GLOG_PREFIX=.*#GLOG_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
262-
sed -i 's#^GTEST_PREFIX=.*#GTEST_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
263-
sed -i 's#^GPERFTOOLS_PREFIX=.*#GPERFTOOLS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
264-
sed -i 's#^BOOST_INCDIR=.*#BOOST_INCDIR='${DEPS_PREFIX}'\/boost_1_57_0#' ${depends_file}
265-
sed -i 's#^INS_PREFIX=.*#INS_PREFIX='${DEPS_PREFIX}'#' ${depends_file}
266-
sed -e '$ c -lgtest_main -lgtest -lglog -lgflags -ltcmalloc_minimal -lunwind' ${depends_file} > depends.mk.new
267-
mv depends.mk.new depends.mk
268-
make -j8 >/dev/null
269-
cp -a build/lib/*.a ${DEPS_PREFIX}/lib
270-
cp -a build/include/*.h ${DEPS_PREFIX}/include
271-
cd -
272-
fi
273204

274205
if [ -d "mdt" ]
275206
then
@@ -282,16 +213,11 @@ else
282213
sed -i 's/^SOFA_PBRPC_PREFIX=.*/SOFA_PBRPC_PREFIX=..\/..\/thirdparty/' depends.mk
283214
sed -i 's/^PROTOBUF_PREFIX=.*/PROTOBUF_PREFIX=..\/..\/thirdparty/' depends.mk
284215
sed -i 's/^SNAPPY_PREFIX=.*/SNAPPY_PREFIX=..\/..\/thirdparty/' depends.mk
285-
sed -i 's/^ZOOKEEPER_PREFIX=.*/ZOOKEEPER_PREFIX=..\/..\/thirdparty/' depends.mk
286216
sed -i 's/^GFLAGS_PREFIX=.*/GFLAGS_PREFIX=..\/..\/thirdparty/' depends.mk
287217
sed -i 's/^GLOG_PREFIX=.*/GLOG_PREFIX=..\/..\/thirdparty/' depends.mk
288-
sed -i 's/^GTEST_PREFIX=.*/GTEST_PREFIX=..\/..\/thirdparty/' depends.mk
289-
sed -i 's/^GPERFTOOLS_PREFIX=.*/GPERFTOOLS_PREFIX=..\/..\/thirdparty/' depends.mk
290218
sed -i 's/^BOOST_INCDIR=.*/BOOST_INCDIR=..\/..\/thirdparty\/boost_1_57_0/' depends.mk
291-
sed -i 's/^INS_PREFIX=.*/INS_PREFIX=..\/..\/thirdparty/' depends.mk
292-
sed -i 's/^TERA_PREFIX=.*/TERA_PREFIX=..\/..\/thirdparty/' depends.mk
293-
sed -i '/-lgtest_main/c -lgtest_main -lgtest -lglog -lgflags -ltcmalloc_minimal -lunwind' depends.mk
294-
make -j8 >/dev/null
219+
sed -i '/-lgtest_main/c -lglog -lgflags' depends.mk
220+
make -j8 libftrace.a >/dev/null
295221
cp src/ftrace/collector/logger.h ${DEPS_PREFIX}/include
296222
cp libftrace.a ${DEPS_PREFIX}/lib
297223
cd -

optools/galaxy

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,90 @@
88
#
99
# processname: galaxy
1010

11-
PROD_ADDR=ftp://xxxxxx/tmp/galaxy.tar.gz
11+
PROD_ADDR=xxxxx
1212
. /etc/rc.d/init.d/functions
1313
AGENT_IP=`hostname -i`
1414
AGENT_HOME=/home/galaxy/agent
1515
RETVAL=0
16+
17+
netCards=$(/sbin/ifconfig | awk '/Ethernet/{a=$0; getline; b=$0; print a,b}' | grep "inet addr" | awk '{print $1}')
18+
19+
readd_mod() {
20+
local DEV=$1
21+
local IP=$(cat /etc/sysconfig/network-scripts/ifcfg-${DEV} | grep IPADDR | cut -d "=" -f 2)
22+
local GATEWAY=$(ip route | grep ${DEV} | grep via | awk '{print $3}' | head -1)
23+
if ! grep "GATEWAY" /etc/sysconfig/network-scripts/ifcfg-${DEV} > /dev/null; then
24+
echo "GATEWAY=${GATEWAY}" >> /etc/sysconfig/network-scripts/ifcfg-${DEV}
25+
fi
26+
local ETH=${DEV}
27+
local driver=`ethtool -i ${ETH} | grep driver | awk '{print $2}'`
28+
29+
if [[ ${driver} == "igb" ]] && ! grep "RSS=8,8" /etc/modprobe.conf | grep "igb" &>/dev/null ;then
30+
sed -i '/options igb.*/d' /etc/modprobe.conf
31+
sed -i '/^$/d' /etc/modprobe.conf
32+
echo "options igb RSS=8,8" >> /etc/modprobe.conf
33+
34+
rmmod igb && modprobe igb && /etc/init.d/network start && /etc/rc.local
35+
fi
36+
}
37+
38+
set_affinity() {
39+
MASK=$((1<<$VEC))
40+
printf "%s mask=%X for /proc/irq/%d/smp_affinity\n" $DEV $MASK $IRQ 2>/dev/null
41+
printf "%X" $MASK > /proc/irq/$IRQ/smp_affinity 2>/dev/null
42+
#echo $DEV mask=$MASK for /proc/irq/$IRQ/smp_affinity
43+
#echo $MASK > /proc/irq/$IRQ/smp_affinity
44+
}
45+
46+
if [[ ${#netCards} -eq 0 ]]; then
47+
exit 1
48+
fi
49+
# check for irqbalance running
50+
IRQBALANCE_ON=`ps ax | grep -v grep | grep -q irqbalance; echo $?`
51+
if [ "$IRQBALANCE_ON" == "0" ] ; then
52+
echo " WARNING: irqbalance is running and will"
53+
echo " likely override this script's affinitization."
54+
echo " Please stop the irqbalance service and/or execute"
55+
echo " 'killall irqbalance'"
56+
fi
57+
58+
for DEV in $(echo ${netCards}); do
59+
#
60+
# Set up the desired devices.
61+
#
62+
eth_interrputs=$(cat /proc/interrupts | grep "${DEV}" | wc -l )
63+
if [[ ${eth_interrputs} -le 2 ]]; then
64+
readd_mod ${DEV}
65+
fi
66+
for DIR in rx tx TxRx fp ''; do
67+
MAX=`grep $DEV-$DIR /proc/interrupts | wc -l`
68+
if [ "$MAX" == "0" ] ; then
69+
MAX=`egrep -i "$DEV:.*$DIR" /proc/interrupts | wc -l`
70+
fi
71+
if [ "$MAX" == "0" ] ; then
72+
echo no $DIR vectors found on $DEV
73+
continue
74+
#exit 1
75+
fi
76+
for VEC in `seq 0 1 $MAX`; do
77+
if [ "x$DIR" = "x" ]; then
78+
IRQ=`cat /proc/interrupts | grep -i $DEV-$DIR$VEC"$" | cut -d: -f1 | sed "s/ //g"`
79+
else
80+
IRQ=`cat /proc/interrupts | grep -i $DEV-$DIR-$VEC"$" | cut -d: -f1 | sed "s/ //g"`
81+
fi
82+
83+
if [ -n "$IRQ" ]; then
84+
set_affinity
85+
else
86+
IRQ=`cat /proc/interrupts | egrep -i $DEV:v$VEC-$DIR"$" | cut -d: -f1 | sed "s/ //g"`
87+
if [ -n "$IRQ" ]; then
88+
set_affinity
89+
fi
90+
fi
91+
done
92+
done
93+
done
94+
1695
init() {
1796
// config core dump dir
1897
mkdir -p /home/disk2/coresave
@@ -34,6 +113,7 @@ init() {
34113
mkdir -p $AGENT_HOME/gc_dir
35114
mkdir -p $AGENT_HOME/log
36115
echo 0 > /proc/sys/kernel/printk
116+
ulimit -n 65536
37117
}
38118

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

53134
start() {

optools/io_dump.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -*- coding:utf-8 -*-
2+
import os
3+
import time
4+
import datetime
5+
import sys
6+
# dump process_name io usage on device
7+
class IoDump(object):
8+
def __init__(self, process_name=[], top_size = 10):
9+
self.process_data = {}
10+
self.process_name = process_name
11+
12+
def readable(self, num):
13+
for unit in ['','K','M','G','T','P','E','Z']:
14+
if abs(num) < 1024.0:
15+
return "%3.1f%s"%(num, unit)
16+
num /= 1024.0
17+
return "%.1f%s" % (num, 'Y')
18+
19+
def collect(self):
20+
entries = os.listdir("/proc")
21+
statistics = {}
22+
for entry in entries:
23+
try:
24+
pid = int(entry)
25+
exe_path = os.path.realpath("/proc/%d/exe"%pid)
26+
offset = exe_path.rfind("/")
27+
bin = exe_path[offset+1:]
28+
if bin in self.process_name:
29+
status, read_bytes_ps, write_bytes_ps = self.calc_process(pid)
30+
if not status:
31+
continue
32+
stat = statistics.get(bin,{"read_bytes_ps":0, "write_bytes_ps":0})
33+
stat["read_bytes_ps"] += read_bytes_ps
34+
stat["write_bytes_ps"] += write_bytes_ps
35+
statistics[bin] = stat
36+
except Exception,e:
37+
pass
38+
stat_array = []
39+
for key in statistics:
40+
item = {"name":key}
41+
item.update(statistics[key])
42+
stat_array.append(item)
43+
sorted_array = sorted(stat_array, key=lambda item : item["read_bytes_ps"], reverse = True)
44+
output = []
45+
now = time.time()
46+
output.append("-------------------------------------------------")
47+
output.append(datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S'))
48+
for item in sorted_array:
49+
output.append("%s read:%s/s write:%s/s"%(item["name"], self.readable(item["read_bytes_ps"]),
50+
self.readable(item["write_bytes_ps"])))
51+
print "\n".join(output)
52+
53+
def calc_process(self, pid):
54+
data = {'read':0,
55+
'write':0,
56+
'cancell':0}
57+
fd = open("/proc/%d/io"%pid, "r")
58+
for line in fd.readlines():
59+
parts = line.replace("\n","").split(":")
60+
if parts[0] == "read_bytes":
61+
data["read"] = int(parts[1][1:])
62+
elif parts[0] == "write_bytes":
63+
data["write"] = int(parts[1][1:])
64+
elif parts[0] == "cancelled_write_bytes":
65+
data["cancell"] = int(parts[1][1:])
66+
fd.close()
67+
if pid in self.process_data:
68+
old_data = self.process_data[pid]
69+
read_bytes_ps = data["read"] - old_data["read"]
70+
write_bytes_ps = (data["write"] - data["cancell"]) - (old_data["write"] - old_data["cancell"])
71+
self.process_data[pid] = data
72+
return True, read_bytes_ps, write_bytes_ps
73+
else:
74+
self.process_data[pid] = data
75+
return False, 0, 0
76+
77+
def main():
78+
dump = IoDump(sys.argv)
79+
while True:
80+
dump.collect()
81+
time.sleep(1)
82+
83+
if __name__ == "__main__":
84+
main()

0 commit comments

Comments
 (0)