[memprof: 43/76] Integrate the detailwin into the main GtkNotebook
- From: Holger Hans Peter Freyther <hfreyther src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [memprof: 43/76] Integrate the detailwin into the main GtkNotebook
- Date: Sun, 13 Jun 2010 03:41:51 +0000 (UTC)
commit 8ff7997a6bb1d74f69a6ece35ecc371ab78ea94c
Author: Tomasz Mon <desowin gmail com>
Date: Sun Apr 6 17:26:34 2008 +0200
Integrate the detailwin into the main GtkNotebook
2009-10-25 Holger Hans Peter Freyther <zecke selfish org>
* memprof.glade: Introduce two tabs and GtkDrawingArea
* src/detailwin.c: Remove widget creation and the special struct
(dw_draw_memstats):
(dw_draw_memmap):
(on_da1_expose_event):
(on_da2_expose_event):
(dw_update):
* src/gui.h: Include the memstat in the ProcessWindow
* src/main.c: Integrate the DetailWin
(process_window_destroy):
(process_window_new):
Taken from memprof-revised and authored by Tomasz Mon <desowin gmail com>
Signed-off-by: Holger Hans Peter Freyther <zecke selfish org>
memprof.glade | 114 ++++++++++++++++++++++++++++++++++++++
src/detailwin.c | 162 +++++++++---------------------------------------------
src/gui.h | 9 ++-
src/main.c | 10 +++-
4 files changed, 154 insertions(+), 141 deletions(-)
---
diff --git a/memprof.glade b/memprof.glade
index 4601e6b..68c6524 100644
--- a/memprof.glade
+++ b/memprof.glade
@@ -1250,6 +1250,120 @@
<property name="type">tab</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkFrame" id="frame2">
+ <property name="border_width">4</property>
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="label_yalign">0.5</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+
+ <child>
+ <widget class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">1</property>
+ <property name="yscale">1</property>
+ <property name="top_padding">0</property>
+ <property name="bottom_padding">0</property>
+ <property name="left_padding">0</property>
+ <property name="right_padding">0</property>
+
+ <child>
+ <widget class="GtkDrawingArea" id="time-graph">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="tab_expand">False</property>
+ <property name="tab_fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label67">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Time Graph</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkFrame" id="frame3">
+ <property name="border_width">4</property>
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="label_yalign">0.5</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+
+ <child>
+ <widget class="GtkAlignment" id="alignment3">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">1</property>
+ <property name="yscale">1</property>
+ <property name="top_padding">0</property>
+ <property name="bottom_padding">0</property>
+ <property name="left_padding">0</property>
+ <property name="right_padding">0</property>
+
+ <child>
+ <widget class="GtkDrawingArea" id="mem-map">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="tab_expand">False</property>
+ <property name="tab_fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label66">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Memory Usage Maps</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="position">3</property>
diff --git a/src/detailwin.c b/src/detailwin.c
index 200fbfd..97be3c1 100644
--- a/src/detailwin.c
+++ b/src/detailwin.c
@@ -41,23 +41,14 @@
#include "gui.h"
#include "memprof.h"
-#define MEMSTATS 4096
-
-typedef struct _DW
-{
- ProcessWindow *pwin;
- GtkWidget *win, *da1, *da2;
- guint memstats[MEMSTATS][2];
-} DW;
-
static void
-dw_draw_memstats(DW *dw)
+dw_draw_memstats(ProcessWindow *pwin)
{
GtkWidget *widget;
GdkPixmap *pixmap;
gint64 i, j, x, y, w, h, hh;
- widget = dw->da1;
+ widget = pwin->time_graph;
w = widget->allocation.width;
h = widget->allocation.height;
if (!widget->window) return;
@@ -70,8 +61,8 @@ dw_draw_memstats(DW *dw)
{
x = w - i;
if (x < 0) break;
- if (dw->pwin->usage_high > 0)
- hh = (h * dw->memstats[i][1]) / dw->pwin->usage_high;
+ if (pwin->usage_high > 0)
+ hh = (h * pwin->memstats[i][1]) / pwin->usage_high;
else
hh = 0;
y = h - hh;
@@ -79,8 +70,8 @@ dw_draw_memstats(DW *dw)
widget->style->base_gc[GTK_STATE_SELECTED],
TRUE,
x, y, 1, hh);
- if (dw->pwin->usage_high > 0)
- hh = (h * dw->memstats[i][0]) / dw->pwin->usage_high;
+ if (pwin->usage_high > 0)
+ hh = (h * pwin->memstats[i][0]) / pwin->usage_high;
else
hh = 0;
y = h - hh;
@@ -89,7 +80,7 @@ dw_draw_memstats(DW *dw)
TRUE,
x, y, 1, hh);
}
- if (dw->pwin->usage_high > 0)
+ if (pwin->usage_high > 0)
{
GdkGC *gc;
@@ -97,10 +88,10 @@ dw_draw_memstats(DW *dw)
gdk_gc_copy(gc, widget->style->dark_gc[GTK_STATE_NORMAL]);
gdk_gc_set_line_attributes(gc, 0, GDK_LINE_ON_OFF_DASH,
GDK_CAP_BUTT, GDK_JOIN_MITER);
- for (j = 0, i = 0; i < dw->pwin->usage_high; i += (256 * 1024), j++)
+ for (j = 0, i = 0; i < pwin->usage_high; i += (256 * 1024), j++)
{
if (j > 3) j = 0;
- y = h - ((i * h) / dw->pwin->usage_high);
+ y = h - ((i * h) / pwin->usage_high);
if (j == 0)
gdk_draw_line(pixmap, widget->style->dark_gc[GTK_STATE_NORMAL],
0, y, w, y);
@@ -177,7 +168,7 @@ dw_draw_memmap_foreach(gpointer key, gpointer value, gpointer data)
}
static void
-dw_draw_memmap(DW *dw)
+dw_draw_memmap(ProcessWindow *pwin)
{
GtkWidget *widget;
GdkPixmap *pixmap;
@@ -185,7 +176,7 @@ dw_draw_memmap(DW *dw)
Mem mem;
GList *l;
- widget = dw->da2;
+ widget = pwin->mem_map;
w = widget->allocation.width;
h = widget->allocation.height;
if (!widget->window) return;
@@ -208,7 +199,7 @@ dw_draw_memmap(DW *dw)
gulong start, end;
guint major, minor, inode;
- snprintf(buffer, 1023, "/proc/%d/maps", dw->pwin->process->pid);
+ snprintf(buffer, 1023, "/proc/%d/maps", pwin->process->pid);
in = fopen(buffer, "r");
while (fgets(buffer, 1023, in))
@@ -252,7 +243,7 @@ dw_draw_memmap(DW *dw)
mem.bpp = (bpl + w - 1) / w;
if (mem.bpp < 1) mem.bpp = 1;
- g_hash_table_foreach(dw->pwin->process->block_table,
+ g_hash_table_foreach(pwin->process->block_table,
dw_draw_memmap_foreach,
&mem);
@@ -265,133 +256,34 @@ dw_draw_memmap(DW *dw)
gdk_pixmap_unref(pixmap);
}
-static gboolean
-on_da1_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
+gboolean
+time_graph_expose_event(GtkWidget *widget, GdkEventExpose *event, ProcessWindow *pwin)
{
- DW *dw;
-
- dw = user_data;
- if (!dw->pwin->process) return FALSE;
- dw_draw_memstats(dw);
+ if (!pwin->process) return FALSE;
+ dw_draw_memstats(pwin);
return FALSE;
}
-static gboolean
-on_da2_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
+gboolean
+mem_map_expose_event(GtkWidget *widget, GdkEventExpose *event, ProcessWindow *pwin)
{
- DW *dw;
-
- dw = user_data;
- if (!dw->pwin->process) return FALSE;
- dw_draw_memmap(dw);
+ if (!pwin->process) return FALSE;
+ dw_draw_memmap(pwin);
return FALSE;
}
void
dw_update(ProcessWindow *pwin)
{
- DW *dw;
guint i;
-
- dw = pwin->detailwin_data;
- if (!dw) return;
if (!pwin->process) return;
for (i = MEMSTATS - 1; i > 0; i--)
{
- dw->memstats[i][0] = dw->memstats[i - 1][0];
- dw->memstats[i][1] = dw->memstats[i - 1][1];
+ pwin->memstats[i][0] = pwin->memstats[i - 1][0];
+ pwin->memstats[i][1] = pwin->memstats[i - 1][1];
}
- dw->memstats[0][0] = pwin->process->bytes_used;
- dw->memstats[0][1] = pwin->usage_high;
- dw_draw_memstats(dw);
- dw_draw_memmap(dw);
-}
-
-void
-dw_init(ProcessWindow *pwin)
-{
- DW *dw;
-
- GtkWidget *win;
- GtkWidget *notebook1;
- GtkWidget *frame1;
- GtkWidget *alignment1;
- GtkWidget *da1;
- GtkWidget *label1;
- GtkWidget *frame2;
- GtkWidget *alignment2;
- GtkWidget *da2;
- GtkWidget *label2;
-
- dw = calloc(1, sizeof(DW));
- pwin->detailwin_data = dw;
- dw->pwin = pwin;
-
- win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title (GTK_WINDOW (win), "Extra Details");
- gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);
-
- notebook1 = gtk_notebook_new ();
- gtk_widget_show (notebook1);
- gtk_container_add (GTK_CONTAINER (win), notebook1);
- gtk_container_set_border_width (GTK_CONTAINER (notebook1), 4);
-
- frame1 = gtk_frame_new (NULL);
- gtk_widget_show (frame1);
- gtk_container_add (GTK_CONTAINER (notebook1), frame1);
- gtk_container_set_border_width (GTK_CONTAINER (frame1), 4);
- gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
-
- alignment1 = gtk_alignment_new (0.5, 0.5, 1, 1);
- gtk_widget_show (alignment1);
- gtk_container_add (GTK_CONTAINER (frame1), alignment1);
-
- da1 = gtk_drawing_area_new ();
- gtk_widget_show (da1);
- gtk_container_add (GTK_CONTAINER (alignment1), da1);
-
- label1 = gtk_label_new ("Time Graph");
- gtk_widget_show (label1);
- gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label1);
-
- frame2 = gtk_frame_new (NULL);
- gtk_widget_show (frame2);
- gtk_container_add (GTK_CONTAINER (notebook1), frame2);
- gtk_container_set_border_width (GTK_CONTAINER (frame2), 4);
- gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
-
- alignment2 = gtk_alignment_new (0.5, 0.5, 1, 1);
- gtk_widget_show (alignment2);
- gtk_container_add (GTK_CONTAINER (frame2), alignment2);
-
- da2 = gtk_drawing_area_new ();
- gtk_widget_show (da2);
- gtk_container_add (GTK_CONTAINER (alignment2), da2);
-
- label2 = gtk_label_new ("Memory Usage Maps");
- gtk_widget_show (label2);
- gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label2);
-
- dw->win = win;
- dw->da1 = da1;
- dw->da2 = da2;
-
- g_signal_connect ((gpointer) da1, "expose_event",
- G_CALLBACK (on_da1_expose_event),
- dw);
- g_signal_connect ((gpointer) da2, "expose_event",
- G_CALLBACK (on_da2_expose_event),
- dw);
-
- gtk_widget_show(win);
-}
-
-void
-dw_shutdown(ProcessWindow *pwin)
-{
- DW *dw;
-
- dw = pwin->detailwin_data;
- free(dw);
- pwin->detailwin_data = NULL;
+ pwin->memstats[0][0] = pwin->process->bytes_used;
+ pwin->memstats[0][1] = pwin->usage_high;
+ dw_draw_memstats(pwin);
+ dw_draw_memmap(pwin);
}
diff --git a/src/gui.h b/src/gui.h
index ed27c7e..7c0aa98 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -27,6 +27,7 @@
#include "process.h"
#include "server.h"
+#define MEMSTATS 4096
typedef struct _ProcessWindow ProcessWindow;
@@ -58,7 +59,9 @@ struct _ProcessWindow {
guint status_update_timeout;
- void *detailwin_data;
+ GtkWidget *time_graph;
+ GtkWidget *mem_map;
+ guint memstats[MEMSTATS][2];
};
void tree_window_show (void);
@@ -77,8 +80,8 @@ void process_window_maybe_detach (ProcessWindow *pwin);
gboolean hide_and_check_quit (GtkWidget *window);
void check_quit (void);
-void dw_init(ProcessWindow *pwin);
-void dw_shutdown(ProcessWindow *pwin);
+gboolean time_graph_expose_event(GtkWidget *widget, GdkEventExpose *event, ProcessWindow *pwin);
+gboolean mem_map_expose_event(GtkWidget *widget, GdkEventExpose *event, ProcessWindow *pwin);
void dw_update(ProcessWindow *pwin);
#endif
diff --git a/src/main.c b/src/main.c
index 5e421e3..787e062 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1310,8 +1310,6 @@ process_window_free (ProcessWindow *pwin)
static void
process_window_destroy (ProcessWindow *pwin)
{
- dw_shutdown(pwin);
-
if (pwin->status_update_timeout)
g_source_remove (pwin->status_update_timeout);
@@ -1555,10 +1553,16 @@ process_window_new (void)
gtk_widget_hide (get_widget (xml, "reset-profile-button"));
}
+ pwin->time_graph = get_widget(xml, "time-graph");
+ pwin->mem_map = get_widget(xml, "mem-map");
+ g_signal_connect(pwin->time_graph, "expose_event",
+ G_CALLBACK (time_graph_expose_event), pwin);
+ g_signal_connect(pwin->mem_map, "expose_event",
+ G_CALLBACK (mem_map_expose_event), pwin);
+
glade_xml_signal_autoconnect (xml);
g_object_unref (G_OBJECT (xml));
- dw_init(pwin);
return pwin;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]