TiConf US 2014

38
TICONF.US, NEW YORK, 10/05/2014 Debugging and Profiling Titanium Apps

description

Slides for my talk at TiConf US 2014

Transcript of TiConf US 2014

Page 1: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Debugging and Profiling Titanium Apps

Page 2: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 2

Olivier Morandi Software engineer !

http://[email protected] @olivier_morandi https://github.com/omorandi

Page 3: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 3

Where I’m from

Page 4: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Ti app development

• Native module development (iOS/Android)

• Optimisations

• R&D

4

Page 5: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Available tools

• Tools I wish would exist

• Experiments & hacks

5

This talk

Page 6: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• console.log() aka Ti.API.info()

• Ti Studio Debugger

6

Titanium JS Debugging Tools

Page 7: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• If abused, logging statements add too much clutter to your code + they’re not inexpensive

• I want to be able to debug both JS and native code (iOS modules) at the same time

• Ti debugger doesn’t fit in a CLI-based workflow

7

Problems

Page 8: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Ti Inspector https://github.com/omorandi/TiInspector

8

Page 9: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 9

Titanium debugger (iOS)

Ti JSCore Debugger

Agent

Custom TCP protocolhttp://docs.appcelerator.com/titanium/latest/#!/guide/Debugger_Protocol

1176979825728*breakpoint*create*app://app.js*116*1*0**1

1176979825728*created

TiStudio

Page 10: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 10

Chrome Remote DebuggingChrome Devtools Inspected Page

JSON-RPC protocol over Websockets

{"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":32,"url":"todo-view.js","columnNumber":0,"condition":""},"id":157}

{"result":{"breakpointId":"odo-view.js:32:0","locations":[{"scriptId":"96","lineNumber":32,"columnNumber":7}]},"id":157}

https://developers.google.com/chrome-developer-tools/docs/debugger-protocol?hl=it

Page 11: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 11

Ti InspectorChrome Devtools

Ti InspectorTi debugger protocolWeb Inspector protocol

Ti JSCore Debugger

Agent

Page 12: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

$ [sudo] npm install -g ti-inspector

12

Ti Inspector - Install

Page 13: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

$ cd path/to/your/ti/project!

$ ti-inspector !

$ open http://localhost:8080!

$ titanium build -p ios —debug-host localhost:8999

13

Ti Inspector - Run

Page 14: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Breakpoints

• Variable & object inspection

• Watches

14

Debugging

Page 15: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Console & REPL

• Stepping

• Conditional breakpoints

15

Debugging

Page 16: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Ti Inspector demo

16

Page 17: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• iOS only

• On device debugging

• Possible running the project through Xcode

• There’ll be a module for that ;-)

• Alloy source maps

• No support for multiple JS threads

• e.g. Ti.UI.Window created via url property

• Expression eval not supported if not suspended

17

What’s missing

Page 18: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Node Inspector https://github.com/node-inspector/node-inspector

18

Page 19: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Originally implemented by Danny Coates, it’s a gateway between Chrome Devtools and the V8 debugging agent

• Strongloop recently took over the project and started improving on it

• It works for debugging Ti Apps on Android

19

Node Inspector

Page 20: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 20

Node InspectorChrome Devtools

Node InspectorV8 debugger protocolWeb Inspector protocol

V8 Debugger

Agent

Page 21: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

$ [sudo] npm install -g node-inspector

21

Node Inspector - Install

Page 22: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

$ node-inspector !

$ titanium build -p android —debug-host localhost:5858!

$ open http://127.0.0.1:8080/debug?port=5858

22

Node Inspector - Run

Page 23: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• No console logging (only evaluation)

23

Limitations

Page 24: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Node Inspector demo

24

Page 25: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

What about other Chrome Devtools features?

25

Page 26: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Profiles ★ cpu ★ heap

• Timeline

• Network

• Page layout

26

Devtools

Page 27: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

More opportunities to inspect the internal state and the behaviour of our app

27

Page 28: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

TiScope (Very early work in progress)

28

Page 29: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Ti Inspector 2.0

★ Instrument Titanium

• events

• network requests

• other sources of interesting behaviour

★ Expose JS engine information

• Execution profiles

• Memory behaviour

★ Analysis through Chrome devtools

29

TiScope

Page 30: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Android only

• At the moment: custom Ti SDK build ★ Some instrumentation hooks added to Ti

proxy implementation ★ Instrumenting agents living in self

contained Java + native library

30

How it works (now)

Page 31: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

TiScope demo (Android)

31

Page 32: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

JS Function Tracing (Very early work in progress)

32

Page 33: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014 33

Tracing function calls on iOS

Page 34: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Tiny modification in Ti-JSCore source code +

• Native iOS module !

• Produce a trace file

• Import into Chrome’s about:tracing page

34

JSCore tracing

Page 35: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Tracing demo

35

Page 36: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• Add more instrumenting agents

• Implement the same on iOS

• Stabilise the code

• Integrate everything together in a self contained tool ★ possibly a CLI build hook

36

Future plans

Page 37: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

• twitter: @olivier_morandi

• email: [email protected]

37

Feedback needed

Page 38: TiConf US 2014

TICONF.US, NEW YORK, 10/05/2014

Q&A !

Thank you!