Using Federicos timeline tool with Mono

While figuring out why Tomboy takes quite a lot of time to start (BGO #567989, hint: it’s not the lack of SQLite), I was reminded of Lord Kelvins old saying: “To measure is to know”.

Thinking how to quantify this, it occured to me that the GNOME community has the perfect tool for figuring out slowness: Federicos awesome timeline tool. All I had to do is figure out how to use this with Mono, which is very easy, as you will see below.

Tomboy startup
Tomboy startup (click for a full size graph)

Federico uses a nice trick using syscalls, which are logged using strace. Fortunately, this is very easy to reproduce with C#.

  1. First we need to generate them, add something like this to your program:

    public class TraceLogger {
        public static void trace (string group, string format, params object[] args)
        {
            string message = String.Format (format, args);
            string str = String.Format ("MARK: {0}: {1}", group, message);
            Mono.Unix.Native.Syscall.access(str, Mono.Unix.Native.AccessModes.F_OK);
        }
    }
  2. Liberally sprinkle tracing statements in your code, like this: TraceLogger.trace("Main", "Starting main loop");
  3. Modify your startup script so that the line containing “exec mono ...” now reads “exec strace -ttt -f -o /tmp/timeline.strace mono ....“.
  4. Use Federicos script to plot it: python plot-timeline.py -o graph.png /tmp/timeline.strace.

That’s all there is to it. The attentive reader will notice that I used the tracing format a bit differently, rather than printing the program name, I use a group parameter. This makes the graph easier to interpret: if you add too many tracing statements, it might be hard to see where the big gaps are. Hijacking the color coding avoids this interpretation difficulty.

Now hurry up and make your Mono apps even faster!

This entry was tagged , , . Bookmark the permalink.

3 Responses to Using Federicos timeline tool with Mono

  1. Vadim P. says:

    Hope people take you up on this. I notice having the tomboy applet in my panel, and thus having to start tomboy & mono, adds 2-3 seconds to the “usable desktop” time.

  2. Miguel de Icaza says:

    Additionally, you could sprinkle things in your code and put this annotation on the method trace:

    [Conditional("TRACE")]
    void trace (….)

    Then when you compile the code with -d:TRACE the calls to Trace.trace would run, but if you do not include the -D, then the method would not be compiled in.

  3. RubenV says:

    Didn’t knew that was possible, that’s a very neat trick miguel!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>