-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxlog
More file actions
executable file
·245 lines (214 loc) · 4.71 KB
/
Copy pathxlog
File metadata and controls
executable file
·245 lines (214 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
#############################################
# author:fang
# version : v1.0
# name : xlog
# dispcripe: uses of log
# CopyRight@fangyunjiang[42550564@qq.com]
#############################################
source ~/command/common
function cal_process_time()
{
local list len i sum av t
list=(`sed '/cost time in '$1' process/!d' $2|sed 's/^.*process \([0-9]\+\).*/\1/'`)
len=${#list[@]}
[ $len -eq 0 ]&&return
sum=0
for ((i=0; i<len; i++));do
((sum+=list[i]))
done
av=`echo "scale=2;$sum/$len/1000"|bc`
echo "cost time in $1 for $len times:"
echo "average is $av ms"
}
function cal_average_interval()
{
local list len i sum av t
list=(`sed '/cost time in '$1' interval/!d' $2|sed '1d'|sed 's/^.*interval \([0-9]\+\).*/\1/'`)
len=${#list[@]}
[ $len -eq 0 ]&&return
sum=0
for ((i=0; i<len; i++));do
((sum+=list[i]))
done
av=`echo "scale=2;$sum/$len/1000"|bc`
echo "the interval in $1 for $len times:"
echo "average is $av ms"
}
function cal_average_size()
{
local list len i sum av bps
list=(`sed '/send rtp/!d;s/^.*length=\([0-9]\+\).*/\1/' $1`)
len=${#list[@]}
[ $len -eq 0 ]&&return
sum=0
for ((i=0; i<len; i++));do
((sum+=list[i]))
done
av=`echo "scale=2;$sum/$len"|bc`
bps=`echo "scale=2;$av*15/1024"|bc`
echo "send rtp len for $len times:"
echo "average is $av"
echo "bps is $bps K/s"
}
function cal_all_time()
{
local i
for((i=0; i<$2;i++));do
cal_process_time $i $1
done
}
function cal_all_interval()
{
local i
for((i=0; i<$2;i++));do
cal_average_interval $i $1
done
}
function cal_time_and_size()
{
cal_all_time $1 4
cal_average_size $1
}
function edit_with_vi()
{
local file
file=$1
if [ $_edit -eq 1 ];then
vi "$file"
if [ $_remove -eq 1 ];then
rm "$file"
fi
fi
}
function read_pbpaste_data_to_file()
{
local file
file=$1
[ $_append -eq 0 ] && __backup_file "$file"
[ -z "$file" ]&&return
if __mac;then
if [ $_append -eq 0 ];then
pbpaste > "$file"
else
echo>>"$file"
pbpaste >> "$file"
fi
elif __windows;then
if [ $_append -eq 0 ];then
cat /dev/clipboard > "$file"
else
echo>>"$file"
cat /dev/clipboard >> "$file"
fi
fi
edit_with_vi "$file"
#echo "have put data to $file"
}
function log_for_android()
{
local file
#__backup_file "$file"
file=$1
[ -f $file ] && rm "$file"
trap "edit_with_vi '$file';exit" INT
adb logcat -c
if [ -z "$_tag" ];then
adb logcat|tee "$file"
else
adb logcat -s "$_tag"|tee "$file"
fi
}
function show_diff_n()
{
local files list1 list2 list3 list4 len num
files=(`echo $1|tr ':' ' '|tr -s ' '`)
len=${#files[@]}
for ((i=0; i<len; i++));do
[ -f "${files[i]}" ] || return
done
for ((i=0; i<len; i++));do
eval `awk -v FS=";;;;" '{print "list'$i'["NR-1"]=\""$1"\""}' ${files[i]}`
done
num=${#list0[@]}
for((i=0;i<num; i++));do
for((j=0;j<len;j++));do
eval "str=\${list$j[i]}"
printf "%-35s" "$str"
done
printf "\n"
done
}
function show_diff_2()
{
local file1 file2 list1 list2 len i
file1=${1%%:*}
file2=${1##*:}
[ -f "$file1" -a -f "$file2" ] || return
[ "$file1" = "$file2" ] && return
eval `awk -v FS=";;;;" '{print "list1["NR-1"]=\""$1"\""}' $file1`
eval `awk -v FS=";;;;" '{print "list2["NR-1"]=\""$1"\""}' $file2`
len=${#list1[@]}
for((i=0;i<len;i++));do
printf "%-40s%s\n" "${list1[i]}" "${list2[i]}"
done
}
function show_help()
{
echo "Usage:xlog v1.0: only used by longmaster video test"
echo " xlog [-f file][-n times][-d diff][-t][-s][-i][-r][-a][-v][-m][-h]"
echo " -f file:set log file"
echo " -n file:set cal times"
echo " -t:cal average time"
echo " -s:cal average size"
echo " -i:cal average interval"
echo " -r:read pbpaste data to file"
echo " -a:log for android"
echo " -x:连接逍遥模拟器"
echo " -v:edit with vi after paste[affect -r|-a]"
echo " -m:rm after edit[affect -r|-a -v]"
echo " -g tag:log for android's tag[affect -a]"
echo " -d diff:show file diff[like -d 1.txt:2.txt:3.txt]"
echo
echo " CopyRight(c)yunjiang.fang@longmaster.com.cn"
}
_file="1.txt"
_times=1
_oper=0
_edit=0
_remove=0
_append=0
_tag=""
function main()
{
while getopts :f:n:d:g:tsiraxvmph opt;do
_oper_right=1
case $opt in
f)_file="$OPTARG";;
n)_times="$OPTARG";;
t)_oper=1;;
s)_oper=2;;
i)_oper=3;;
r)_oper=4;;
a)_oper=5;;
x)adb connect 127.0.0.1:21503;exit;;
v)_edit=1;;
m)_remove=1;;
p)_append=1;;
d)_oper=6;_diff="$OPTARG";;
g)_tag="$OPTARG";;
h)show_help;exit;;
*)show_help;exit;;
esac
done
case $_oper in
0)cal_time_and_size "$_file";;
1)cal_all_time "$_file" "$_times";;
2)cal_average_size "$_file";;
3)cal_all_interval "$_file" "$_times";;
4)read_pbpaste_data_to_file "$_file";;
5)log_for_android "$_file";;
6)show_diff_n "$_diff";;
esac
}
main "$@"