Commit bd6df837 authored by Robert Roth's avatar Robert Roth

Use two decimals precision for CPU usage (fixes #140)

parent a4e21b9c
......@@ -87,7 +87,7 @@ MutableProcInfo()
disk_read_bytes_current(0ULL),
disk_write_bytes_current(0ULL),
status(0U),
pcpu(0U),
pcpu(0),
nice(0)
{
}
......@@ -118,7 +118,7 @@ MutableProcInfo()
guint64 disk_read_bytes_current;
guint64 disk_write_bytes_current;
guint status;
guint pcpu;
gdouble pcpu;
gint nice;
std::string cgroup_name;
......
......@@ -75,7 +75,7 @@ fill_proc_properties (GtkTreeView *tree, ProcInfo *info)
#ifdef HAVE_WNCK
{ N_("X Server Memory"), format_memsize(info->memxserver)},
#endif
{ N_("CPU"), g_strdup_printf("%d%%", info->pcpu)},
{ N_("CPU"), g_strdup_printf("%.2f%%", info->pcpu)},
{ N_("CPU Time"), procman::format_duration_for_display(100 * info->cpu_time / GsmApplication::get()->frequency) },
{ N_("Started"), procman_format_date_for_display(info->start_time) },
{ N_("Nice"), g_strdup_printf("%d", info->nice)},
......
......@@ -377,7 +377,7 @@ proctable_new (GsmApplication * const app)
G_TYPE_ULONG, /* Writable Memory */
G_TYPE_ULONG, /* Shared Memory */
G_TYPE_ULONG, /* X Server Memory */
G_TYPE_UINT, /* % CPU */
G_TYPE_DOUBLE, /* % CPU */
G_TYPE_UINT64, /* CPU time */
G_TYPE_ULONG, /* Started */
G_TYPE_INT, /* Nice */
......@@ -480,7 +480,12 @@ proctable_new (GsmApplication * const app)
GUINT_TO_POINTER(i),
NULL);
break;
case COL_CPU:
gtk_tree_view_column_set_cell_data_func(col, cell,
&procman::percentage_cell_data_func,
GUINT_TO_POINTER(i),
NULL);
break;
case COL_CPU_TIME:
gtk_tree_view_column_set_cell_data_func(col, cell,
&procman::duration_cell_data_func,
......@@ -965,7 +970,7 @@ update_info (GsmApplication *app, ProcInfo *info)
if (not app->config.solaris_mode)
cpu_scale *= app->config.num_cpus;
info->pcpu = difference * cpu_scale / app->cpu_total_time;
info->pcpu = (gdouble)difference * cpu_scale / app->cpu_total_time;
info->pcpu = MIN(info->pcpu, cpu_scale);
app->processes.cpu_times[info->pid] = info->cpu_time = proctime.rtime;
......
......@@ -280,6 +280,9 @@ get_size_from_column(GtkTreeModel* model, GtkTreeIter* first,
case G_TYPE_UINT64:
size = g_value_get_uint64(&value);
break;
case G_TYPE_DOUBLE:
size = g_value_get_double(&value);
break;
default:
g_assert_not_reached();
}
......@@ -342,6 +345,24 @@ namespace procman
g_free(str);
}
void percentage_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data)
{
const guint index = GPOINTER_TO_UINT(user_data);
gdouble size;
GValue value = { 0 };
gtk_tree_model_get_value(model, iter, index, &value);
size = g_value_get_double(&value);
g_value_unset(&value);
char *str = g_strdup_printf("%.2f", size);
g_object_set(renderer, "text", str, NULL);
g_free(str);
}
/*
Same as above but handles size == 0 as not available
......
......@@ -69,6 +69,9 @@ namespace procman
void time_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
void percentage_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
void status_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment