1. 程式人生 > >shell 通過log分析效能

shell 通過log分析效能

指紋驗證時間統計比較麻煩,通過shell 實時監聽log,提取出其中重要的log對應的時間。

#! /bin/bash
echo "begin"

#test config
LOG_1="fingerprintd"
LOG_2="PowerManagerService"
LOG_3="DisplayPowerController"
LOG_4="mdss_dsi_panel_bklt_dcs"

time_0=""
time_1=""
time_2=""
time_3=""
time_4=""

#test config end

function get_test_config() 
{
    echo LOG_1_is: $LOG_1
    echo LOG_2_is: $LOG_2
    echo LOG_3_is: $LOG_3
    echo LOG_4_is: $LOG_4
}

function get_time_1(){
	
	#echo $var | grep --line-buffer fingerprintd | grep -v --line-buffer goodix | grep -v --line-buffer result | grep --line-buffer authenticate
	#echo $var | grep "fingerprintd,authenticate" | grep -v result
	echo $var | grep --line-buffer "fingerprintd: onAuthenticated" | grep -v --line-buffer "goodix"
	if [ $? -eq 0 ];then
		echo target_string_found++++++++++++++++++++++
		#echo var:$var
		time_1=$(echo $var | awk '{print $2}')
		#echo time_1:$time_1
#		break;
	# else
		# echo target_string_not_found
	fi
}
function get_time_2(){
	echo get_time_2_begin
	#echo $var | grep --line-buffer fingerprintd | grep -v-line-buffer goodix | grep -q --line-buffer authenticate
	echo $var | grep --line-buffer "Waking up from sleep"
	if [ $? -eq 0 ];then
		echo target_string_found++++++++++++++++++++++
		#echo var:$var
		time_2=$(echo $var | awk '{print $2}')
		#echo time_2:$time_2
#		break;
	#else
		#echo target_string_not_found
	fi
}
function get_time_3(){
	echo get_time_3_begin
	#echo $var | grep --line-buffer fingerprintd | grep -v-line-buffer goodix | grep -q --line-buffer authenticate
	echo $var | grep --line-buffer "Unblocked screen on after"
	if [ $? -eq 0 ];then
		echo target_string_found++++++++++++++++++++++
		#echo var:$var
		time_3=$(echo $var | awk '{print $2}')
		#echo time_3:$time_3
#		break;
	#else
		#echo target_string_not_found
	fi
}
function get_time_4(){
	echo get_time_4_begin
	#echo $var | grep --line-buffer fingerprintd | grep -v-line-buffer goodix | grep -q --line-buffer authenticate
	echo $var | grep --line-buffer "mdss_dsi_panel_bklt_dcs" | grep -v --line-buffer "level=0"
	if [ $? -eq 0 ];then
		echo target_string_found++++++++++++++++++++++
		#echo var:$var
		time_4=$(echo $var | awk '{print $2}')
		#echo time_4:$time_4
#		break;
	#else
		#echo target_string_not_found
	fi
}

function get_time_diff () {
	time1=`echo $1 | cut -d \. -f 2`
	time2=`echo $2 | cut -d \. -f 2`
	#echo $time1
	#echo $time2
	let time_diff=$time2-$time1
	if(( time_diff < 0 )) ; then 
		let time_diff=$time_diff+1000
	fi
	echo $time_diff
	#end_s=`echo $2 | cut -d \. -f 1`
}



get_test_config
adb shell logcat -c
LOG=$LOG_1
adb shell logcat | grep -E --line-buffer "fingerprintd|PowerManagerService|DisplayPowerController|mdss_dsi_panel_bklt_dcs" | while read var
do
	#echo var: $var
	 if [ -z "$time_1" ] ; then  # (-n 為非空)
		 echo $var | grep fingerprintd
		 echo time_1_is_empty
		 get_time_1 $var
		 continue
	 fi
	if [ -z "$time_2" ] ; then  # (-n 為非空)
		echo time_2_is_empty
		get_time_2 $var
		continue
	fi
	if [ -z "$time_3" ] ; then  # (-n 為非空)
		echo time_3_is_empty
		get_time_3 $var
		continue
	fi
	if [ -z "$time_4" ] ; then  # (-n 為非空)
		echo time_4_is_empty
		get_time_4 $var
		continue
	fi
	echo "test"
	echo $time_0

	echo $time_1
	echo $time_2
	echo $time_3
	echo $time_4
	
	echo time1_is:$(get_time_diff $time_1 $time_2)
	echo time2_is:$(get_time_diff $time_2 $time_3)
	echo time3_is:$(get_time_diff $time_3 $time_4)
	break ##???
	
	
	# case "$var" in 
		# $LOG_1)
			# echo "fingerprintd"
			# ;;
		# *)
			# echo "default_case"
			# ;;
	# esac
done

echo $time_0
echo $time_1
echo $time_2
echo $time_3
echo $time_4






問題: 過濾過程很慢