Использование Debug утилит в разработке под Android

  • 1,829 views
Uploaded on

Antonenko V., Android developer at SoftTechnics

Antonenko V., Android developer at SoftTechnics

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,829
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
9
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Использование debug утилит в разработке под Android Антоненко Вячеслав Android developer 24.06.2011 1Friday, July 1, 11
  • 2. Утилиты Memory Analyzer (MAT) Traceview Hierarchyviewer Layoutopt LogcatFriday, July 1, 11
  • 3. Поиск утечки памяти  Анализ логов  Причины утечки памяти  Memory AnalyzerFriday, July 1, 11
  • 4. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms +2msFriday, July 1, 11
  • 5. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms +2ms Причина GC •GC_CONCURRENT •GC_FOR_MALLOC •GC_EXTERNAL_ALLOC •GC_HPROF_DUMP_HEAP •GC_EXPLICITFriday, July 1, 11
  • 6. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms  Reason for GC  Amount freedFriday, July 1, 11
  • 7. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms +2ms  Reason for GC  Amount freed  Heap statisticsFriday, July 1, 11
  • 8. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms +2ms  Reason for GC  Amount freed  Heap statistics  External memory statisticsFriday, July 1, 11
  • 9. Анализ лога D/dalvikvm( 3215): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms +2ms  Reason for GC  Amount freed  Heap statistics  External memory statistics  Pause timeFriday, July 1, 11
  • 10. Причины утечки памяти  Ссылки на не используемые объекты  Ссылки на Acitvity, Drawable, View  Долго живущие статические переменные  Не статические внутренние классыFriday, July 1, 11
  • 11. Получение дампа памяти  Получение дампа –DDMS –android.os.Debug.dumpHprofData()  Конвертация в стандартный HPROF формат –hprof-con dump.hprof converted_dump.hprof  Анализ при помощи MATFriday, July 1, 11
  • 12. Демонстрация примера работы с MATFriday, July 1, 11
  • 13. Friday, July 1, 11
  • 14. Friday, July 1, 11
  • 15. Оптимизация скорости работы приложения  Поиск узких мест в приложении  Оптимизация пользовательских элементов управленияFriday, July 1, 11
  • 16. Поиск «узких» мест в приложении Утилиты:  Traceview Режим StrictModeFriday, July 1, 11
  • 17. Использование Traceview из EclipseFriday, July 1, 11
  • 18. Использование Traceview из кода android.os.Debug.startMethodTracing("trace_file_name"); // your code is here android.os.Debug.stopMethodTracing(); Необходимо установить разрешение на WRITE_EXTERNAL_STORAGE Получение trace из устройства adb pull /sdcard/trace_file_name.trace Traceview trace_file_nameFriday, July 1, 11
  • 19. Режим StrictMode StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectAll() .penaltyLog().build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder().detectAll(). penaltyLog().build());Friday, July 1, 11
  • 20. Friday, July 1, 11
  • 21. … StrictMode(13858): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:758) … StrictMode(13858): at com.softtechnics.mobiletalk.traceview.MobileTalkOptTraceViewActivity .onCreate(MobileTalkOptTraceViewActivity.java:25) …Friday, July 1, 11
  • 22. Оптимизация пользовательских элементов Утилиты  hierarchyviewer  layoutoptFriday, July 1, 11
  • 23. <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <View android:layout_width="fill_parent" android:layout_height="120dip" android:background="@drawable/gradient_ligh_perfor_bg_bmp" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="20dip" android:paddingRight="20dip" android:paddingTop="55dip"> <EditText android:id="@+id/email" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:inputType="textEmailAddress" android:background="@drawable/reg_pole" android:hint="@string/hint_email" android:textColorHint="#545353" android:lines="1" /> //some code ... </RelativeLayout> </FrameLayout>Friday, July 1, 11
  • 24. Friday, July 1, 11
  • 25. <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android"> <View android:layout_width="fill_parent" android:layout_height="120dip" android:background="@drawable/gradient_ligh_perfor_bg_bmp" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="20dip" android:paddingRight="20dip" android:paddingTop="55dip"> <EditText android:id="@+id/email" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:inputType="textEmailAddress" android:background="@drawable/reg_pole" android:hint="@string/hint_email" android:textColorHint="#545353" android:lines="1" /> //some code ... </RelativeLayout> </merge>Friday, July 1, 11
  • 26. Friday, July 1, 11
  • 27. Использование Layoutopt layoutopt MobileTalkOptUI/res/layout/ MobileTalkOptUI/res/layout/pay.xml 31:607 This ScrollView layout or its LinearLayout parent is possibly useless 36:606 This LinearLayout tag should use android:layout_height="wrap_content« 78:91 This tag and its children can be replaced by one <TextView/> and a compound drawable 118:130 This LinearLayout layout or its LinearLayout parent is useless 129:129 Use an android:layout_height of 0dip instead of wrap_content for better performance 148:161 This LinearLayout layout or its LinearLayout parent is useless 160:160 Use an android:layout_height of 0dip instead of wrap_content for better performance MobileTalkOptUI/res/layout/main.xmlFriday, July 1, 11
  • 28. Спасибо за внимание! ул. Михайловская 25 Одесса 65005, Украина www.softtechnics.bizFriday, July 1, 11