How to access JavaScript execution trace at runtime in Firefox?

525 views
Skip to first unread message

SK

unread,
Mar 15, 2013, 4:17:07 AM3/15/13
to fir...@googlegroups.com

I want to know how to access JavaScript execution trace at runtime. I saw Firebug can do something like this:

enter image description here

Refer to the image above, all the line numbers executed are highlighted in green. They are achieved at runtime. I guess there must be some way to access those info from the JavaScript engine used by the browser.

Say now I want to build a firebug plugin to access those info and examine all the variables in each executed line at the runtime, how should I do?


Thank you!

Jan Honza Odvarko

unread,
Mar 15, 2013, 11:05:03 AM3/15/13
to Firebug
Firebug is currently using JSD (jsdIDebuggerService) to figure out,
which line
is executable. However, the plan is to switch to JSD2 (work in
progress)
https://wiki.mozilla.org/Debugger

You should also base your extension on JSD2

Look for getLineOffsets(line) and getOffsetLine(offset) in the
Debugger document.
I didn't test it, but I think that if getLineOffset returns null, the
line is not executable.

Honza

MMTY

unread,
Mar 19, 2013, 2:34:12 PM3/19/13
to fir...@googlegroups.com
Thank you. Is it possible to get the line execution trace in order? getLineOffsets() is just used to tell whether the line is executed or not.

Thanks

--
--
You received this message because you are subscribed to the Google
Groups "Firebug" group.
To post to this group, send email to fir...@googlegroups.com
To unsubscribe from this group, send email to
firebug+u...@googlegroups.com
For more options, visit this group at
https://groups.google.com/forum/#!forum/firebug

---
You received this message because you are subscribed to a topic in the Google Groups "Firebug" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebug/MQJCrYSwT9k/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to firebug+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Jan Honza Odvarko

unread,
Mar 20, 2013, 3:44:43 AM3/20/13
to Firebug

On Mar 19, 7:34 pm, MMTY <kheathe...@gmail.com> wrote:
> Thank you. Is it possible to get the line execution trace in
> order?
What do you mean by order?

> getLineOffsets() is just used to tell whether the line is executed
> or not.
Note that it should say whether the line is "executable" (not
executed)

Honza


>
> Thanks

MMTY

unread,
Mar 20, 2013, 4:43:05 PM3/20/13
to fir...@googlegroups.com
Hi Honza

Thank you for your reply.

Look at this example:

#1 function callMe(){ 
#2 if(true){
#3   var a = 1;
#4   var b = 2;
#5 }else{
#6   var c = 10;
#7 }
#8 }
#9 callMe();

I want to develop a extension for firebug to add some debugging functionality that can give the execution trace in order, so the result will look like this:
#9 -> #1 -> #2 -> #3 -> #4

I looked through the firebug code and the JSD component. The getLineOffsets() only check if the line is valid for execution.
A way to approach this is to set breakpoints on all lines and keep resuming the JS. So when the breakpoints are reached, the JSD setbreakpointHook can tell the frame info. However, it is quite slow and unpractical.

Any thoughts? Thank you!

MMTY

unread,
Mar 20, 2013, 4:44:07 PM3/20/13
to fir...@googlegroups.com
And on the reslut(#9 -> #1 -> #2 -> #3 -> #4), I will also want to know the time the line is executed. 

Thanks!

Jan Honza Odvarko

unread,
Mar 22, 2013, 11:15:09 AM3/22/13
to Firebug
> > A way to approach this is to set breakpoints on all lines and keep
> > resuming the JS. So when the breakpoints are reached, the JSD
> > setbreakpointHook can tell the frame info. However, it is quite slow
> > and unpractical.
I don't know about any better way.

> I will also want to know the time the line is executed.
There is now time-stamp coming from JSD2 so, you'll need to
use (new Date()).getTime()

You can also take a look at the built in profiler...
https://developer.mozilla.org/en-US/docs/Performance/Profiling_with_the_Built-in_Profiler

Honza

Simon Lindholm

unread,
Mar 22, 2013, 2:11:56 PM3/22/13
to fir...@googlegroups.com
(new Date()).getTime()
 
(Or performance.now().)

Jan Honza Odvarko

unread,
Mar 22, 2013, 2:19:40 PM3/22/13
to Firebug
I have yet asked on IRC and got this answer:

Honza: take a look at JSOPTION_PCCOUNT, djf and I used that to
implement a command line coverage tool called covermonkey a while back

I didn't checked that out, but figured out that you could be
interested...

Honza

On Mar 22, 7:11 pm, Simon Lindholm <simon.lindhol...@gmail.com> wrote:
> > (new Date()).getTime()
>
> (Or performance.now().)
>
> Den fredagen den 22:e mars 2013 kl. 16:15:09 UTC+1 skrev Jan Honza Odvarko:
>
>
>
>
>
>
>
>
>
> > > > A way to approach this is to set breakpoints on all lines and keep
> > > > resuming the JS. So when the breakpoints are reached, the JSD
> > > > setbreakpointHook can tell the frame info. However, it is quite slow
> > > > and unpractical.
> > I don't know about any better way.
>
> > > I will also want to know the time the line is executed.
> > There is now time-stamp coming from JSD2 so, you'll need to
> > use (new Date()).getTime()
>
> > You can also take a look at the built in profiler...
>
> >https://developer.mozilla.org/en-US/docs/Performance/Profiling_with_t...
> > > >> > > To post to this group, send email to fir...@googlegroups.com<javascript:>
> > > >> > > To unsubscribe from this group, send email to
> > > >> > > firebug+u...@googlegroups.com <javascript:>
> > > >> > > For more options, visit this group at
> > > >> > >https://groups.google.com/forum/#!forum/firebug
>
> > > >> > > ---
> > > >> > > You received this message because you are subscribed to a topic
> > in the
> > > >> > > Google Groups "Firebug" group.
> > > >> > > To unsubscribe from this topic, visit
>
> >https://groups.google.com/d/topic/firebug/MQJCrYSwT9k/unsubscribe?hl=en.
> > > >> > > To unsubscribe from this group and all its topics, send an email
> > to
> > > >> > > firebug+u...@googlegroups.com <javascript:>.
> > > >> > > For more options, visithttps://groups.google.com/groups/opt_out.
>
> > > >> --
> > > >> --
> > > >> You received this message because you are subscribed to the Google
> > > >> Groups "Firebug" group.
> > > >> To post to this group, send email to fir...@googlegroups.com<javascript:>
> > > >> To unsubscribe from this group, send email to
> > > >> firebug+u...@googlegroups.com <javascript:>
> > > >> For more options, visit this group at
> > > >>https://groups.google.com/forum/#!forum/firebug
>
> > > >> ---
> > > >> You received this message because you are subscribed to a topic in
> > the
> > > >> Google Groups "Firebug" group.
> > > >> To unsubscribe from this topic, visit
>
> >https://groups.google.com/d/topic/firebug/MQJCrYSwT9k/unsubscribe?hl=en.
> > > >> To unsubscribe from this group and all its topics, send an email to
> > > >> firebug+u...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages