Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging as a Skill

Debugging as a Skill

Himanshu Singh

August 08, 2024
Tweet

More Decks by Himanshu Singh

Other Decks in Technology

Transcript

  1. Debugging. - Need for debugging? - Understanding basic aspect for

    Debugging. - Leveraging Android Studio for our use case. - Debugging Compose Code. @hi_man_shoe
  2. Debugging 101. fun testForPrintln() { val loggedInUser = getUser() println(loggedInUser)

    } fun testForPrintln() { val loggedInUser = getUser() println(loggedInUser) } @hi_man_shoe
  3. Debugging 101. fun testForPrintln() { val loggedInUser = getUser() println(loggedInUser)

    } fun testForPrintln() { val loggedInUser = getUser() println(loggedInUser) } Output @hi_man_shoe
  4. Debugging 102. fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString())

    } fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString()) } Output
  5. Debugging 102. fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString())

    } fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString()) }
  6. Debugging 102. fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString())

    } fun testForLogger() { val loggedInUser = getUser() Log.d(TAG,loggedInUser.toString()) }
  7. Types. - Debug (Log.e) - Verbose (Log.v) - Info (Log.i)

    - Warn (Log.w) - Error (Log.e) - WTF! (Log.wtf) : What a Terrible Failure @hi_man_shoe
  8. Android Debugger : 201. - Debug the data loading/sequence in

    App - Can select the point to specifically check - Verify and move on! @hi_man_shoe
  9. Profiler : 202. - To improve performance issues on your

    app. - Helps us identify the issues. - Can help in CPU, memory, graphics, network, or the device battery. - Is natively available in Android Studio out of box! @hi_man_shoe
  10. UI Debugging : 501. - Help us build performant UI

    - Let us understanding places to improve/fix - Build global UI for 1000s of Phone and share best user experience. @hi_man_shoe
  11. Layout inspector: 502 - Helps debug Layout - Gives count

    for Recomposition/Skips in Composable @hi_man_shoe
  12. Profiling HWUI : 503. Settings > Developer Option > Monitoring

    > Pro fi le HWUI rendering. @hi_man_shoe
  13. Profiling HWUI : 503. - Each Screen has its own

    bar graph representing the UI changes. - vertical bar is a individual frame. - And height of it shows the time (ms) it took to render. @hi_man_shoe
  14. GPU Overdraw : 504. - The drawn pixels are not

    visible in the view displayed to the user - Can reduce performance. - More battery usage. - Bad user experience. @hi_man_shoe
  15. GPU Overdraw : 504. Settings > Developer Option > Hardware

    accelerated rendering > Debug GPU Overdraw. @hi_man_shoe
  16. Fixing GPU Overdraw : 504. - Reduce nested layouts -

    Use inline Composables like Rows and Columns - Optimizing backgrounds and backgroundColor - Less recompositions in Composable and persisting state values in scope of composable. @hi_man_shoe
  17. Strict Mode : 505. A developer too which detects things

    you might Be doing by accident and bring them to your attention so we can fi x. “ “ @hi_man_shoe
  18. Strict Mode : 505. override fun onCreate() { super.onCreate() if

    (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build() ) StrictMode.setVmPolicy( StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build() ) } } @hi_man_shoe
  19. Strict Mode : 505. override fun onCreate() { super.onCreate() if

    (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build() ) StrictMode.setVmPolicy( StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build() ) } } @hi_man_shoe
  20. Strict Mode : 505. override fun onCreate() { super.onCreate() if

    (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build() ) StrictMode.setVmPolicy( StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build() ) } } @hi_man_shoe
  21. Compose Compiler Report : 506. The compose compiler report generates

    report to determine which of you composable are skippable and which are not! @hi_man_shoe
  22. Compose Compiler Report : 506. subprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).con fi gureEach

    { kotlinOptions { if (project. fi ndProperty("composeCompilerReports") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } if (project. fi ndProperty("composeCompilerMetrics") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } } } }
  23. Compose Compiler Report : 506. subprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).con fi gureEach

    { kotlinOptions { if (project. fi ndProperty("composeCompilerReports") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } if (project. fi ndProperty("composeCompilerMetrics") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } } } }
  24. Compose Compiler Report : 506. subprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).con fi gureEach

    { kotlinOptions { if (project. fi ndProperty("composeCompilerReports") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } if (project. fi ndProperty("composeCompilerMetrics") == "true") { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + project.buildDir.absolutePath + "/compose_compiler" ] } } } }
  25. • module-class.txt : A report on the stability of classes

    in this • module-composables.txt : A report on how restartable and skippable the composables are. • module-composables.csv : A CSV Version of report. Compose Compiler Report : 506. @hi_man_shoe
  26. composables.txt restartable scheme("[androidx.compose.ui.UiComposable]") fun ServerList( stable index: Int unstable servers:

    List<Servers> stable OnServerClick: Function1<Long, Unit> stable modi fi er: Modi fi er? = @static Companion ) @hi_man_shoe
  27. composables.txt restartable scheme("[androidx.compose.ui.UiComposable]") fun ServerList( stable index: Int unstable servers:

    List<Servers> stable OnServerClick: Function1<Long, Unit> stable modi fi er: Modi fi er? = @static Companion ) @hi_man_shoe
  28. Pull Request Run the Compiler check Comment in PR Compose

    Compiler Report : 506. @hi_man_shoe
  29. - Wrong Usage of Threads. - Context :D - Patterns

    like Singleton. - Deregistering callbacks? Memory Leaks : 506. @hi_man_shoe