先clone下来SRS的代码,国内推荐oschina阿里云的镜像:
mkdir -p ~/git/ && cd ~/git && git clone [email protected]:winlinvip/srs.oschina.git
设置好java环境,解压hadoop 2.7,添加到PATH,也就是能执行java和hadoop之后,就可以统计SRS的代码了,环境变量设置:
# by winlin export JAVA_HOME=/usr/local/jdk export JRE_HOME=$JAVA_HOME/jre export HADOOP_HOME=/usr/local/hadoop export SCALA_HOME=/usr/local/scala export SPARK_HOME=/usr/local/spark export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$SCALA_HOME/bin:$SPARK_HOME/bin export CLASS_PATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
cd /usr/local/hadoop && rm -rf input output && (mkdir input && cd input && files=`find /home/winlin/git/srs/trunk/src/ -name "*.*pp"|grep -v utest`; for file in $files; do cp $file .; done) && duration=`time hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount input/ output 2>/dev/null` && (cd output && cat part-r-00000 |awk '{print $2,$1}'|sort -n) && echo "=================" && echo $duration && rm -rf input output
配合linux的sort,就可以得到频率最高的单词。
1012 #include 1015 and 1089 in 1103 ret=%d", 1116 ret); 1160 ((ret 1194 ret 1207 ERROR_SUCCESS) 1341 is 1516 for 1538 /** 1725 of 1836 */ 1860 virtual 1925 != 2460 ret; 2876 to 3740 int 4167 if 4300 return 4844 * 4940 // 5265 the 6917 } 7240 { 9136 =
1. SRS的函数才1860个,所有的SRS的函数都是virtual开头,即使是private。
2. 注释真不少,*/和//占了很多。
3. C系列的语言,{}很多,说明代码风格比较统一。
使用Spark统计SRS的命令:
cd /usr/local/spark && rm -f srs.txt && files=`find /home/winlin/git/srs/trunk/src/ -name "*.*pp"|grep -v utest`; for file in $files; do cat $file>>srs.txt; done && duration=`time (spark-submit /usr/local/spark/examples/src/main/python/wordcount.py srs.txt >result.txt 2>/dev/null) 2>&1` && cat result.txt|awk '{print $2,$1}'|sort -n && echo "=========" && echo $duration && rm -f result.txt
1012 #include: 1015 and: 1089 in: 1103 ret=%d",: 1116 ret);: 1160 ((ret: 1194 ret: 1207 ERROR_SUCCESS): 1341 is: 1516 for: 1538 /**: 1725 of: 1836 */: 1860 virtual: 1925 !=: 2460 ret;: 2876 to: 3740 int: 4167 if: 4299 return: 4844 *: 4940 //: 5265 the: 6917 }: 7240 {: 9136 =: 314558 :
real 0m13.488s user 0m21.393s sys 0m5.310s
real 0m15.105s user 0m17.929s sys 0m5.538s