Also include swap in the memory graph
This commit is contained in:
@@ -36,6 +36,7 @@ struct _XtmProcessMonitor
|
||||
gfloat step_size;
|
||||
gint type;
|
||||
GArray * history;
|
||||
GArray * history_swap;
|
||||
};
|
||||
G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
|
||||
|
||||
@@ -66,6 +67,7 @@ static void
|
||||
xtm_process_monitor_init (XtmProcessMonitor *monitor)
|
||||
{
|
||||
monitor->history = g_array_new (FALSE, TRUE, sizeof (gfloat));
|
||||
monitor->history_swap = g_array_new (FALSE, TRUE, sizeof (gfloat));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -116,7 +118,12 @@ xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr)
|
||||
|
||||
minimum_history_length = (guint)(gtk_widget_get_allocated_width(widget) / monitor->step_size);
|
||||
if (monitor->history->len < minimum_history_length)
|
||||
{
|
||||
g_array_set_size (monitor->history, minimum_history_length + 1);
|
||||
if (monitor->type == 1)
|
||||
g_array_set_size (monitor->history_swap, minimum_history_length + 1);
|
||||
}
|
||||
|
||||
|
||||
xtm_process_monitor_paint (monitor, cr);
|
||||
return FALSE;
|
||||
@@ -167,6 +174,23 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width
|
||||
cairo_set_source_rgba (cr, 0.67, 0.09, 0.32, 1.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
/* Draw Swap graph */
|
||||
if (monitor->type == 1)
|
||||
{
|
||||
cairo_translate (cr, step_size * i, 0);
|
||||
cairo_move_to (cr, width, height);
|
||||
for (i = 0; (step_size * (i - 1)) <= width; i++)
|
||||
{
|
||||
peak = &g_array_index (monitor->history_swap, gfloat, i);
|
||||
cairo_translate (cr, -step_size, 0);
|
||||
cairo_line_to (cr, width, (1.0 - ((gdouble)(*peak))) * height);
|
||||
}
|
||||
cairo_set_source_rgba (cr, 0.33, 0.04, 0.16, 0.3);
|
||||
cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgba (cr, 0.33, 0.04, 0.16, 1.0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
cairo_destroy (cr);
|
||||
|
||||
return graph_surface;
|
||||
@@ -222,7 +246,7 @@ xtm_process_monitor_new (void)
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak)
|
||||
xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat peak_swap)
|
||||
{
|
||||
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||
g_return_if_fail (peak >= 0.0f && peak <= 1.0f);
|
||||
@@ -231,6 +255,13 @@ xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak)
|
||||
if (monitor->history->len > 1)
|
||||
g_array_remove_index (monitor->history, monitor->history->len - 1);
|
||||
|
||||
if (monitor->type == 1)
|
||||
{
|
||||
g_array_prepend_val (monitor->history_swap, peak_swap);
|
||||
if (monitor->history_swap->len > 1)
|
||||
g_array_remove_index (monitor->history_swap, monitor->history_swap->len - 1);
|
||||
}
|
||||
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
||||
}
|
||||
@@ -256,6 +287,7 @@ xtm_process_monitor_clear (XtmProcessMonitor *monitor)
|
||||
{
|
||||
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||
g_array_set_size (monitor->history, 0);
|
||||
g_array_set_size (monitor->history_swap, 0);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef struct _XtmProcessMonitor XtmProcessMonitor;
|
||||
|
||||
GType xtm_process_monitor_get_type (void);
|
||||
GtkWidget * xtm_process_monitor_new (void);
|
||||
void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak);
|
||||
void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat peak_swap);
|
||||
void xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size);
|
||||
void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type);
|
||||
void xtm_process_monitor_clear (XtmProcessMonitor *monitor);
|
||||
|
||||
@@ -159,6 +159,8 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV
|
||||
text = g_strdup_printf (_("Swap: %s"), statusbar->swap);
|
||||
gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text);
|
||||
gtk_widget_set_tooltip_text (statusbar->label_swap, text);
|
||||
gdk_rgba_parse (&color, "#75324d");
|
||||
gtk_widget_override_color (statusbar->label_swap, GTK_STATE_FLAG_NORMAL, &color);
|
||||
g_free (text);
|
||||
break;
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ xtm_process_window_get_model (XtmProcessWindow *window)
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap __unused, gchar* swap_str)
|
||||
xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str)
|
||||
{
|
||||
gchar text[100];
|
||||
gchar value[4];
|
||||
@@ -450,12 +450,12 @@ xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processe
|
||||
|
||||
g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, NULL);
|
||||
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0f);
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0f, -1.0);
|
||||
g_snprintf (value, sizeof(value), "%.0f", cpu);
|
||||
g_snprintf (text, sizeof(text), _("CPU: %s%%"), value);
|
||||
gtk_widget_set_tooltip_text (window->cpu_monitor, text);
|
||||
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0f);
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0f, swap / 100.0f);
|
||||
g_snprintf (text, sizeof(text), _("Memory: %s"), memory_str);
|
||||
gtk_widget_set_tooltip_text (window->mem_monitor, text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user