[gnome-system-monitor] Add Priority column to the process table to show user-friendly nice values.
- From: Chris KÃhl <chriskuehl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Add Priority column to the process table to show user-friendly nice values.
- Date: Mon, 12 Dec 2011 00:12:55 +0000 (UTC)
commit 6fcbf5aaa65d63dd751c812c3ac05a937b50450d
Author: Robert Roth <robert roth off gmail com>
Date: Fri Nov 25 23:12:00 2011 +0200
Add Priority column to the process table to show user-friendly nice values.
https://bugzilla.gnome.org/show_bug.cgi?id=131802
src/org.gnome.gnome-system-monitor.gschema.xml.in | 14 ++++++
src/procdialogs.cpp | 24 +++--------
src/proctable.cpp | 15 ++++++-
src/proctable.h | 1 +
src/util.cpp | 45 +++++++++++++++++++++
src/util.h | 8 ++++
6 files changed, 86 insertions(+), 21 deletions(-)
---
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index a9f5e49..2a1a8ec 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -447,6 +447,20 @@
</_summary>
</key>
+ <key name="col-18-width" type="i">
+ <default>100
+ </default>
+ <_summary>Width of process 'Priority' column
+ </_summary>
+ </key>
+
+ <key name="col-18-visible" type="b">
+ <default>true
+ </default>
+ <_summary>Show process 'Priority' column on startup
+ </_summary>
+ </key>
+
</schema>
<schema id="org.gnome.gnome-system-monitor.disktreenew" path="/org/gnome/gnome-system-monitor/disktreenew/">
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index 460bf77..d990933 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -115,28 +115,15 @@ procdialog_create_kill_dialog (ProcData *procdata, int signal)
gtk_widget_show_all (kill_alert_dialog);
}
-static gchar *
-get_nice_level (gint nice)
-{
- if (nice < -7)
- return _("(Very High Priority)");
- else if (nice < -2)
- return _("(High Priority)");
- else if (nice < 3)
- return _("(Normal Priority)");
- else if (nice < 7)
- return _("(Low Priority)");
- else
- return _("(Very Low Priority)");
-}
-
static void
renice_scale_changed (GtkAdjustment *adj, gpointer data)
{
GtkWidget *label = GTK_WIDGET (data);
new_nice_value = int(gtk_adjustment_get_value (adj));
- gtk_label_set_text (GTK_LABEL (label), get_nice_level (new_nice_value));
+ gchar* text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (new_nice_value));
+ gtk_label_set_text (GTK_LABEL (label), text);
+ g_free(text);
}
@@ -224,10 +211,11 @@ procdialog_create_renice_dialog (ProcData *procdata)
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_table_attach (GTK_TABLE (table), hscale, 1, 2, 0, 1,
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-
- priority_label = gtk_label_new (get_nice_level (info->nice));
+ text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (info->nice));
+ priority_label = gtk_label_new (text);
gtk_table_attach (GTK_TABLE (table), priority_label, 1, 2, 1, 2,
GTK_FILL, GTK_FILL, 0, 0);
+ g_free(text);
text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
_("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 4373522..ebe5573 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -67,7 +67,6 @@ ProcInfo* ProcInfo::find(pid_t pid)
-
static void
set_proctree_reorderable(ProcData *procdata)
{
@@ -249,6 +248,7 @@ proctable_new (ProcData * const procdata)
/* xgettext: combined noun, the function the process is waiting in, see wchan ps(1) */
N_("Waiting Channel"),
N_("Control Group"),
+ N_("Priority"),
NULL,
"POINTER"
};
@@ -279,6 +279,7 @@ proctable_new (ProcData * const procdata)
G_TYPE_ULONG, /* Memory */
G_TYPE_STRING, /* wchan */
G_TYPE_STRING, /* Cgroup */
+ G_TYPE_STRING, /* Priority */
GDK_TYPE_PIXBUF, /* Icon */
G_TYPE_POINTER, /* ProcInfo */
G_TYPE_STRING /* Sexy tooltip */
@@ -322,7 +323,7 @@ proctable_new (ProcData * const procdata)
gtk_tree_view_set_expander_column (GTK_TREE_VIEW (proctree), column);
- for (i = COL_USER; i <= COL_CGROUP; i++) {
+ for (i = COL_USER; i <= COL_PRIORITY; i++) {
GtkCellRenderer *cell;
GtkTreeViewColumn *col;
@@ -377,7 +378,15 @@ proctable_new (ProcData * const procdata)
GUINT_TO_POINTER(i),
NULL);
break;
-
+ case COL_PRIORITY:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::priority_cell_data_func,
+ GUINT_TO_POINTER(COL_NICE),
+ NULL);
+ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), i,
+ procman::priority_compare_func,
+ GUINT_TO_POINTER(COL_NICE), NULL);
+ break;
default:
gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
break;
diff --git a/src/proctable.h b/src/proctable.h
index 1a26a62..193288d 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -44,6 +44,7 @@ enum
COL_MEM,
COL_WCHAN,
COL_CGROUP,
+ COL_PRIORITY,
COL_PIXBUF,
COL_POINTER,
COL_TOOLTIP,
diff --git a/src/util.cpp b/src/util.cpp
index 5820237..18fd8b5 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -210,6 +210,20 @@ procman::format_size(guint64 size, guint64 max_size, bool want_bits)
}
}
+gchar *
+procman::get_nice_level (gint nice)
+{
+ if (nice < -7)
+ return _("Very High");
+ else if (nice < -2)
+ return _("High");
+ else if (nice < 3)
+ return _("Normal");
+ else if (nice < 7)
+ return _("Low");
+ else
+ return _("Very Low");
+}
gboolean
@@ -473,6 +487,37 @@ namespace procman
g_object_set(renderer, "text", str, NULL);
}
+ void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+
+ GValue value = { 0 };
+
+ gtk_tree_model_get_value(model, iter, index, &value);
+
+ gint priority = g_value_get_int(&value);
+
+ g_value_unset(&value);
+
+ g_object_set(renderer, "text", procman::get_nice_level(priority), NULL);
+
+ }
+
+ gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+ GValue value1 = { 0 };
+ GValue value2 = { 0 };
+ gtk_tree_model_get_value(model, first, index, &value1);
+ gtk_tree_model_get_value(model, second, index, &value2);
+ gint result = g_value_get_int(&value1) - g_value_get_int(&value2);
+ g_value_unset(&value1);
+ g_value_unset(&value2);
+ return result;
+ }
template<>
void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value)
diff --git a/src/util.h b/src/util.h
index 2907b82..3b0d76e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -97,6 +97,12 @@ namespace procman
void status_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
+ void priority_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
+ gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data);
+
template<typename T>
void poison(T &t, char c)
@@ -139,6 +145,8 @@ namespace procman
gchar* format_size(guint64 size, guint64 max = 0, bool want_bits = false);
+ gchar* get_nice_level (gint nice);
+
std::string format_rate(guint64 rate, guint64 max_rate = 0, bool want_bits = false);
std::string format_network(guint64 rate, guint64 max_rate = 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]