Disable IPv6 to solve DualMode issue
[platform/core/dotnet/launcher.git] / tools / Performance / performance_test.sh
1 #!/bin/bash
2
3 STREAM_LOG_FILE=stream.log
4 DATE=$(date +%Y%m%d_%H%M)
5 RESULT_LOG_FILE='result/result_'$DATE'.log'
6
7 WAIT_FOR_LAUNCH=10
8 WAIT_FOR_LONG_LAUNCH=30
9 WAIT_FOR_KILL=5
10
11 PKG_IDS=()
12 APP_IDS=()
13
14 LONG_LAUNCHING_APP=(
15     "org.tizen.example.SNSUI.Tizen",
16 )
17
18 initialize ()
19 {
20     echo ""
21     echo "[>] Initialize for Performance Test"
22     if [ $(sdb get-state 2>/dev/null | grep -c "device") -eq 0 ];
23     then
24         echo ""
25         echo "[!] device is not connected - cannot execute"
26         echo ""
27         exit 0
28     fi
29
30     if [ $(dpkg-query -W -f='${Status}' inotify-tools 2>/dev/null | grep -c "ok installed") -eq 0 ];
31     then
32         echo ""
33         echo "[!] inotify-tools package should install"
34         echo "[!] starting install inotify-tools .. "
35         sudo apt-get install inotify-tools
36         if [ $(dpkg-query -W -f='${Status}' inotify-tools 2>/dev/null | grep -c "ok installed") -eq 0 ];
37         then
38             echo ""
39             echo "[!] install inotify-tools fail - cannot execute"
40             echo ""
41             exit 0
42         fi
43         echo 32768 | sudo tee /proc/sys/fs/inotify/max_user_watches
44         echo fs.inotify.max_user_watches=32768 | sudo tee -a /etc/sysctl.conf
45         sudo sysctl -p
46     fi
47     sdb root on
48     sdb shell "devicectl display stop">/dev/null 2>&1
49     mkdir result>/dev/null 2>&1
50     rm $STREAM_LOG_FILE>/dev/null 2>&1
51     touch $STREAM_LOG_FILE
52 }
53
54 install_tpk ()
55 {
56 #install tpk packages
57     echo "[>] Installing package in tpk directory"
58     TPKS=($(ls tpk | grep .tpk))
59
60
61     for item in ${TPKS[*]}
62     do
63         INSTALL_MSG=$(sdb install tpk/$item | grep start)
64         INSTALL_MSG=$(echo $INSTALL_MSG | sed "s/\[/ /g")
65         INSTALL_MSG=$(echo $INSTALL_MSG | sed "s/\]/ /g")
66         PKG_IDS+=($(echo $INSTALL_MSG | awk '{print $7}' | tr -d '\r'))
67         echo " [>] ($(echo $INSTALL_MSG | awk '{print $7}')) installs complete"
68     done
69 }
70
71 get_current_tpk_apps ()
72 {
73     echo "[>] Get application list in device"
74 #    PKG_IDS+=$(
75 #        sdb shell "su - owner -c 'pkgcmd -l | grep tpk'" |  while read line
76 #        do
77 #            APP_LIST_ENTITY=$line
78 #            APP_LIST_ENTITY=$(echo $APP_LIST_ENTITY | sed "s/\[/ /g")
79 #            APP_LIST_ENTITY=$(echo $APP_LIST_ENTITY | sed "s/\]/ /g")
80 #            APP_OWNER=($(echo $APP_LIST_ENTITY | awk '{print $1}'))
81 #            if [[ $APP_OWNER == 'user' ]]
82 #            then
83 #                echo $APP_LIST_ENTITY | awk '{print $6}'
84 #            fi
85 #        done | sort | tr -d '\r'
86 #    )
87 #In 3.0 mobile / wearable, appfw install all of application to global application
88     PKG_IDS+=$(
89         sdb shell "su - owner -c 'ls -al /opt/usr/globalapps/ | grep tizenglobalapp'" |  while read line
90         do
91             APP_LIST_ENTITY=$line
92             APP_GLOBAL=($(echo $APP_LIST_ENTITY | awk '{print $3}'))
93             if [[ $APP_GLOBAL == 'tizenglobalapp' ]]
94             then
95                 echo $APP_LIST_ENTITY | awk '{print $9}'
96             fi
97         done | sort | tr -d '\r'
98     )
99 }
100
101 make_appid_list ()
102 {
103 #get app ids
104     echo "[>] Get application id that installed"
105     for item in ${PKG_IDS[*]}
106     do
107         APP_LIST_MSG=$(sdb shell "su - owner -c 'pkginfo --pkg $item' | grep mainappid" | tail -1)
108         APP_IDS+=($(echo $APP_LIST_MSG | awk '{print $3}' | tr -d '\r'))
109     done
110 }
111
112 initialize_first_launch ()
113 {
114     if [[ -z ${APP_IDS[0]} ]]; then
115         echo ""
116         echo "[!] No tpk Packages for test"
117         echo "[!] Copy tpk files in [./tpk] directory"
118         echo ""
119         exit 0
120     fi
121     echo "[>] Initial launch an application"
122     APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -s ${APP_IDS[0]}'")
123     sleep 10
124     APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -t ${APP_IDS[0]}'")
125     sleep 5
126 }
127
128 execute_time_stamp_auto ()
129 {
130     echo ""
131     echo "[>] Start performance test that applciation launching time"
132     echo ""
133 #execute dlogstreamer
134     sdb shell "dlogutil -c"
135     sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE &
136     DLOG_STREAMER_PID=$!
137 #execute timestamp
138     /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
139     TIMESTAMP_PID=$!
140 }
141
142 execute_time_stamp_auto_memory ()
143 {
144     echo ""
145     echo "[>] Start performance test that applciation launching memory"
146     echo ""
147     sdb shell "dlogutil -c"
148     sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE &
149     DLOG_STREAMER_PID=$!
150 #execute timestamp
151     /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
152     TIMESTAMP_PID=$!
153 #execute memorystamp
154     /bin/bash ./memorystamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
155     MEMORYSTAMP_PID=$!
156 }
157
158 execute_time_stamp_manual ()
159 {
160 #execute dlogstreamer
161     echo ""
162     echo "[>] Start performance test that applciation launching time"
163     echo ""
164     rm $STREAM_LOG_FILE
165     touch $STREAM_LOG_FILE
166     sdb shell "dlogutil -c"
167     sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE &
168     DLOG_STREAMER_PID=$!
169 #execute timestamp
170     /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE
171     TIMESTAMP_PID=$!
172     wait $TIMESTAMP_PID
173 }
174
175 execute_time_stamp_manual_trace ()
176 {
177 #execute dlogstreamer
178     echo ""
179     echo "[>] Start performance test that applciation launching time"
180     echo ""
181     rm $STREAM_LOG_FILE
182     touch $STREAM_LOG_FILE
183     sdb shell "dlogutil -c"
184     sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE &
185     DLOG_STREAMER_PID=$!
186 #execute timestamp
187     /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
188     TIMESTAMP_PID=$!
189 #execute ttrace
190     ~/tizen-sdk/tools/ttrace/ttrace.py -b 20480 -t 10 -o result/trace.html idle app view am &
191     TTRACE_PID=$!
192     wait $TTRACE_PID
193     rm result/*.ftrace
194     rm result/*.raw
195 }
196
197 execute_time_stamp_manual_memory ()
198 {
199     echo ""
200     echo "[>] Start performance test that applciation launching memory"
201     echo ""
202     rm $STREAM_LOG_FILE
203     touch $STREAM_LOG_FILE
204     sdb shell "dlogutil -c"
205     sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE &
206     DLOG_STREAMER_PID=$!
207 #execute timestamp
208     /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
209     TIMESTAMP_PID=$!
210 #execute memorystamp
211     /bin/bash ./memorystamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE &
212     MEMORYSTAMP_PID=$!
213     wait $MEMORYSTAMP_PID
214 }
215
216 execute_all_app ()
217 {
218 #execute each apps
219     for item in ${APP_IDS[*]}
220     do
221         APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -s $item'")
222         if [[ "${LONG_LAUNCHING_APP[@]}" =~ "${item}" ]]; then
223             sleep $WAIT_FOR_LONG_LAUNCH
224         else
225             sleep $WAIT_FOR_LAUNCH
226         fi
227         APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -t $item'")
228         sleep $WAIT_FOR_KILL
229     done
230 }
231
232 execute_all_app_trace ()
233 {
234 #execute each apps
235     for item in ${APP_IDS[*]}
236     do
237         ~/tizen-sdk/tools/ttrace/ttrace.py -b 20480 -t 13 -o result/${item}.html idle app view am & > /dev/null 2>&1
238         TTRACE_PID=$!
239         sleep 1
240         APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -s $item'")
241         if [[ "${LONG_LAUNCHING_APP[@]}" =~ "${item}" ]]; then
242             sleep $WAIT_FOR_LONG_LAUNCH
243         else
244         sleep $WAIT_FOR_LAUNCH
245         fi
246         APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -t $item'")
247         sleep $WAIT_FOR_KILL
248         sleep 4
249     done
250     rm result/*.ftrace
251     rm result/*.raw
252 }
253
254 execute_all_app_memory ()
255 {
256     sleep $WAIT_FOR_LAUNCH
257 #execute each apps
258     for item in ${APP_IDS[*]}
259     do
260         if [[ "${LONG_LAUNCHING_APP[@]}" =~ "${item}" ]]; then
261             echo ""
262         else
263             APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -s $item'")
264             sleep $WAIT_FOR_LONG_LAUNCH
265             #APP_LIST_MSG=$(sdb shell "su - owner -c 'app_launcher -t $item'")
266             sleep $WAIT_FOR_KILL
267         fi
268         sleep $WAIT_FOR_LONG_LAUNCH
269     done
270 }
271
272 finalize ()
273 {
274     echo ""
275     echo "[>] Result"
276     echo ""
277     cat $RESULT_LOG_FILE
278     echo ""
279     echo "[>] Result file : [ $RESULT_LOG_FILE ]"
280 }
281
282 destory ()
283 {
284     echo ""
285     kill -9 $DLOG_STREAMER_PID>/dev/null 2>&1
286     kill -9 $TIMESTAMP_PID>/dev/null 2>&1
287     kill -9 $TTRACE_PID>/dev/null 2>&1
288     kill -9 $MEMORYSTAMP_PID>/dev/null 2>&1
289     rm $STREAM_LOG_FILE>/dev/null 2>&1
290     sdb shell "devicectl display start">/dev/null 2>&1
291     echo "[>] Finalize for Performance Test"
292     echo ""
293 }
294
295 help ()
296 {
297     echo ""
298     echo "[!] usage   : <script> [option]"
299     echo "    options : -a --auto             full automatic launching time test"
300     echo "            : (suboption for auto) -s --skip-install  skip install tpk (execute tpk app in device)"
301     echo "            : -m --manual           execute application manually"
302     echo "            : -am --auto-memory     full automatic launching memory test"
303     echo "            : -mm --manual-memory   execute application manually with memory test"
304     echo "            : -at --auto-ttrace     full automatic launching time test with ttrace"
305     echo "            : -mt --manual-ttrace   execute application manually with ttrace"
306     echo "example : ./performance_test.sh --auto"
307     echo ""
308 }
309
310
311 trap "destory" 0
312
313 if [[ $1 == '-a' ]] || [[ $1 == "--auto" ]]
314 then
315     echo ""
316     echo "[>] Start with AUTO mode"
317     initialize
318     if [[ $2 == "-s" ]] || [[ $2 == "--skip-install" ]]
319     then
320         get_current_tpk_apps
321     else
322         install_tpk
323     fi
324     make_appid_list
325     initialize_first_launch
326     execute_time_stamp_auto
327     execute_all_app
328     finalize
329 elif [[ $1 == "-m" ]] || [[ $1 == "--manual" ]]
330 then
331     echo ""
332     echo "[>] Start with MANUAL mode"
333     echo "[>] execute installed application in your device"
334     initialize
335     execute_time_stamp_manual
336     finalize
337 elif [[ $1 == "-am" ]] || [[ $1 == "--auto-memory" ]]
338 then
339     echo ""
340     echo "[>] Launching Memory Profiling with AUTO mode"
341     initialize
342     if [[ $2 == "-s" ]] || [[ $2 == "--skip-install" ]]
343     then
344         get_current_tpk_apps
345     else
346         install_tpk
347     fi
348     make_appid_list
349     initialize_first_launch
350     execute_time_stamp_auto_memory
351     execute_all_app_memory
352     finalize
353 elif [[ $1 == "-mm" ]] || [[ $1 == "--manual-memory" ]]
354 then
355     echo ""
356     echo "[>] Launching Memory Profiling with MANUAL mode"
357     initialize
358     execute_time_stamp_manual_memory
359     finalize
360 elif [[ $1 == "-at" ]] || [[ $1 == "--auto-ttrace" ]]
361 then
362     echo ""
363     echo "[>] Start with T-trace Auto mode"
364     initialize
365     if [[ $2 == "-s" ]] || [[ $2 == "--skip-install" ]]
366     then
367         get_current_tpk_apps
368     else
369         install_tpk
370     fi
371     make_appid_list
372     initialize_first_launch
373     execute_time_stamp_auto
374     execute_all_app_trace
375     finalize
376 elif [[ $1 == "-mt" ]] || [[ $1 == "--manual-ttrace" ]]
377 then
378     echo ""
379     echo "[>] Start with T-trace Manual mode"
380     echo "[>] execute installed application in your device"
381     initialize
382     execute_time_stamp_manual_trace
383     finalize
384 else
385     help
386 fi