for all these features you'll need qt 5.14 · 2020. 1. 31. · how to profile a qt app on...

32
Testing & Profiling Qt on Android BogDan Vatră, Programmer at KDAB

Upload: others

Post on 12-Sep-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Testing&ProfilingQtonAndroid

BogDanVatră,ProgrammeratKDAB

Page 2: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

It'sallaboutQt5.14!

p.2

Forallthesefeaturesyou'llneedQt5.14!

Page 3: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

What'snewonQt5.14forAndroid?

What'snewonQt5.14forAndroid? p.3

What'snewonQt5.14forAndroid?

HowtouseQtTestonAndroid

HowtouseAVDsforrunningtests

HowtoprofileaQtapponAndroid

HowtouseaddresssanitizeronAndroid

Page 4: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Androidmultiarchbuildinonego

What'snewonQt5.14forAndroid? p.4

thebiggestfeatureaddedsinceImadetheQtonAndroidport

bydefaultallABIs(armeabi-v7a,arm64-v8,x86&x86_64)arebuilt

allowsyoutodecidewhichABI(s)youwanttobuildfor:

fromcommandline:$qmakeANDROID_ABIS="armeabi-v7aarm64-v8a"

Page 5: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

AndroidAppBundles(aab)

What'snewonQt5.14forAndroid? p.5

AndroidAppBundles(aab)isthenew(preferred)waytodistributeyourappsonGooglePlay

generatesandservesoptimizedAPKsforeachuser’sdeviceconfiguration

supportsdynamicfeaturemodules,viaplaycorelibrary

fromcommandline:$makeaab

Seehttps://developer.android.com/guide/app-bundleformoreinfo

Page 6: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

QtonAndroid5.14bringsmore

What'snewonQt5.14forAndroid? p.6

Sameasfor.aabyoucannowcreatean.apkfilefromcommandline:$makeapk

reworkedassetssupport:nowitlistsallthefilesandfolders.

loadQtpluginsdirectlyfromandroidlibsfolder

afewmore,checkhttps://www.kdab.com/qt-for-android-better-than-ever-before/formoreinfo

Page 7: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowtouseQtTestonAndroid

HowtouseQtTestonAndroid p.7

What'snewonQt5.14forAndroid?

HowtouseQtTestonAndroid

HowtouseAVDsforrunningtests

HowtoprofileaQtapponAndroid

HowtouseaddresssanitizeronAndroid

Page 8: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Howdoweruntestsondesktop?

HowtouseQtTestonAndroid p.8

howdoweruntestsondesktop?$makecheck

Page 9: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowdidweusedtoruntestsonAndroid?

HowtouseQtTestonAndroid p.9

usuallywedidn't

therewere(atleast?)twoscriptswhichusedtohelp

thesescriptsneverworkedproperly;(

Page 10: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Okayokay,but...

HowtouseQtTestonAndroid p.10

howshouldweruntestsonAndroid?$makecheck

Page 11: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

...

HowtouseQtTestonAndroid p.11

ThisishowwearegoingtoruntestsonAndroidusingQt5.14:$makecheck

Yes,nowit'sthateasy!

Page 12: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Areyoukidding?!?!

HowtouseQtTestonAndroid p.12

25minutesjusttellustorun:$makecheck

Page 13: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Holdyourhorses...:)

HowtouseQtTestonAndroid p.13

ThereareafewAndroidspecificthingswhichyoureallyneedtoknow:

sayhellotoandroidtestrunner

howtobuild&runyourtestsefficiently

howtorunyourtestsonaspecificdevice/emulator

howtopassargumentstoandroidtestrunner

howtopassargumentstoyourtest

Page 14: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Sayhellotoandroidtestrunner

HowtouseQtTestonAndroid p.14

androidtestrunnerisanewtooladdedtoQt5.14which:

