7

I would like to measure how much time it takes for some softwares to start.

I know the command time but in the case of firefox (iceweasel for me on Debian), this command prints only the time I let firefox open. If I launch:

$ time iceweasel www.google.com

I will have a startup time only after I closed firefox and this time will only indicate how long I left firefox opened. For example:

real    0m50.565s
user    0m4.276s
sys 0m0.248s

How can I know exactly how much firefox need to start?

  • 5
    Define "start". Is it when it opens its first window, when it will first respond to mouse clicks, when it finishes loading the web site, etc. – derobert Feb 4 '15 at 18:31
  • @derobert By "start" I mean to see the window. In fact, I don't really care, I just want a exact way of measuring the "startup" (whatever it is) to be able to do some tests (i.e. removing some addons and see if there is a improvement). – ppr Feb 4 '15 at 19:48
  • 1
    You could also try this extension: about:startup. – don_crissti Feb 4 '15 at 20:06
6

This is hacky and unscriptable.

Firefox can run javascript via command line like so:

firefox "javascript:alert(Date.now())"

That will open Firefox and run javascript that pops up a message box containing the current epoch time to the millisecond.

You can get the number of milliseconds elapsed in epoch time at your command line with

date +%s%N | cut -b1-13

So to answer your question, run

date +%s%N | cut -b1-13; iceweasel "javascript:alert(Date.now())"

Then subtract the number in your terminal from the number in Firefox. This gives you the number of milliseconds Firefox took to open and display some basic javascript.

Sources:

3

You can use some tool which can get window id associated with PID, and wait until that window is created. The process id of previously started program is available in $! variable.

As an example - using wmctrl one can get list of all windows and check if any of them is started by given PID:

$ wmctrl -lp
0x00e00003 -1 397    jjmach sawfishpager
0x01200003  6 399    jjmach wmctrl -lp jimmij@jjmach: /proc
0x0180004b  0 655    jjmach emacs@jjmach.jj
0x02800078  7 680    jjmach How to measure Firefox's startup time? - Mozilla Firefox

Window id is in first column, and process id in third, so we need to pipe it to awk in order to check if given process id has associated window.

wmctrl -lp | awk -v pid="$!" '$3==pid{print "Window is created with id "$1}'

Now we need to put it in some loop and measure the time until above command will end successfully:

firefox & time (while wmctrl -lp | awk -v pid="$!" '$3==pid{exit 1}'; do :; done)

So we start firefox and immediately start a loop which in body does nothing (:) and ends when awk returns non-zero value.

2
  1. start a listening netcat in the background
  2. call firefox to connect it
  3. wait it with a wait bash builtin.
  4. finally kill everything nc -l 64738 & firefox http://127.0.0.1:64738 & wait <...yet to be solved that only the nc should be waited for...> killall firefox <..yet to be solved to not kill your girlfriends browser>
2

AFAIK the startup time in milliseconds can be found here:

about:telemetry -> Simple Measurements -> firstPaint

1

You can read the measured startup time from the configuration (about:config):

browser.slowStartup.averageTime

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.