Postcards from the Fridge

Sunday, July 09, 2006



Alright, a few post back, people have been asking me how to reproduce the work that I've been doing.

First, I've be relying heavily on Federico's code to do the tracing/visualization. This requires that gnome is run within strace.

0) Boot your machine to init level 3.

This will allow us to run startx, run through the gnome initialization cycle, and then end without adding stuff to gdm.

1) Sprinkle the gnome code with calls to program_log.

First, I've created a header that I can include with the following code:

#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

static void program_log (const char *format, ...)
va_list args;
char *formatted, *str;
struct timeval current_time;
if (getenv("GNOME_PROFILING"))
va_start (args, format);
formatted = g_strdup_vprintf (format, args);
va_end (args);
str = g_strdup_printf ("MARK: %s: %s",g_get_prgname(), formatted);
g_free (formatted);
access (str, F_OK);
g_free (str);

In nautilus-main.c in the first non-declaration line of 'main()' I have added:
program_log("%s Starting_Nautilus",__FUNCTION__);
In nautilus-icon-container.c in the first non declaration line of 'expose_event()', I have added:
program_log("icon_container expose_event");

This is enough to time the nautilus startup.

NOTE: This implementation is pretty hacky right now. This should probably be pushed into a common library (glib?) somewhere, but right now it is handy because I don't have to rely on every application that I want to profile including a particular library. I just add the "#include" and drop in some calls to "program-log" and I am off to the races.

2) Add stracing to xinitrc.

When you launch gnome, you have to make sure strace is running, so I 've added calls to strace into my xinit file (for reasons described in previous posts) .

Add something similar to the following to your ".xinitrc":
"exec strace -e clone,execve,open,access -ttt -f -o /tmp/gnome.log /home/gnome/bin/jhbuild run gnome-session"
3) Start GNOME with profiling turned on.

Now you can launch gnome with tracing turned on:
env GNOME_PROFILING=1 startx
After this command has completed, an strace of the session will be sitting in tmp.

4) Add a command to the session startup which will automatically teardown the session.

I've added the following shell script to my gnome-session startup: (You may have to adjust the initial sleep if things take longer than 5 seconds to startup.)
sleep 5
gnome-session-save --kill
sleep 5
killall X
5) Turn off the "IS it ok to logout prompt"?
Run "gnome-session-properties" an disable 'ask on logout".

Now, you should be able to run startx, have gnome start, and then exit back to the initial prompt.

6) Script the automatic timing and analysis of the startup/teardown.

First, I created a script to automatically determine the time to start the session and time to start nautilus and output that in a file called "summary":
(The script is called
import sys
import string

for line in sys.stdin:

__if line.find("Starting_Nautilus")!=-1:
____start_time = string.atof(line.split()[1])

__if line.find('execve("/home/gnome/bin/jhbuild')!=-1:
____session_start_time = string.atof(line.split()[1])

__if (line.find("icon_container expose_event")!=-1) and found_event==0:
____expose_time = string.atof(line.split()[1])

print "Start->Icon_Expose (ses):", expose_time-session_start_time, "(Naut):", expose_time-start_time
Next, I created a script to run this AND Federico's graphical analysis tool. It will create a directory with the time of the run, a copy of the log, and the picture of the execution.

I call it "":
while /bin/true
DATE=`date +%Y%m%d%H%M%S`
mkdir $DATE
env GNOME_PROFILING=1 startx
cp /tmp/gnome.log $DATE/
~/ $DATE/gnome.log -o $DATE/output-$DATE.png
rm -f /tmp/*.log
cat $DATE/gnome.log | ./ | tee $DATE/summary
sleep 3
7) Run for infinity.
Now, you can run this for a long time, and just let gnome startup/teardown. After 40 or so runs, I stop the loop, and see what happened.

8) Analyze the results

Next I gather all of the results into a single file with:
"grep Nau */summary > results.csv"
I can then load this file into gnumeric and graph the results.

9) (Extra) Prune the startup of the session.

Currently, I am just starting nautilus (no WM, and no gnome-panel).

I have a ~/.gnome2/session file that looks as follows:
1,RestartCommand=nautilus --no-default-window --sm-client-id default1
That's all for right now. I found something interesting, but I'll save that for the next post.



  • Thanks a lot for this Cookbook !

    By Blogger Moksha, at 12:59 AM  

  • no:
    if line.find("Starting_Nautilus")!=-1:

    if "Starting_Nautilus" in line:

    By Anonymous Justin, at 12:07 PM  


    By Anonymous Anonymous, at 9:01 PM  

  • By Anonymous Anonymous, at 2:50 PM  

  • which gay actors have come out Really? amazing. STUDY theme! blog in my favorites Well of course tin ... Really? amazing. Who is mulberry? All true, but how else? IMHO, the author is wrong I do not know about you, but I like it! There is.

    By Anonymous Anonymous, at 2:43 AM  

Post a Comment

<< Home