Skip to content

Using Kojak to Profile the Backbone MVC App

Bart wood edited this page Oct 25, 2013 · 2 revisions

I've heard it might useful to show how Kojak actually works with a real example. I've taken the Backbone MVC App and created an example of how to profile it with Kojak.

The original Backbone Todo MVC app can be found here: https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/backbone

I've pulled out the code to the Kojak repo on 10/25/2013: https://github.com/theironcook/Kojak/tree/master/example/TodoMVC_Backbone

All of the changes I introduced to get Kojak working with the sample app can be found here from line 65: https://github.com/theironcook/Kojak/blob/master/example/TodoMVC_Backbone/index.html

To use Kojak with this simple application I first have to understand where the main pakages live. In this simple example there is only one root pakage with the name app. I tell Kojak about this by calling kConfig.setIncludedPackages(['app']);.

I also needed to expose the Todos clazz to Kojak because it wasn't exposed under the app pakage. I do that with this line of code app.Todos = app.todos.constructor;.

I then had to introduce artificial delays in the code. (Normally Kojak is most useful for large applications.) I created the function blockThread and I call it from the Todo initialize function if the title of the Todo contains the word "wait".

I also call the kInst.instrument() function actually instrument all of the code underneath the app pakage.

Then I call kRep.instrumentedCode({verbose: true}); to see what code has been instrumented.

After the app has loaded you need to invoke some of the functionality. Create a few todo items with the word "wait" in the title. You can also specify how long to wait by including a number after "wait". If you enter "wait 500" the code will block for 500 milliseconds in the Todo initialize() function.

You can then run kRep.funcPerf({sortBy: 'CallCount'}); to see what the slowest functions are.

I sort by 'CallCount' because some of the function times are so fast they won't even show up in the report because the IsolatedTime is 0.

Clone this wiki locally