nkashyap / console.io

JavaScript Remote Web Console
http://nkashyap.github.io/console.io
188 stars 20 forks source link

Profiling Support #11

Open nkashyap opened 10 years ago

nkashyap commented 10 years ago

From: Igor Bezkrovny

Hi,

We are working on SmartTV HTML5 games on wide range of TV platforms.

Profiling such games on device is only way to make games running fast. Profiling is must-have for development on SmartTV devices for us.

There are 2 methods to implement profiler in JS I see: 1) Project, that has been written in 8 hours in total: https://github.com/igor-bezkrovny/jsprofiler

I was inspired by deprecated yahoo profiler, but yui profiler very limited. So I used idea(such idea is used in john resig inheritance and stacktrace.js and so on) and implemented very useful profiler for SmartTV (JS). Please do not be angry on widget code - it is constantly under small improvements of information output.

Method: Walk recursively and instrument every found function and it's prototype. Minuses: a) anonymous function can't be instrumented automatically b) you should tell profiler which object/objects should be walked by profiler before html5 application start To instrument all global methods/classes/objects just use 'window' as root object

If you will be interested I have much more fresh and updated version (not published it yet).

2) Method: take AST(with Esprima for example), walk recursively, add call to small instrumentation utility methods before and after all functions and even to getters/setters and read-only properties, after that remove all original code in runtime, convert AST back to JS string (Esprima supports that) and eval all that code. We have all methods instrumented. Minuses: too complex implementation, possible unknown number of restrictions for eval'ing code on real projects, and memory consuming during instrumentation/ast generation/...

Also there is another model of profiling code, as it is done in chrome/firefox profilers. Difference between https://github.com/igor-bezkrovny/jsprofiler and chrome/firefox is that jsprofiler constantly updates and allows to profile dynamic problems in js games, it allows to see changes during game play without need to manual compare of snapshots of chrome's profilers every second.

It is very good idea to add profiler to console.io. What do you think?

nkashyap commented 10 years ago
nkashyap commented 10 years ago
nkashyap commented 10 years ago