android fundamentals, debugging · © 2008 haim michael introduction the eclipse ide and the...

86
© 2008 Haim Michael Debugging

Upload: others

Post on 01-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Debugging

Page 2: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Introduction

The Eclipse IDE and the android SDK provide a rich set of

tools that assist us with developing our application for the

android platform and with debugging it.

Page 3: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

Developing for the android platform we can enjoy the same

Eclipse IDE features we know when using the Eclipse IDE

for other platforms.

Page 4: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

Page 5: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

When using the Eclipse IDE we get error messages on the

fly concurrently with coding our program.

We even get suggestions for fixing our code.

Page 6: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

Page 7: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

There are three available ways for toggling a break-point.

We can select the line and select from the top menu

Run->Toggle Break Point

We can double click in the left margin of the editor at the line

we want to toggle.

We can use the keyboard pressing Ctrl+shift+B.

Page 8: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Editor

Page 9: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Debugger

There are three available ways for toggling a break-point.

We can select the line and select from the top menu

Run->Toggle Break Point.

We can double click in the left margin of the editor at the line

we want to toggle.

We can use the keyboard pressing Ctrl+shift+B.

We start debugging by selecting from our top menu the

'Debug As' option.

Page 10: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Debugger

Page 11: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Eclipse Java Debugger

Page 12: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

Logcat is a general purpose logging facility. The Logcat

pane is available as part of the debugger perspective. The

Logcat pane includes a log of messages.

Page 13: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

Page 14: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

Each one of the messages has a different entry priority. The

Log class includes separated static methods for each one of

the available entry priorities.

static int d(String tag, String msg, Throwable tr)

Send a DEBUG log message and log the exception.

static int d(String tag, String msg)

Send a DEBUG log message.

Page 15: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

static int e(String tag, String msg)

Send an ERROR log message.

static int e(String tag, String msg, Throwable tr)

Send a ERROR log message and log the exception.

static int i(String tag, String msg, Throwable tr)

Send a INFO log message and log the exception.

static int i(String tag, String msg)

Send an INFO log message.

Page 16: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

static int v(String tag, String msg, Throwable tr)

Send a VERBOSE log message and log the exception.

static int v(String tag, String msg)

Send a VERBOSE log message.

static int w(String tag, String msg)

Send a WARN log message.

static int w(String tag, Throwable tr)

Send a WARN log message.

Page 17: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Logcat

static int w(String tag, String msg, Throwable tr)

Send a WARN log message and log the exception.

Page 18: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Sample

public class LoggerDemo extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);setContentView(R.layout.main);Button bt = (Button)findViewById(R.id.Button01);bt.setOnClickListener(new OnClickListener(){

@Overridepublic void onClick(View v) {

int sum = 0;for(int i=1; i<=100; i++){

sum += i;Log.i("loop","i="+i+" sum="+sum);

}EditText text = (EditText)findViewById(R.id.EditText01);text.setText("sum of 1..100 is "+sum);

}});

}}

Page 19: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Sample

Page 20: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Sample

Page 21: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

The android debug bridge (adb) is a special command line

tool the android platform comes with.

Using the android debug bridge we can remotely control the

device or the emulator we are working with.

We can invoke the android debug bridge client from the

command line prompt.

Page 22: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

Typing 'adb logcat' in the command line will get us the

detailed logcat messages.

Page 23: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

Page 24: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

Typing 'adb' in the command line will get us a detailed list of

all available adb's commands.

Page 25: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

Page 26: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Android Debug Bridge

Page 27: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Delvik Debug Monitor Service

Once the android SDK plug-in for the Eclipse IDE is

installed, we can start using the Delvik Debug Monitor

Service (DDMS).

The DDMS perspective provides a window based interface

for android specific debug information on the emulator (or

the real handset).

Page 28: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Delvik Debug Monitor Service

Page 29: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Delvik Debug Monitor Service

Page 30: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The Traceview utility allows tracking the exact methods that

are been called as well as the exact time each one of these

methods executions takes.

Page 31: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The Traceview utility includes two parts. The first is a small

utility that creates a log file that includes detailed data about

each and every method invocation. The second is a

graphics based application you can execute passing over

the log file and get a detailed graphics representation of all

methods calls.

Page 32: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

In order to use the Traceview utility we should first import

the android.os package and add to our code the following

lines.

...Debug.startMethodTracing(“mytrace”);...

...Debug.stopMethodTracing();...

Page 33: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The Tracebiew utility will fill in the log file on the android SD

card with data generated during the code execution.

If we work with the emulator then we should create an AVD

with a virtual SD card.

Page 34: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The first step should be creating the file on the SD card:mksdcard 10M traco

Page 35: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

Page 36: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The second step should be creating the AVD we want to use

specifying the size of the requested SD card.

Page 37: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

Page 38: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The third step should be telling the emulator we want to use

a virtual SC card. In the Eclipse IDE you should choose

Window > Preferences > Android > Launch. Within the box

