all repos — tint2 @ 7c3951e3a00a6ef257a505b623508de0c40708cd

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

systray: Profiling code. Export environment variable SYSTRAY_PROFILING=1 when running tint2 to enable it
o9000 o9000
commit

7c3951e3a00a6ef257a505b623508de0c40708cd

parent

552f060612bbd988f476b64a3f4de065a8bea2c4

3 files changed, 66 insertions(+), 6 deletions(-)

jump to
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -52,6 +52,7 @@ int systray_max_icon_size;

int systray_monitor; int chrono; int systray_composited; +int systray_profile; // background pixmap if we render ourselves the icons static Pixmap render_background;

@@ -67,6 +68,7 @@ systray.area._draw_foreground = draw_systray;

systray.area._on_change_layout = on_change_systray; systray.area.size_mode = SIZE_BY_CONTENT; systray.area._resize = resize_systray; + systray_profile = getenv("SYSTRAY_PROFILING") != NULL; } void cleanup_systray()

@@ -125,6 +127,8 @@

void draw_systray(void *obj, cairo_t *c) { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); if (systray_composited) { if (render_background) XFreePixmap(server.dsp, render_background);

@@ -138,6 +142,8 @@

int resize_systray(void *obj) { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); Systraybar *sysbar = obj; GSList *l; int count;

@@ -155,7 +161,8 @@ if (((TrayWindow*)l->data)->hide)

continue; count++; } - //printf("count %d\n", count); + if (systray_profile) + printf("%s:%d number of icons = %d\n", __FUNCTION__, __LINE__, count); if (panel_horizontal) { int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;

@@ -178,6 +185,8 @@

void on_change_systray (void *obj) { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); // here, systray.area.posx/posy are defined by rendering engine. so we can calculate position of tray icon. Systraybar *sysbar = obj; if (sysbar->icons_per_column == 0 || sysbar->icons_per_row == 0)

@@ -203,7 +212,8 @@ continue;

traywin->y = posy; traywin->x = posx; - // printf("systray %d %d : pos %d, %d\n", traywin->parent, traywin->win, posx, posy); + if (systray_profile) + printf("%s:%d win = %lu, parent = %lu, x = %d, y = %d\n", __FUNCTION__, __LINE__, traywin->win, traywin->parent, posx, posy); traywin->width = sysbar->icon_size; traywin->height = sysbar->icon_size; if (panel_horizontal) {

@@ -237,6 +247,8 @@ // systray protocol

void start_net() { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); if (net_sel_win) { // protocol already started if (!systray_enabled)

@@ -294,6 +306,7 @@ return;

} //fprintf(stderr, "tint2 : systray started\n"); + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); XClientMessageEvent ev; ev.type = ClientMessage; ev.window = server.root_win;

@@ -310,6 +323,8 @@

void net_message(XClientMessageEvent *e) { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); unsigned long opcode; Window win;

@@ -338,7 +353,8 @@

void stop_net() { - //fprintf(stderr, "tint2 : systray stopped\n"); + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); if (systray.list_icons) { // remove_icon change systray.list_icons while(systray.list_icons)

@@ -358,6 +374,8 @@

gboolean error; int window_error_handler(Display *d, XErrorEvent *e) { + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); error = TRUE; if (e->error_code != BadWindow) { printf("systray: error code %d\n", e->error_code);

@@ -406,6 +424,8 @@

gboolean add_icon(Window win) { + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, win); TrayWindow *traywin; Panel *panel = systray.area.panel; int hide = 0;

@@ -447,7 +467,7 @@ break;

} } } - //printf("add_icon: %d, pid %d, %d\n", win, pid, num_empty_same_pid); + printf("add_icon: %lu, pid %d, %d\n", win, pid, num_empty_same_pid); // Create the parent window that will embed the icon XWindowAttributes attr;

@@ -498,6 +518,9 @@ if (!traywin->hide && !panel->is_hidden)

XMapRaised(server.dsp, traywin->parent); XSync(server.dsp, False); + if (systray_profile) + printf("[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); + // Resize and redraw the systray systray.area.resize = 1; systray.area.redraw = 1;

@@ -509,6 +532,8 @@ }

gboolean reparent_icon(TrayWindow *traywin) { + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); if (traywin->reparented) return TRUE;

@@ -540,8 +565,6 @@ remove_icon(traywin);

return FALSE; } - traywin->reparented = 1; - // Embed into parent { XEvent e;

@@ -618,11 +641,18 @@ XMoveResizeWindow(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height);

XSync(server.dsp, False); + traywin->reparented = 1; + + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); + return TRUE; } void remove_icon(TrayWindow *traywin) { + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); Panel* panel = systray.area.panel; // remove from our list

@@ -667,6 +697,8 @@ }

void systray_reconfigure_event(TrayWindow *traywin) { + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); Panel* panel = systray.area.panel; //printf("move tray %d\n", traywin->x);

@@ -687,6 +719,8 @@ }

void systray_destroy_event(TrayWindow *traywin) { + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); remove_icon(traywin); }

@@ -696,6 +730,9 @@ {

// we end up in this function only in real transparency mode or if systray_task_asb != 100 0 0 // we made also sure, that we always have a 32 bit visual, i.e. we can safely create 32 bit pixmaps here TrayWindow* traywin = t; + + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); // wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms struct timespec now;

@@ -842,6 +879,9 @@ panel_refresh = 1;

refresh_systray = 1; } + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); + return; on_error:

@@ -860,6 +900,8 @@

void systray_render_icon(void* t) { TrayWindow* traywin = t; + if (systray_profile) + printf("[%f] %s:%d win = %lu\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win); if (!traywin->reparented) { if (!reparent_icon(traywin)) return;
M src/util/timer.csrc/util/timer.c

@@ -445,3 +445,16 @@ free(t1);

} free(mth); } + +double profiling_get_time_old_time = 0; +double profiling_get_time() +{ + struct timespec cur_time; + clock_gettime(CLOCK_MONOTONIC, &cur_time); + double t = cur_time.tv_sec + cur_time.tv_nsec * 1.0e-9; + if (profiling_get_time_old_time == 0) + profiling_get_time_old_time = t; + double delta = t - profiling_get_time_old_time; + profiling_get_time_old_time = t; + return delta; +}
M src/util/timer.hsrc/util/timer.h

@@ -73,4 +73,9 @@ gint compare_timespecs(const struct timespec* t1, const struct timespec* t2);

struct timespec add_msec_to_timespec(struct timespec ts, int msec); +/** Returns the time difference in seconds between the current time and the last time this function was called. + * At the first call returns zero. +**/ +double profiling_get_time(); + #endif // TIMER_H