Javascript profile in Firefox

(I know some people have already asked js profile questions, but this is not what I need if I understand them correctly.)

I would like to track javascript execution to collect information about 1) which function is called, 2) the time when the function is called, and 3) the time the function is executed.

I want to collect information on the Internet (by expanded code), but not internally. So the compromise should be easy. Also, I don't want to manually add a line before and after the function is called. However, it would be great if there was a way that could dynamically process the code.

Thanks in advance!

+2


source to share


3 answers


I don't think there is a system where JavaScript will automatically keep track of when a function starts and when a function stops. You will most likely have to add yourself. If that's what you want, you might want to consider using PHP to serve up your JavaScript, and use a regex to find the start and end of each function using regex or something.

Your RegExp might look like this (completely untested, so you'll have to experiment):

/function [A-Za-z_$][A-Za-z0-9_$]*{(.*?)}/i

      

Once you have access to the inside of the function, you can replace that value with a function to keep track of its start and end, wrapped around the original function definition.

It's helpful to do exactly what you want without worrying about how to change your js code. This is what the server will handle in its entirety.

Either this, or instead of directly calling the function, use a wrapper function:



function wrapFunction( func, context, argList )
{ 
    // Replace with however you are storing this.
    console.log( new Date().getTime() );
    func.apply( context, argList );
    console.log( new Date().getTime() );
}

      

This can be much cleaner than having a server updating your JS for you. Unfortunately, this also means having to rewrite the JS manually.

My recommendation would be to just adapt the logging syntax and use it. Most recorders will display the timestamp, context, level, and specific message. If you just call the logger at the beginning and end of the function, it will do exactly what you are looking for. Also, since many of these are customizable, you will be able to display it in the JS console in Firefox, send information to the server, or disconnect entirely if you choose.

There is a list of JS loggers here:

JavaScript logs

This unfortunately requires you to manually update everything, but it seems like the easiest way to get 90% of what you're looking for out of the box.

+3


source


Maybe a FireBug profiler can help you track down slow functions.



Shown here is a video detailing the profiling options. (Index: 3:20).

+1


source


console.profile([title])
//also see
console.trace()

      

http://getfirebug.com/wiki/index.php/Console_API

+1


source







All Articles