for the emulator options you should add the following code-sdcard ./traco

Make sure to specify the complete path to the file, so the

emulator can always find it.

Page 39: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

Page 40: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

The fourth step would be executing our code. Our code

should include the call to start tracing the methods.Debug.startMethodTracing("traco"); //traco is the filename

In addition, our code should include a call to stop it.Debug.stopMethodTracing();

When the application calls startMethodTracing(), the

system creates a file called ___.trace (e.g. traco.trace). This

file contains the binary method trace data and its mapping

table with thread and method names.

Page 41: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

When using the Traceview utility the execution times are

significantly slower. Therefore, we shouldn't refer these

times as the accurate one. We can only compare them with

each other.

Once the execution completes we can get the log data

displayed in a graphics way.adb pull /sdcard/traco.trace /tmptraceview /tmp/traco

Page 42: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

Page 43: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael

Traceview

Page 44: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 1

10/11/10 © 2008 Haim Michael 1

Debugging

Page 45: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 2

10/11/10 © 2008 Haim Michael 2

Introduction

The Eclipse IDE and the android SDK provide a rich set of

tools that assist us with developing our application for the

android platform and with debugging it.

Page 46: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 3

10/11/10 © 2008 Haim Michael 3

Eclipse Java Editor

Developing for the android platform we can enjoy the same

Eclipse IDE features we know when using the Eclipse IDE

for other platforms.

Page 47: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 4

10/11/10 © 2008 Haim Michael 4

Eclipse Java Editor

Page 48: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 5

10/11/10 © 2008 Haim Michael 5

Eclipse Java Editor

When using the Eclipse IDE we get error messages on the

fly concurrently with coding our program.

We even get suggestions for fixing our code.

Page 49: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 6

10/11/10 © 2008 Haim Michael 6

Eclipse Java Editor

Page 50: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 7

10/11/10 © 2008 Haim Michael 7

Eclipse Java Editor

There are three available ways for toggling a break-point.

We can select the line and select from the top menu

Run->Toggle Break Point

We can double click in the left margin of the editor at the line

we want to toggle.

We can use the keyboard pressing Ctrl+shift+B.

Page 51: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 8

10/11/10 © 2008 Haim Michael 8

Eclipse Java Editor

Page 52: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 9

10/11/10 © 2008 Haim Michael 9

Eclipse Java Debugger

There are three available ways for toggling a break-point.

We can select the line and select from the top menu

Run->Toggle Break Point.

We can double click in the left margin of the editor at the line

we want to toggle.

We can use the keyboard pressing Ctrl+shift+B.

We start debugging by selecting from our top menu the

'Debug As' option.

Page 53: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 10

10/11/10 © 2008 Haim Michael 10

Eclipse Java Debugger

Page 54: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 11

10/11/10 © 2008 Haim Michael 11

Eclipse Java Debugger

Page 55: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 12

10/11/10 © 2008 Haim Michael 12

Logcat

Logcat is a general purpose logging facility. The Logcat

pane is available as part of the debugger perspective. The

Logcat pane includes a log of messages.

Page 56: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 13

10/11/10 © 2008 Haim Michael 13

Logcat

Page 57: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 14

10/11/10 © 2008 Haim Michael 14

Logcat

Each one of the messages has a different entry priority. The

Log class includes separated static methods for each one of

the available entry priorities.

static int d(String tag, String msg, Throwable tr)

Send a DEBUG log message and log the exception.

static int d(String tag, String msg)

Send a DEBUG log message.

Page 58: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 15

10/11/10 © 2008 Haim Michael 15

Logcat

static int e(String tag, String msg)

Send an ERROR log message.

static int e(String tag, String msg, Throwable tr)

Send a ERROR log message and log the exception.

static int i(String tag, String msg, Throwable tr)

Send a INFO log message and log the exception.

static int i(String tag, String msg)

Send an INFO log message.

Page 59: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 16

10/11/10 © 2008 Haim Michael 16

Logcat

static int v(String tag, String msg, Throwable tr)

Send a VERBOSE log message and log the exception.

static int v(String tag, String msg)

Send a VERBOSE log message.

static int w(String tag, String msg)

Send a WARN log message.

static int w(String tag, Throwable tr)

Send a WARN log message.

Page 60: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 17

10/11/10 © 2008 Haim Michael 17

Logcat

static int w(String tag, String msg, Throwable tr)

Send a WARN log message and log the exception.

Page 61: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 18

10/11/10 © 2008 Haim Michael 18

Sample

public class LoggerDemo extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);setContentView(R.layout.main);Button bt = (Button)findViewById(R.id.Button01);bt.setOnClickListener(new OnClickListener(){

@Overridepublic void onClick(View v) {

int sum = 0;for(int i=1; i<=100; i++){

sum += i;Log.i("loop","i="+i+" sum="+sum);

}EditText text = (EditText)findViewById(R.id.EditText01);text.setText("sum of 1..100 is "+sum);

}});

}}

Page 62: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 19

10/11/10 © 2008 Haim Michael 19

Sample

Page 63: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 20

10/11/10 © 2008 Haim Michael 20

Sample

Page 64: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 21

10/11/10 © 2008 Haim Michael 21

Android Debug Bridge

The android debug bridge (adb) is a special command line

tool the android platform comes with.

Using the android debug bridge we can remotely control the

device or the emulator we are working with.

We can invoke the android debug bridge client from the

command line prompt.

The server runs in the background. The server communicates either with the

emulator or the handset it self. The communication itself is carried out using the

TCP/IP protocol.

Page 65: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 22

10/11/10 © 2008 Haim Michael 22

Android Debug Bridge

Typing 'adb logcat' in the command line will get us the

detailed logcat messages.

Page 66: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 23

10/11/10 © 2008 Haim Michael 23

Android Debug Bridge

Page 67: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 24

10/11/10 © 2008 Haim Michael 24

Android Debug Bridge

Typing 'adb' in the command line will get us a detailed list of

all available adb's commands.

Page 68: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 25

10/11/10 © 2008 Haim Michael 25

Android Debug Bridge

Page 69: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 26

10/11/10 © 2008 Haim Michael 26

Android Debug Bridge

Page 70: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 27

10/11/10 © 2008 Haim Michael 27

Delvik Debug Monitor Service

Once the android SDK plug-in for the Eclipse IDE is

installed, we can start using the Delvik Debug Monitor

Service (DDMS).

The DDMS perspective provides a window based interface

for android specific debug information on the emulator (or

the real handset).

Page 71: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 28

10/11/10 © 2008 Haim Michael 28

Delvik Debug Monitor Service

Page 72: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 29

10/11/10 © 2008 Haim Michael 29

Delvik Debug Monitor Service

Page 73: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 30

10/11/10 © 2008 Haim Michael 30

Traceview

The Traceview utility allows tracking the exact methods that

are been called as well as the exact time each one of these

methods executions takes.

Page 74: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 31

10/11/10 © 2008 Haim Michael 31

Traceview

The Traceview utility includes two parts. The first is a small

utility that creates a log file that includes detailed data about

each and every method invocation. The second is a

graphics based application you can execute passing over

the log file and get a detailed graphics representation of all

methods calls.

Page 75: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 32

10/11/10 © 2008 Haim Michael 32

Traceview

In order to use the Traceview utility we should first import

the android.os package and add to our code the following

lines.

...Debug.startMethodTracing(“mytrace”);...

...Debug.stopMethodTracing();...

Page 76: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 33

10/11/10 © 2008 Haim Michael 33

Traceview

The Tracebiew utility will fill in the log file on the android SD

card with data generated during the code execution.

If we work with the emulator then we should create an AVD

with a virtual SD card.

Page 77: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 34

10/11/10 © 2008 Haim Michael 34

Traceview

The first step should be creating the file on the SD card:mksdcard 10M traco

Page 78: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 35

10/11/10 © 2008 Haim Michael 35

Traceview

Page 79: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 36

10/11/10 © 2008 Haim Michael 36

Traceview

The second step should be creating the AVD we want to use

specifying the size of the requested SD card.

Page 80: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 37

10/11/10 © 2008 Haim Michael 37

Traceview

Page 81: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 38

10/11/10 © 2008 Haim Michael 38

Traceview

The third step should be telling the emulator we want to use

a virtual SC card. In the Eclipse IDE you should choose

Window > Preferences > Android > Launch. Within the box

for the emulator options you should add the following code-sdcard ./traco

Make sure to specify the complete path to the file, so the

emulator can always find it.

Page 82: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 39

10/11/10 © 2008 Haim Michael 39

Traceview

Page 83: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 40

10/11/10 © 2008 Haim Michael 40

Traceview

The fourth step would be executing our code. Our code

should include the call to start tracing the methods.Debug.startMethodTracing("traco"); //traco is the filename

In addition, our code should include a call to stop it.Debug.stopMethodTracing();

When the application calls startMethodTracing(), the

system creates a file called ___.trace (e.g. traco.trace). This

file contains the binary method trace data and its mapping

table with thread and method names.

Page 84: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 41

10/11/10 © 2008 Haim Michael 41

Traceview

When using the Traceview utility the execution times are

significantly slower. Therefore, we shouldn't refer these

times as the accurate one. We can only compare them with

each other.

Once the execution completes we can get the log data

displayed in a graphics way.adb pull /sdcard/traco.trace /tmptraceview /tmp/traco

Page 85: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 42

10/11/10 © 2008 Haim Michael 42

Traceview

Page 86: Android Fundamentals, Debugging · © 2008 Haim Michael Introduction The Eclipse IDE and the android SDK provide a rich set of tools that assist us with developing our application

© 2008 Haim Michael 10/11/10

© 2008 Haim Michael 43

10/11/10 © 2008 Haim Michael 43

Traceview