SlideShare a Scribd company logo
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

More Related Content

What's hot

Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発Kobold2Dで始めるゲーム開発
Kobold2Dで始めるゲーム開発
Kohki Miki
 
Enterprise js pratices
Enterprise js praticesEnterprise js pratices
Enterprise js pratices
Marjan Nikolovski
 
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
corehard_by
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
Mobile Data Systems Ltd.
 
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
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
C++17 now
C++17 nowC++17 now
C++17 now
corehard_by
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
Grain final border one
Grain final border oneGrain final border one
Grain final border one
Ashish Gupta
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
Eric 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 ClojureScript
Murilo Pereira
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
Doeun 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 4
Linaro
 
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
Bartosz Kosarzycki
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
Mindfire Solutions
 
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
Linaro
 
"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
Fwdays
 
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
 

What's hot (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
 

Viewers also liked

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
Phuoc 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 Provider
Phuoc 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 programming
Phuoc Nguyen
 
Android talks #08 android profiling
Android talks #08   android profilingAndroid talks #08   android profiling
Android talks #08 android profiling
Infinum
 
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
MultiUni
 
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 presentation
Nguyen Duong
 
Android chapter03-life-cycle
Android chapter03-life-cycleAndroid chapter03-life-cycle
Android chapter03-life-cycle
Vu Dang
 
Basic Sqlite in Android
Basic Sqlite in AndroidBasic Sqlite in Android
Basic Sqlite in Android
yuchi_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-10
Giap Le Van
 
Android OS
Android OSAndroid 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
Học viện đào tạo CNTT NIIT iNET
 
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
TÓ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
 

Viewers also liked (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 to Android Nâng cao-Bài 9-Debug in Android Application Development

.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
Bala Subra
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
Bala Subra
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
Dror Bereznitsky
 
Android tools for testers
Android tools for testersAndroid tools for testers
Android tools for testers
Maksim Kovalev
 
Android developmenttools 20100424
Android developmenttools 20100424Android developmenttools 20100424
Android developmenttools 20100424
Marakana 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 System
William 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.ppt
ManjuAppukuttan2
 
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
 
Stetho demo
Stetho demoStetho demo
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
 
Android tools
Android toolsAndroid tools
Android tools
Alexey Ustenko
 
Damage Control
Damage ControlDamage Control
Damage Control
sintaxi
 
Troubleshooting real production problems
Troubleshooting real production problemsTroubleshooting real production problems
Troubleshooting real production problems
Tier1 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 to Android Nâng cao-Bài 9-Debug in Android Application Development (20)

.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and 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...
 

More from Phuoc Nguyen

Lanh dao va TPP
Lanh dao va TPPLanh dao va TPP
Lanh dao va TPP
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 tools
Phuoc Nguyen
 
A successful project sharing
A successful project sharingA successful project sharing
A successful project sharing
Phuoc 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
 

More from 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)
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

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