createsthe.apk(ifit'snotalreadycreated)

installsthe.apk

runsthefirstActivityfromAndroidManifest.xmluse--activityparametertospecifyanotherone

checksthetestresults

ifspecified,pullsthetestsoutputfilesinthebuildfolder

Beaware:multipleinstanceswillwaitforeachothertocomplete!

Page 15: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Howtobuild&runyourtestsefficiently

HowtouseQtTestonAndroid p.15

buildonlytheneededABIs

buildyourAPKsinparallel!

runthetests

1 $qmakeANDROID_ABIS="x86_64"2 $make-j$(nproc)apk3 $makecheck

Page 16: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Howtorunyourtestsonaspecificdevice

HowtouseQtTestonAndroid p.16

UseANDROID_DEVICE_SERIALenvironmentvariable

$ANDROID_DEVICE_SERIAL="emulator-5554"makecheck

Page 17: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Howtopassargumentstoandroidtestrunner

HowtouseQtTestonAndroid p.17

UseTESTARGSvariabletopassparamstoandroidtestrunner

$makeTESTARGS="--timeout600"check

Page 18: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Howtopassargumentstoyourtest

HowtouseQtTestonAndroid p.18

useTESTARGSvariabletopassparamstoandroidtestrunner

use--paramtopassparamstothetestitself

$makeTESTARGS="---oout.xml,xml-oout.txt,txt-o-,tap-vs"check

--followingparamswillbepasseddirectlytotestapp

-oout.xml,xmlstoresthetestsresultsinout.xml

-oout.txt,txtstoresthetestsresultsinout.txt

-o-,tapprints(tostdout)tapformat

-vsenablesloggingofeverysignalemission

out.xmlandout.txtarepulledbyandroidtestrunnertotestbuildfolder

Page 19: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowtouseAVDsforrunningtests

HowtouseAVDsforrunningtests p.19

What'snewonQt5.14forAndroid?

HowtouseQtTestonAndroid

HowtouseAVDsforrunningtests

HowtoprofileaQtapponAndroid

HowtouseaddresssanitizeronAndroid

Page 20: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Plumbing

HowtouseAVDsforrunningtests p.20

usesdkmanagertoinstalltheemulatorandasystemimage$.../tools/bin/sdkmanager"emulator""system-images;android-29;default;x86_64"

useavdmanagertocreateanAVD$.../tools/bin/avdmanagercreateavd-ntest-k"system-images;android-29;default;x86_64"

choosecustomhardwareprofilechooseyesforhw.gpu.enabled

Page 21: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

StartanAVD

HowtouseAVDsforrunningtests p.21

useemulatortool$.../tools/emulator-avdtest

pass--no-windowparamtoemulatorfordockerhosts

Page 22: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowtoprofileaQtapponAndroid

HowtoprofileaQtapponAndroid p.22

What'snewonQt5.14forAndroid?

HowtouseQtTestonAndroid

HowtouseAVDsforrunningtests

HowtoprofileaQtapponAndroid

HowtouseaddresssanitizeronAndroid

Page 23: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowtouseGoogletoolstodoprofiling

HowtoprofileaQtapponAndroid p.23

Whatwearegoingtocover:

howtouseNDKtoolstodoC/C++profiling

WhatweareNOTgoingtocover:

howtodoQMLprofiling

howtodoJavaprofiling

Page 24: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Steps:

HowtoprofileaQtapponAndroid p.24

build&installtheapplicationusingQtCreator

useNDKtoolstostartprofilerecording

starttheapplication

stoptheapplication

generateareportusingtheNDKtools

Page 25: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Build&installtheapplication

HowtoprofileaQtapponAndroid p.25

buildyourQt5.14app(inreleasemode)usingQtCreatorpreQt5.14stripsthe.sofilesinyourandroid-builddir,whichwillcasethereportsteptonotshowyouanysymbols

doNOTsignyourapplicationsigningtheapplicationwillremovethedebugablemanifestflag.

installtheapplicationonthetargetdevice

Page 26: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

UseNDKtoolstostartprofilerecording

HowtoprofileaQtapponAndroid p.26

gotondk_folder/simpleperffolder

run./app_profiler.pytostartrecordingtheprofilingdata.Passatleast:--appparametertospecifythepackagename--libparametertospecifywhereisthebuilddirofyourapplicationformoreparameterspleasecheckhttps://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/android_application_profiling.md

$./app_profiler.py--apporg.qtproject.example.profile\--lib/home/bogdan/projects/build-profile-Release/android-build

Waitabituntiltheprofilerisreadyforrecording.

Page 27: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Start&stoptheapplication

HowtoprofileaQtapponAndroid p.27

starttheapplication

stoptheapplication

waituntil./app_profiler.pypullstherecordedprofiledata

Page 28: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

GenerateareportusingtheNDKtools

HowtoprofileaQtapponAndroid p.28

 Thereareacoupleofreportingtoolsinthatfolder,themostimportantonesare:

report.pyisawrapperoftheperfreportcommandonthehost#Reportcallgraph$./report.py-g

report_html.pygeneratesreport.htmlfilebasedontheprofilingdata#Generateinteractivechartstatistics,sampletableandflamegraphs,basedonperf.data$./report_html.py

Page 29: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Whattolookfor

HowtoprofileaQtapponAndroid p.29

qtMainLoopThreaisthethreadthatcallsyourmainfunctionusuallythisisthethreadthatyou'relookingfor

QtThread,QQmlThreadareQtinternalthreadsusedbyQmlEngine(Renderer)

RenderThread,Binder:XXXXXXareAndroidinternalthreads

unnamedthreadsusuallyareAndroidinternalthreads,butmightbeapplication'stoo

It'shighlyrecommendedtoexplicitlynameallyourapplicationthreads(useQThread::setObjectNamebeforeyoustartit)

Page 30: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

HowtouseaddresssanitizeronAndroid

HowtouseaddresssanitizeronAndroid p.30

What'snewonQt5.14forAndroid?

HowtouseQtTestonAndroid

HowtouseAVDsforrunningtests

HowtoprofileaQtapponAndroid

HowtouseaddresssanitizeronAndroid

Page 31: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

SamesupportasyoufindonGNU/Linux

HowtouseaddresssanitizeronAndroid p.31

firstclasssupportforaddresssanitizeronAndroidinQt5.14$qmakeCONFIG+=sanitizerCONFIG+=sanitize_address$makeapk

Yep,that'sallyouneedtodo!

Caveats:

itseemsitworksonlyonarm64-v8

itseemsitworksonlyonAndroid9+

itworkedformeonlyonGoogle'sPixel3

Page 32: For all these features you'll need Qt 5.14 · 2020. 1. 31. · How to profile a Qt app on Android p.25 build your Qt 5.14 app (in release mode) using QtCreator pre Qt 5.14 strips

Thankyou!

www.kdab.com

[email protected]