SlideShare una empresa de Scribd logo
1 de 23
1
ANDROID NÂNG CAOANDROID NÂNG CAO
Bài 9:
Debugging inDebugging in
Android Application DevelopmentAndroid Application Development
Debug Environment
Dev Tools Android application
Hierarchy Viewer & layoutopt
Traceview & Method profiling
ANR & StrictMode
Agenda
jhat & Heap Profiling
Debug Environment
Android Debug Bridge
Model:
 Client
 Server
Components
A client
A server
A daemon
Important commands:
-d/-e/-s
devices.
install/uninstall.
pull/push
forward
shell
logcat
kill-server
Client
1
Client
2
Server
Daemon
1
Daemon
2
Daemon
31
5037
5037
5555/5554
5585/5584
5557/5556
UI/Application Exercise Monkey
The Monkey: generates pseudo-random streams of user events
Application: stress-test applications
Detect application crashes or receives any sort of unhandled
exception.
ANR error.
Basic usage:
$ adb shell monkey [options] <event-count>
 Sample:
$ adb shell monkey -p your.package.name -v 500
 Reference:
http://developer.android.com/guide/developing/tools/monkey.html
Dalvik Debug Monitor Server
 2 ways to start DDMS:
 Command line.
 Show DDMS perspective in Eclipse.
 Using:
 Monitoring:
 Viewing heap usage for a process.
 Tracking memory allocation of objects.
 Examining thread information.
 Starting method profiling.
 Using LogCat.
 File operation
 Work with emulator or device’s file system.
 Emulating phone operations and location
 Changing network state, speed, latency.
 Spoofing calls or SMS text messages.
 Setting the location of phone.
 Process Management
 Execute garbage collection
 Interrupt process
 Reference:
http://developer.android.com/guide/developing/debugging/ddms.html
adb logcat command
Use to view & follow the content of system log’s buffer.
Filter log output:
Using filter expression: tag:priority … tag:priority
Controll log output format:
Using –v switch: brief, process, tag, thread, raw, time, long.
Viewing Alternative Log Buffers :
Using –b switch: radio, event, main.
Viewing stdout and stderr:
setprop log.redirect-stdio true or edit /data/local.prop
Reference:
http://developer.android.com/guide/developing/tools/adb.html
Device
DDMS & Debuggers
DDMS adb
Connect
VM monitoring service
VM
JDWP
Debugger
(jdb)
VM start/stop
adbd
VM’s PID
Monitor
8700
8600
Hierarchy Viewer & layoutopt
Purpose: Debugging & profiling user interface
Tools:
Hierarchy Viewer.
layoutopt
Reference:
http://developer.android.com/guide/developing/debugging/debugging-ui.html
Hierarchy Viewer
Purpose: Debugging &optimize user interface
Running HV:
Connect your device or launch an emulator.
Install the application you want to work with.
Run the application, and ensure that its UI is visible.
Launch hierarchyviewer
The first window you see displays a list of devices and emulators.
Select the name of your Activity from the list. You can now look at
its view hierarchy using the View Hierarchy window, or look at a
magnified image of the UI using the Pixel Perfect window
Hierarchy Viewer
•TreeView:
Hierarchy Viewer
•Pixel Perfect window:
layoutopt
Purpose: analyze XML layout file to find inefficiences.
Running layoutopt: layoutopt <xmlfile>
Information display when effect is detected:
The filename
 The line number.
 The description.
TraceView & Method Profiling
 TraceView: a graphical viewer for execution logs that you create by using the Debug
class to log tracing information in your code.
 Application:
 Method profiling to find the bottle neck in your code execution.
 Usage:
 Create trace file:
 Using Debug class:
// start tracing to "/sdcard/xml.trace"
Debug.startMethodTracing(“xml");
//Call to the method you want to trace.
// stop tracing
Debug.stopMethodTracing();
 Using method profiling feature of DDMS to generate trace file.
 Copy file to host machine.
 Viewing trace file in Traceview.
 Limitation:
 Thread name is not emitted if thread exits during profiling.
 Reuses thread ID of VM.
 Reference:
http://developer.android.com/guide/developing/debugging/debugging-tracing.html
TraceView & Method Profiling
 Timeline Panel:
 Profile Panel:
dmtracedump
 Generate graphical call-stack diagram from trace log file.
Call reference number Inclusive elapsed time Exclusive elapsed time
Number of calls
dmtracedump [-ho] [-s sortable] [-d trace-base-name] [-g outfile] <trace-base-name>
jhat & Heap Profiling
 Heap Profiling helps to find the leak memory, speed up the program:
 How many instances of a class.
 How much memory usage.
 Usage:
 Set the break point:
 Exception break point.
 Conditional break point.
 Dump HPROF file from DDMS.
 Using jhat (java heap analysis tool) to parse hprof file.
 Open the favorite web browser and visit: http://localhost:7000
jhat & Heap Profiling
 Exception breakpoint:
 Run > Add Java Exception Breakpoint …
 Conditional breakpoint:
 Right click on breakpoint > Properties > Check Conditional checkbox > Enter the
condition.
Read more about MAT: http://10.1.6.46/mediawiki/index.php/Dectect_memory_leak_using_MAT
jhat & Heap Profiling
 Using DDMS dump hprof file:
 Click on “Show heap histogram”:
ANR & StrictMode
 ANR.
 Causes
 Activity
 BroadcastReceiver
 StrictMode:
public void onCreate() {
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
super.onCreate();
}
 Reference:
http://developer.android.com/guide/practices/design/responsiveness.html
Dev Tools Application
 Get it from emulator & install into real device.
 Application:
 Enable some settings in your device for testing & debugging.
 Usage:
 Launch it > Development Settings
 Debug app
 Wait for debugger
 Show screen updates
 Immediately destroy activities
 Show CPU usage
 Show background
 Reference:
http://developer.android.com/guide/developing/debugging/debugging-devtools.html
Debug Tips
 Dump the stack trace:
adb shell > ps > kill -3
 Display useful info on the emulator screen:
View Dev Tools App
 Get application and system state information from the emulator:
View dumpsys and dumpstate
 Get wireless connectivity information:
DDMS > Device menu > Dump radio state
 Log trace data:
Call startMethodTracing()
 Log radio data:
adb shell>logcat –b radio
 Capture screenshots:
DDMS> Select device >Screen Capture
 Use debugging helper classes:
Log, Debug, StrictMode
 Garbage collection:
Any object the debugger is aware of is not garbage collected until after the debugger disconnects
Nguyen Huu Phuoc, MEng.
●  Blog:http://folami.nghelong.com
●  Website http://phuocnh.nghelong.com

Más contenido relacionado

La actualidad más candente

Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発Kohki Miki
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageablecorehard_by
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Grain final border one
Grain final border oneGrain final border one
Grain final border oneAshish Gupta
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCPEric Jain
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?Christophe Porteneuve
 
The Case for React.js and ClojureScript
The Case for React.js and ClojureScriptThe Case for React.js and ClojureScript
The Case for React.js and ClojureScriptMurilo Pereira
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4Linaro
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorBartosz Kosarzycki
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3Linaro
 
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur Shemsedinov"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur ShemsedinovFwdays
 
T-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLT-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLmniemi
 

La actualidad más candente (20)

Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発
 
Enterprise js pratices
Enterprise js praticesEnterprise js pratices
Enterprise js pratices
 
Modern c++
Modern c++Modern c++
Modern c++
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
 
C++17 now
C++17 nowC++17 now
C++17 now
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Grain final border one
Grain final border oneGrain final border one
Grain final border one
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
 
The Case for React.js and ClojureScript
The Case for React.js and ClojureScriptThe Case for React.js and ClojureScript
The Case for React.js and ClojureScript
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Dynamic virtual evironments
Dynamic virtual evironmentsDynamic virtual evironments
Dynamic virtual evironments
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3
 
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur Shemsedinov"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
 
T-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLT-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIML
 

Destacado

Android Nâng cao-Bài 3: Broadcast Receiver
Android Nâng cao-Bài 3: Broadcast ReceiverAndroid Nâng cao-Bài 3: Broadcast Receiver
Android Nâng cao-Bài 3: Broadcast ReceiverPhuoc Nguyen
 
Android Nâng cao-Bài 4: Content Provider
Android Nâng cao-Bài 4: Content ProviderAndroid Nâng cao-Bài 4: Content Provider
Android Nâng cao-Bài 4: Content ProviderPhuoc Nguyen
 
Android Nâng cao-Bài 8-JSON & XML Parsing
Android Nâng cao-Bài 8-JSON & XML ParsingAndroid Nâng cao-Bài 8-JSON & XML Parsing
Android Nâng cao-Bài 8-JSON & XML ParsingPhuoc Nguyen
 
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnit
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnitAndroid Nâng cao-Bài 6-Multi theme-adb tool-jUnit
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnitPhuoc Nguyen
 
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Ngo Trung
 
Android Nâng cao-Bài 5:Notification Multiresolution Multilanguage
Android Nâng cao-Bài 5:Notification Multiresolution MultilanguageAndroid Nâng cao-Bài 5:Notification Multiresolution Multilanguage
Android Nâng cao-Bài 5:Notification Multiresolution MultilanguagePhuoc Nguyen
 
Android location sensor programming
Android location sensor programmingAndroid location sensor programming
Android location sensor programmingPhuoc Nguyen
 
Android talks #08 android profiling
Android talks #08   android profilingAndroid talks #08   android profiling
Android talks #08 android profilingInfinum
 
IT120-1. Giới thiệu về Android SDK
IT120-1. Giới thiệu về Android SDKIT120-1. Giới thiệu về Android SDK
IT120-1. Giới thiệu về Android SDKMultiUni
 
Google Android Security (Basic2Advanced)
Google Android Security (Basic2Advanced)Google Android Security (Basic2Advanced)
Google Android Security (Basic2Advanced)Giap Le Van
 
Android presentation
Android presentationAndroid presentation
Android presentationNguyen Duong
 
Android chapter03-life-cycle
Android chapter03-life-cycleAndroid chapter03-life-cycle
Android chapter03-life-cycleVu Dang
 
Basic Sqlite in Android
Basic Sqlite in AndroidBasic Sqlite in Android
Basic Sqlite in Androidyuchi_1k91 Pit
 
Slide hội thảo Google Android BKHN 26-10
Slide hội thảo Google Android BKHN 26-10Slide hội thảo Google Android BKHN 26-10
Slide hội thảo Google Android BKHN 26-10Giap Le Van
 
Tìm hiểu về hệ điều hành android
Tìm hiểu về hệ điều hành androidTìm hiểu về hệ điều hành android
Tìm hiểu về hệ điều hành androidTÓc Đỏ XuÂn
 
Bài 1: Giới thiệu Android
Bài 1: Giới thiệu AndroidBài 1: Giới thiệu Android
Bài 1: Giới thiệu Androidhoccungdoanhnghiep
 

Destacado (20)

Android Nâng cao-Bài 3: Broadcast Receiver
Android Nâng cao-Bài 3: Broadcast ReceiverAndroid Nâng cao-Bài 3: Broadcast Receiver
Android Nâng cao-Bài 3: Broadcast Receiver
 
Android Nâng cao-Bài 4: Content Provider
Android Nâng cao-Bài 4: Content ProviderAndroid Nâng cao-Bài 4: Content Provider
Android Nâng cao-Bài 4: Content Provider
 
Android Nâng cao-Bài 8-JSON & XML Parsing
Android Nâng cao-Bài 8-JSON & XML ParsingAndroid Nâng cao-Bài 8-JSON & XML Parsing
Android Nâng cao-Bài 8-JSON & XML Parsing
 
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnit
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnitAndroid Nâng cao-Bài 6-Multi theme-adb tool-jUnit
Android Nâng cao-Bài 6-Multi theme-adb tool-jUnit
 
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
Cách tối ưu hóa môi trường lập trình ứng dụng cho Android - Tăng tốc máy ảo A...
 
Android Nâng cao-Bài 5:Notification Multiresolution Multilanguage
Android Nâng cao-Bài 5:Notification Multiresolution MultilanguageAndroid Nâng cao-Bài 5:Notification Multiresolution Multilanguage
Android Nâng cao-Bài 5:Notification Multiresolution Multilanguage
 
Android location sensor programming
Android location sensor programmingAndroid location sensor programming
Android location sensor programming
 
Android talks #08 android profiling
Android talks #08   android profilingAndroid talks #08   android profiling
Android talks #08 android profiling
 
Android chapter03-life-cycle
Android chapter03-life-cycleAndroid chapter03-life-cycle
Android chapter03-life-cycle
 
IT120-1. Giới thiệu về Android SDK
IT120-1. Giới thiệu về Android SDKIT120-1. Giới thiệu về Android SDK
IT120-1. Giới thiệu về Android SDK
 
Android ios wp7
Android ios wp7Android ios wp7
Android ios wp7
 
Google Android Security (Basic2Advanced)
Google Android Security (Basic2Advanced)Google Android Security (Basic2Advanced)
Google Android Security (Basic2Advanced)
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Android chapter03-life-cycle
Android chapter03-life-cycleAndroid chapter03-life-cycle
Android chapter03-life-cycle
 
Basic Sqlite in Android
Basic Sqlite in AndroidBasic Sqlite in Android
Basic Sqlite in Android
 
Slide hội thảo Google Android BKHN 26-10
Slide hội thảo Google Android BKHN 26-10Slide hội thảo Google Android BKHN 26-10
Slide hội thảo Google Android BKHN 26-10
 
Android OS
Android OSAndroid OS
Android OS
 
Lap trinh android – kiem tien ngay trong khi hoc
Lap trinh android – kiem tien ngay trong khi hocLap trinh android – kiem tien ngay trong khi hoc
Lap trinh android – kiem tien ngay trong khi hoc
 
Tìm hiểu về hệ điều hành android
Tìm hiểu về hệ điều hành androidTìm hiểu về hệ điều hành android
Tìm hiểu về hệ điều hành android
 
Bài 1: Giới thiệu Android
Bài 1: Giới thiệu AndroidBài 1: Giới thiệu Android
Bài 1: Giới thiệu Android
 

Similar a Android Nâng cao-Bài 9-Debug in Android Application Development

.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and TechniquesBala Subra
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging TechniquesBala Subra
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsDror Bereznitsky
 
Android tools for testers
Android tools for testersAndroid tools for testers
Android tools for testersMaksim Kovalev
 
Android developmenttools 20100424
Android developmenttools 20100424Android developmenttools 20100424
Android developmenttools 20100424Marakana Inc.
 
Reversing & malware analysis training part 12 rootkit analysis
Reversing & malware analysis training part 12   rootkit analysisReversing & malware analysis training part 12   rootkit analysis
Reversing & malware analysis training part 12 rootkit analysisAbdulrahman Bassam
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Massimo Oliviero
 
Android Logging System
Android Logging SystemAndroid Logging System
Android Logging SystemWilliam Lee
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VOpersys inc.
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIOpersys inc.
 
CHAPTER 3 BASIC DYNAMIC ANALYSIS.ppt
CHAPTER 3 BASIC DYNAMIC ANALYSIS.pptCHAPTER 3 BASIC DYNAMIC ANALYSIS.ppt
CHAPTER 3 BASIC DYNAMIC ANALYSIS.pptManjuAppukuttan2
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsPositive Hack Days
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharingJames Hsieh
 
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientHoneynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientAngelo Dell'Aera
 
Damage Control
Damage ControlDamage Control
Damage Controlsintaxi
 
Troubleshooting real production problems
Troubleshooting real production problemsTroubleshooting real production problems
Troubleshooting real production problemsTier1 app
 
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...DevOpsDays Tel Aviv
 

Similar a Android Nâng cao-Bài 9-Debug in Android Application Development (20)

.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
 
Android tools for testers
Android tools for testersAndroid tools for testers
Android tools for testers
 
Android developmenttools 20100424
Android developmenttools 20100424Android developmenttools 20100424
Android developmenttools 20100424
 
Reversing & malware analysis training part 12 rootkit analysis
Reversing & malware analysis training part 12   rootkit analysisReversing & malware analysis training part 12   rootkit analysis
Reversing & malware analysis training part 12 rootkit analysis
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
 
Android Logging System
Android Logging SystemAndroid Logging System
Android Logging System
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 
CHAPTER 3 BASIC DYNAMIC ANALYSIS.ppt
CHAPTER 3 BASIC DYNAMIC ANALYSIS.pptCHAPTER 3 BASIC DYNAMIC ANALYSIS.ppt
CHAPTER 3 BASIC DYNAMIC ANALYSIS.ppt
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android Applications
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
 
Stetho demo
Stetho demoStetho demo
Stetho demo
 
Android dev
Android devAndroid dev
Android dev
 
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientHoneynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
 
Android tools
Android toolsAndroid tools
Android tools
 
Damage Control
Damage ControlDamage Control
Damage Control
 
Troubleshooting real production problems
Troubleshooting real production problemsTroubleshooting real production problems
Troubleshooting real production problems
 
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
 

Más de Phuoc Nguyen

Hiberbate Framework
Hiberbate FrameworkHiberbate Framework
Hiberbate FrameworkPhuoc Nguyen
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate FrameworkPhuoc Nguyen
 
Webservice performance testing with SoapUI
Webservice performance testing with SoapUIWebservice performance testing with SoapUI
Webservice performance testing with SoapUIPhuoc Nguyen
 
Web application security test tools
Web application security test toolsWeb application security test tools
Web application security test toolsPhuoc Nguyen
 
A successful project sharing
A successful project sharingA successful project sharing
A successful project sharingPhuoc Nguyen
 
Buồn vui nghề IT (Pros & cons of IT Career)
Buồn vui nghề IT (Pros & cons of IT Career)Buồn vui nghề IT (Pros & cons of IT Career)
Buồn vui nghề IT (Pros & cons of IT Career)Phuoc Nguyen
 

Más de Phuoc Nguyen (7)

Lanh dao va TPP
Lanh dao va TPPLanh dao va TPP
Lanh dao va TPP
 
Hiberbate Framework
Hiberbate FrameworkHiberbate Framework
Hiberbate Framework
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Webservice performance testing with SoapUI
Webservice performance testing with SoapUIWebservice performance testing with SoapUI
Webservice performance testing with SoapUI
 
Web application security test tools
Web application security test toolsWeb application security test tools
Web application security test tools
 
A successful project sharing
A successful project sharingA successful project sharing
A successful project sharing
 
Buồn vui nghề IT (Pros & cons of IT Career)
Buồn vui nghề IT (Pros & cons of IT Career)Buồn vui nghề IT (Pros & cons of IT Career)
Buồn vui nghề IT (Pros & cons of IT Career)
 

Último

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Android Nâng cao-Bài 9-Debug in Android Application Development

  • 1. 1 ANDROID NÂNG CAOANDROID NÂNG CAO Bài 9: Debugging inDebugging in Android Application DevelopmentAndroid Application Development
  • 2. Debug Environment Dev Tools Android application Hierarchy Viewer & layoutopt Traceview & Method profiling ANR & StrictMode Agenda jhat & Heap Profiling
  • 4. Android Debug Bridge Model:  Client  Server Components A client A server A daemon Important commands: -d/-e/-s devices. install/uninstall. pull/push forward shell logcat kill-server Client 1 Client 2 Server Daemon 1 Daemon 2 Daemon 31 5037 5037 5555/5554 5585/5584 5557/5556
  • 5. UI/Application Exercise Monkey The Monkey: generates pseudo-random streams of user events Application: stress-test applications Detect application crashes or receives any sort of unhandled exception. ANR error. Basic usage: $ adb shell monkey [options] <event-count>  Sample: $ adb shell monkey -p your.package.name -v 500  Reference: http://developer.android.com/guide/developing/tools/monkey.html
  • 6. Dalvik Debug Monitor Server  2 ways to start DDMS:  Command line.  Show DDMS perspective in Eclipse.  Using:  Monitoring:  Viewing heap usage for a process.  Tracking memory allocation of objects.  Examining thread information.  Starting method profiling.  Using LogCat.  File operation  Work with emulator or device’s file system.  Emulating phone operations and location  Changing network state, speed, latency.  Spoofing calls or SMS text messages.  Setting the location of phone.  Process Management  Execute garbage collection  Interrupt process  Reference: http://developer.android.com/guide/developing/debugging/ddms.html
  • 7. adb logcat command Use to view & follow the content of system log’s buffer. Filter log output: Using filter expression: tag:priority … tag:priority Controll log output format: Using –v switch: brief, process, tag, thread, raw, time, long. Viewing Alternative Log Buffers : Using –b switch: radio, event, main. Viewing stdout and stderr: setprop log.redirect-stdio true or edit /data/local.prop Reference: http://developer.android.com/guide/developing/tools/adb.html
  • 8. Device DDMS & Debuggers DDMS adb Connect VM monitoring service VM JDWP Debugger (jdb) VM start/stop adbd VM’s PID Monitor 8700 8600
  • 9. Hierarchy Viewer & layoutopt Purpose: Debugging & profiling user interface Tools: Hierarchy Viewer. layoutopt Reference: http://developer.android.com/guide/developing/debugging/debugging-ui.html
  • 10. Hierarchy Viewer Purpose: Debugging &optimize user interface Running HV: Connect your device or launch an emulator. Install the application you want to work with. Run the application, and ensure that its UI is visible. Launch hierarchyviewer The first window you see displays a list of devices and emulators. Select the name of your Activity from the list. You can now look at its view hierarchy using the View Hierarchy window, or look at a magnified image of the UI using the Pixel Perfect window
  • 13. layoutopt Purpose: analyze XML layout file to find inefficiences. Running layoutopt: layoutopt <xmlfile> Information display when effect is detected: The filename  The line number.  The description.
  • 14. TraceView & Method Profiling  TraceView: a graphical viewer for execution logs that you create by using the Debug class to log tracing information in your code.  Application:  Method profiling to find the bottle neck in your code execution.  Usage:  Create trace file:  Using Debug class: // start tracing to "/sdcard/xml.trace" Debug.startMethodTracing(“xml"); //Call to the method you want to trace. // stop tracing Debug.stopMethodTracing();  Using method profiling feature of DDMS to generate trace file.  Copy file to host machine.  Viewing trace file in Traceview.  Limitation:  Thread name is not emitted if thread exits during profiling.  Reuses thread ID of VM.  Reference: http://developer.android.com/guide/developing/debugging/debugging-tracing.html
  • 15. TraceView & Method Profiling  Timeline Panel:  Profile Panel:
  • 16. dmtracedump  Generate graphical call-stack diagram from trace log file. Call reference number Inclusive elapsed time Exclusive elapsed time Number of calls dmtracedump [-ho] [-s sortable] [-d trace-base-name] [-g outfile] <trace-base-name>
  • 17. jhat & Heap Profiling  Heap Profiling helps to find the leak memory, speed up the program:  How many instances of a class.  How much memory usage.  Usage:  Set the break point:  Exception break point.  Conditional break point.  Dump HPROF file from DDMS.  Using jhat (java heap analysis tool) to parse hprof file.  Open the favorite web browser and visit: http://localhost:7000
  • 18. jhat & Heap Profiling  Exception breakpoint:  Run > Add Java Exception Breakpoint …  Conditional breakpoint:  Right click on breakpoint > Properties > Check Conditional checkbox > Enter the condition. Read more about MAT: http://10.1.6.46/mediawiki/index.php/Dectect_memory_leak_using_MAT
  • 19. jhat & Heap Profiling  Using DDMS dump hprof file:  Click on “Show heap histogram”:
  • 20. ANR & StrictMode  ANR.  Causes  Activity  BroadcastReceiver  StrictMode: public void onCreate() { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(); }  Reference: http://developer.android.com/guide/practices/design/responsiveness.html
  • 21. Dev Tools Application  Get it from emulator & install into real device.  Application:  Enable some settings in your device for testing & debugging.  Usage:  Launch it > Development Settings  Debug app  Wait for debugger  Show screen updates  Immediately destroy activities  Show CPU usage  Show background  Reference: http://developer.android.com/guide/developing/debugging/debugging-devtools.html
  • 22. Debug Tips  Dump the stack trace: adb shell > ps > kill -3  Display useful info on the emulator screen: View Dev Tools App  Get application and system state information from the emulator: View dumpsys and dumpstate  Get wireless connectivity information: DDMS > Device menu > Dump radio state  Log trace data: Call startMethodTracing()  Log radio data: adb shell>logcat –b radio  Capture screenshots: DDMS> Select device >Screen Capture  Use debugging helper classes: Log, Debug, StrictMode  Garbage collection: Any object the debugger is aware of is not garbage collected until after the debugger disconnects
  • 23. Nguyen Huu Phuoc, MEng. ●  Blog:http://folami.nghelong.com ●  Website http://phuocnh.nghelong.com