# 1. git clone tidb or tikv
# 1.1 git clone https://github.com/tikv/tikv.git
# 1.2 git clone https://github.com/pingcap/tidb.git
# 2. copy bisect.sh to the repo folder and change the bisect.sh corespondingly
# 2.1 choose tidb or tikv command
# 2.2 change the bench_type/bench_sub_type/thread, threshhold
# 3 创建 testbed，把.env 和 kubeconfig.yml 文件拷贝到 /home/perfdata/endless/testcase/perftest
# 需要使用生产的 rms 地址, 
# 3.1 创建 bestbed： tcctl testbed create -f testbed-tiflash.yaml -r http://rms.pingcap.net:30007
# 3.2 获取 kubeconfig.yml 和 .env 文件：tcctl testbed get benchbot-amd64-xl-tpcds-tps-1021162-1-683 -r http://rms.pingcap.net:30007
# 4. run below under repor
# git bisect reset
# git bisect start
# git bisect bad c645f6beaf90d2c87f790e8d9ac6446ae72935c3
# git bisect good 99b34363cda1bd394ae689802655e9d9cf76d7fb
# git bisect run ./bisect.sh
#!/bin/sh
cd /home/perfdata/tikv

commit=`git rev-parse HEAD`
echo $commit

cd /home/perfdata/endless/testcase/perftest
# for tidb
#KUBECONFIG=./kubeconfig.yml ginkgo -focus bench -- perftest -bench-type ycsb -bench-sub-types "workloada" -versions nightly -threads 500 -dsn "perfdata:g2dmtGjk@tcp(172.16.4.36:3306)/perfdata?charset=utf8mb4&parseTime=True&loc=Local" -tidb-configs "{prepared-plan-cache.enabled: true}" -tidb-urls "http://fileserver.pingcap.net/download/builds/pingcap/tidb/pr/5ceb77c7c7ade8226c8928783b885673187f85ec/centos7/tidb-server.tar.gz" -benchmark-id 510003 -staging=false
KUBECONFIG=./kubeconfig.yml ginkgo -focus bench -- perftest -bench-type ycsb -bench-sub-types "workloada" -versions nightly -threads 500 -dsn "perfdata:g2dmtGjk@tcp(172.16.4.36:3306)/perfdata?charset=utf8mb4&parseTime=True&loc=Local" -tidb-configs "{prepared-plan-cache.enabled: true}" -tikv-urls "http://fileserver.pingcap.net/download/builds/pingcap/tikv/$commit/centos7/tikv-server.tar.gz" -benchmark-id 510003 -staging=false -bisect=true
cd /home/perfdata/tikv
result=$(mysql -h 172.16.4.36 -u perfdata -P 3306 -D perfdata  -pg2dmtGjk -N -se 'select (select tps from oltp_summary_logs where benchmark_id=510003 order by begin_at desc limit 1) < 18500')
echo result
echo $result
# git clean -df
git reset --hard HEAD
# rm -rf /tmp/tidb
echo $result
exit $result