Re: Unaccounted time during containers' lifecycle



(dropping gtk-list)

2007/4/8, Matt Hoosier <matt hoosier gmail com>:
On 4/8/07, Ross Burton <ross burtonini com> wrote:
> [Cycle 36]: construction finished at 0.0025 sec
> [Cycle 36]: style set at 0.0032 sec
> [Cycle 36]: requisition computed at 0.0075 sec
> [Cycle 36]: size allocated at 0.0080 sec
> [Cycle 36]: realized at 0.0081 sec
> [Cycle 36]: mapped at 0.0088 sec
> [Cycle 36]: exposed at 0.0726 sec
>
> Hm, style set isn't that slow.  Hm, for some reason I'm not getting the
> second requisition/size-allocated pair after the window was mapped.
> Where you using a standard theme, or something custom?  (I'm using
> Darkilouche, which is based on Clearlooks).

Those tests were run with the stock Gtk 'Default' theme. I also did a
quick check just now to make sure that the stripped down version of
gnome-settings-daemon isn't somehow producing a spurious 'Default' ->
'Default' theme transition. It wasn't; the timings were the same both
with and without that daemon running in the background.

I tested with both Clearlooks and stock theme, and also got just one
size-request iteration (with a recent gtk+ version if that should
matter).

One thing I'm wondering is what is your window manager. You said you
were on ARM so first wm that leaps into mind is Matchbox, which most
likely will reconfigure the window (as it allows only fullscreen apps)
when it is mapped. Configure-events seem like good candidates for
causing size calculation, so you might want to check for these.

The attached version of the program connects to the configure-event
signal and prints it out, revealing that I actually get two of these
with metacity (wonder why) between map expose. The size doesn't change
and I guess matches the widget's idea of it's size so no
recalculation, but maybe this is not the case for you?

--
Kalle Vahlman, zuh iki fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi
#include <glib.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtktable.h>
#include <gtk/gtkwindow.h>
#include <stdio.h>

#define ROWS    5
#define COLUMNS 5

static GTimer* timer = NULL;
static int kill_window_idle_handle = -1;
static int cycle_number = 0;

static void     window_realize_cb       (GtkWidget *, gpointer);
static void     window_size_allocate_cb (GtkWidget *, GtkAllocation*, gpointer);
static void     window_size_request_cb  (GtkWidget *, GtkRequisition*, gpointer);
static void     window_map_cb           (GtkWidget *, gpointer);
static gboolean window_expose_cb        (GtkWindow *, GdkEventExpose * e);
static gboolean window_configure_cb     (GtkWindow *, GdkEventConfigure * e);

static GtkWidget *
create_table_item (guint index)
{
    GtkWidget * item = NULL;

    item = gtk_vbox_new (FALSE, 0);

    GtkWidget * top = gtk_hbox_new (FALSE, 0);
    GtkWidget * bottom = gtk_hbox_new (FALSE, 0);

    gtk_container_add (GTK_CONTAINER (item), top);
    gtk_container_add (GTK_CONTAINER (item), bottom);

    gtk_container_add (GTK_CONTAINER (top),
                       gtk_button_new ());
    gtk_container_add (GTK_CONTAINER (top),
                       gtk_alignment_new (0.5, 0.5, 0.0, 0.0));
    gtk_container_add (GTK_CONTAINER (bottom),
                       gtk_label_new (""));
    gtk_container_add (GTK_CONTAINER (bottom),
                       gtk_check_button_new ());

    return item;
}

static GtkWidget *
create_window ()
{
    guint i, j;
    GtkWidget * window;
    GtkWidget* table;
    GtkWidget* item;

    if (!timer)
        timer = g_timer_new ();

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    table = gtk_table_new (ROWS, COLUMNS, FALSE);

    for (i = 0; i < ROWS; i++)
    {
        for (j = 0; j < COLUMNS; j++)
        {
            item = create_table_item (i * COLUMNS + j);
            gtk_table_attach_defaults (GTK_TABLE (table),
                                       item,
                                       j,
                                       j + 1,
                                       i,
                                       i + 1);

        }
    }

    gtk_container_add (GTK_CONTAINER (window), table);
    
    g_signal_connect (G_OBJECT (window), "realize",
                      G_CALLBACK (window_realize_cb), NULL);
    g_signal_connect (G_OBJECT (window), "map",
                      G_CALLBACK (window_map_cb), NULL);
    g_signal_connect (G_OBJECT (window), "configure-event",
                      G_CALLBACK (window_configure_cb), NULL);
    g_signal_connect (G_OBJECT (window), "size-request",
                      G_CALLBACK (window_size_request_cb), NULL);
    g_signal_connect (G_OBJECT (window), "size-allocate",
                      G_CALLBACK (window_size_allocate_cb), NULL);
    g_signal_connect (G_OBJECT (window), "expose-event",
                      G_CALLBACK (window_expose_cb), NULL);
    
    cycle_number++;

    if (timer)
    {
        printf ("[Cycle %d]: construction finished at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
    }

    return window;
}

static gboolean
kill_window (GtkWindow * win)
{
    GtkWidget * new_window;
    new_window = create_window ();
    gtk_widget_show_all (new_window);

    gtk_widget_destroy (GTK_WIDGET (win));

    kill_window_idle_handle = -1;
    return FALSE;
}

static void
window_realize_cb (GtkWidget *w, gpointer unused)
{
    if (timer)
    {
        printf ("[Cycle %d]: realized at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
    }
}

static void
window_map_cb (GtkWidget *w, gpointer unused)
{
    if (timer)
    {
        printf ("[Cycle %d]: mapped at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
    }
}

static void
window_size_allocate_cb (GtkWidget *w, GtkAllocation* unused1, gpointer unused2)
{
    if (timer)
    {
        printf ("[Cycle %d]: size allocated at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
    }
}

static void
window_size_request_cb (GtkWidget *w, GtkRequisition* unused1, gpointer unused2)
{
    if (timer)
    {
        printf ("[Cycle %d]: requisition computed at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
    }
}

static gboolean
window_configure_cb     (GtkWindow *w, GdkEventConfigure * e)
{
    if (timer)
    {
        printf ("[Cycle %d]: configured to %i,%i %ix%i at %3.4f sec\n",
                cycle_number,
                e->x, e->y, e->width, e->height,
                (float) g_timer_elapsed (timer, NULL));
    }
}

static gboolean
window_expose_cb (GtkWindow *win, GdkEventExpose * e)
{
    if (kill_window_idle_handle == -1)
    {
      kill_window_idle_handle = g_idle_add ((GSourceFunc) (kill_window), (gpointer) win);
    }

    if (timer)
    {
        printf ("[Cycle %d]: exposed at %3.4f sec\n",
                cycle_number,
                (float) g_timer_elapsed (timer, NULL));
        g_timer_destroy (timer);
        timer = NULL;
    }

    return FALSE;
}

int
main (int argc, char * argv[])
{
    GtkWidget* window;
    double time_initialization;
    double time_construction;


    gtk_init(&argc, &argv);

    timer = g_timer_new ();
    window = create_window ();

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]