和几个项目经理朋友聊到项目工作量评估,公司内部对代码量,工程师的工作量通常有集成工具记录和衡量,但是如何比对其它业界的项目效率就成立讨论焦点,比如Google的Android工程师的代码出产效率,每个项目都花费了多少人力等等。受人之托,从Android的Git历史中研究以下这些问题,于是有了这个Bash脚本工具。
最新版本的github.com下载链接 https://github.com/neokidd/ghist2db
使用这个工具的前提是你有包含完整Git历史信息的Android的代码库,一般来说,是用"repo sync"来完成的下载的代码库,可以是全部project,也可以是部分的,比如说是用"repo sync framewors/base"这样单独sync的某些project。
repo for-all -c ghist2db.sh
输出结果是在代码库顶级目录下的一个ginfo.db文件,然后就可以用sqlite3来取得许多有趣的统计信息。比如在Android 4.0.4上,谷歌工程师commit的次数一共是155416,最多的工程师是三位大神是[email protected], [email protected] (Diane Hackbod, 大名鼎鼎的framework工程师), [email protected]。另外,如何假设每个谷歌工程师每周3次commit,那么Android 4.0.4共花费了51805 staff*week的工作量。#!/bin/bash
usage()
{
echo "ghist2db -- convert Android git history to sqlite db."
echo "Usage:"
echo "repo forall -c ghist2db.sh"
echo "or, run it separately for each repo project"
}
find_repo_top()
{
cwd=$1
while [ "$cwd" != "" -a "$cwd" != "~" ]; do
if [ -f $cwd/.repo/repo/main.py ]; then
repo_top=$cwd
return
fi
cwd=${cwd%\/*}
done
}
if [ "$repo_top"=="" ]; then
#echo "repo_top is empty, need to call find_repo_top"
find_repo_top `pwd`
fi
if [ "$repo_top" == "" ]; then
echo "seems you're not in a Android repo, please cd to Android repo!"
usage; exit 1
fi
repo_name=${repo_top##*\/}
#echo "repo_top: " $repo_top
#echo "repo_name: " $repo_name
proj=`pwd | awk -F"$repo_name"/ '{print $2}'`
echo "populating git info in $proj..."
# step 1: print git history logs in with "--pretty" format option, so that it's ready as sql sentences.
git log --pretty=format:"insert into googler_info (h, ae, ce, at, proj) values ('%h', '%ae', '%ce', '%at', '$proj');" [email protected] > googler_info.txt
# step 2: group all insert operations into one commit.
echo -e "begin;\n$(cat googler_info.txt)\ncommit;" > final_googler_info.sql
# step 3: add lines for creating table.
echo -e "create table if not exists googler_info(
_id integer primary key autoincrement,
h text not null,
ae text not null,
ce text not null,
at text not null,
proj text not null);
\n$(cat final_googler_info.sql)" > final_googler_info.sql
# step 4: create the db file
echo "inserting to db..."
sqlite3 "$repo_top"/ginfo.db < final_googler_info.sql
echo "done."
%at: author date, UNIX timestamp
3. step3中,在开头加入创建db的语句,注意需要用到if not exists。
4. step4中,用sqlite3来执行这些sql语句。
5. Android原生的repo for-all负责遍历每个project,并运行ghist2db.sh这个脚本。所有信息被插入同一个db。