Skip to content

Commit

Permalink
Add disk IO on process info
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuj authored and lukefromdc committed Apr 29, 2019
1 parent 1f42b9e commit fc1f63b
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LT_INIT

# Package dependencies
GLIB_REQUIRED=2.50.0
LIBGTOP_REQUIRED=2.23.1
LIBGTOP_REQUIRED=2.37.2
GIOMM_REQUIRED=2.26.0
GLIBMM_REQUIRED=2.22
GTK_REQUIRED=3.22.0
Expand Down
36 changes: 34 additions & 2 deletions src/org.mate.system-monitor.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,43 @@
</key>
<key name="col-22-width" type="i">
<default>100</default>
<summary>Width of process 'Priority' column</summary>
<summary>Width of process “Disk Write Total” column</summary>
</key>
<key name="col-22-visible" type="b">
<default>false</default>
<summary>Show process “Disk Write Total” column on startup</summary>
</key>
<key name="col-23-width" type="i">
<default>100</default>
<summary>Width of process “Disk Read Total” column</summary>
</key>
<key name="col-23-visible" type="b">
<default>false</default>
<summary>Show process “Disk Read Total” column on startup</summary>
</key>
<key name="col-24-width" type="i">
<default>100</default>
<summary>Width of process “Disk Read” column</summary>
</key>
<key name="col-24-visible" type="b">
<default>false</default>
<summary>Show process “Disk Read” column on startup</summary>
</key>
<key name="col-25-width" type="i">
<default>100</default>
<summary>Width of process “Disk Write” column</summary>
</key>
<key name="col-25-visible" type="b">
<default>false</default>
<summary>Show process “Disk Write” column on startup</summary>
</key>
<key name="col-26-width" type="i">
<default>100</default>
<summary>Width of process “Priority” column</summary>
</key>
<key name="col-26-visible" type="b">
<default>true</default>
<summary>Show process 'Priority' column on startup</summary>
<summary>Show process Priority column on startup</summary>
</key>
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.mate.system-monitor.disktreenew" path="/org/mate/system-monitor/disktreenew/">
Expand Down
10 changes: 9 additions & 1 deletion src/procman.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ struct ProcConfig
struct MutableProcInfo
{
MutableProcInfo()
: status(0)
: disk_write_bytes_current(0ULL),
disk_read_bytes_current(0ULL),
disk_write_bytes_total(0ULL),
disk_read_bytes_total(0ULL),
status(0U)
{ }

std::string user;
Expand All @@ -136,6 +140,10 @@ MutableProcInfo()

gulong start_time;
guint64 cpu_time;
guint64 disk_write_bytes_current;
guint64 disk_read_bytes_current;
guint64 disk_write_bytes_total;
guint64 disk_read_bytes_total;
guint status;
guint pcpu;
gint nice;
Expand Down
11 changes: 11 additions & 0 deletions src/procproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ format_memsize(guint64 size)
return g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
}

static gchar*
format_size(guint64 size)
{
if (size == 0)
return g_strdup(_("N/A"));
else
return g_format_size(size);
}

static void
fill_proc_properties (GtkWidget *tree, ProcInfo *info)
{
Expand All @@ -122,6 +131,8 @@ fill_proc_properties (GtkWidget *tree, ProcInfo *info)
{ N_("Writable Memory"), format_memsize(info->memwritable)},
{ N_("Shared Memory"), format_memsize(info->memshared)},
{ N_("X Server Memory"), format_memsize(info->memxserver)},
{ N_("Disk Read Total"), format_size(info->disk_read_bytes_total)},
{ N_("Disk Write Total"), format_size(info->disk_write_bytes_total)},
{ N_("CPU"), g_strdup_printf("%d%%", info->pcpu)},
{ N_("CPU Time"), procman::format_duration_for_display(100 * info->cpu_time / ProcData::get_instance()->frequency) },
{ N_("Started"), procman_format_date_for_display(info->start_time) },
Expand Down
51 changes: 50 additions & 1 deletion src/proctable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <glibtop.h>
#include <glibtop/loadavg.h>
#include <glibtop/proclist.h>
#include <glibtop/procio.h>
#include <glibtop/procstate.h>
#include <glibtop/procmem.h>
#include <glibtop/procmap.h>
Expand Down Expand Up @@ -263,6 +264,10 @@ proctable_new (ProcData * const procdata)
for multi-seat environments. See http://en.wikipedia.org/wiki/Multiseat_configuration */
N_("Seat"),
N_("Owner"),
N_("Disk Read Total"),
N_("Disk Write Total"),
N_("Disk Read"),
N_("Disk Write"),
N_("Priority"),
NULL,
"POINTER"
Expand Down Expand Up @@ -298,6 +303,10 @@ proctable_new (ProcData * const procdata)
G_TYPE_STRING, /* Session */
G_TYPE_STRING, /* Seat */
G_TYPE_STRING, /* Owner */
G_TYPE_UINT64, /* Disk read total */
G_TYPE_UINT64, /* Disk write total*/
G_TYPE_UINT64, /* Disk read */
G_TYPE_UINT64, /* Disk write */
G_TYPE_STRING, /* Priority */
GDK_TYPE_PIXBUF, /* Icon */
G_TYPE_POINTER, /* ProcInfo */
Expand Down Expand Up @@ -397,15 +406,32 @@ proctable_new (ProcData * const procdata)
GUINT_TO_POINTER(i),
NULL);
break;

case COL_DISK_READ_TOTAL:
case COL_DISK_WRITE_TOTAL:
gtk_tree_view_column_set_cell_data_func(col, cell,
&procman::storage_size_na_cell_data_func,
GUINT_TO_POINTER(i),
NULL);
break;

case COL_DISK_READ_CURRENT:
case COL_DISK_WRITE_CURRENT:
gtk_tree_view_column_set_cell_data_func(col, cell,
&procman::io_rate_cell_data_func,
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);
break;

default:
gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
break;
}

// sorting
Expand All @@ -418,6 +444,10 @@ proctable_new (ProcData * const procdata)
case COL_MEMWRITABLE:
case COL_CPU:
case COL_CPU_TIME:
case COL_DISK_READ_TOTAL:
case COL_DISK_WRITE_TOTAL:
case COL_DISK_READ_CURRENT:
case COL_DISK_WRITE_CURRENT:
case COL_START_TIME:
gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), i,
procman::number_compare_func, GUINT_TO_POINTER(i),
Expand All @@ -443,6 +473,10 @@ proctable_new (ProcData * const procdata)
case COL_CPU:
case COL_NICE:
case COL_PID:
case COL_DISK_READ_TOTAL:
case COL_DISK_WRITE_TOTAL:
case COL_DISK_READ_CURRENT:
case COL_DISK_WRITE_CURRENT:
case COL_CPU_TIME:
case COL_MEM:
g_object_set(G_OBJECT(cell), "xalign", 1.0f, NULL);
Expand Down Expand Up @@ -650,6 +684,10 @@ update_info_mutable_cols(ProcInfo *info)
tree_store_update(model, &info->node, COL_MEMXSERVER, info->memxserver);
tree_store_update(model, &info->node, COL_CPU, info->pcpu);
tree_store_update(model, &info->node, COL_CPU_TIME, info->cpu_time);
tree_store_update(model, &info->node, COL_DISK_READ_TOTAL, info->disk_read_bytes_total);
tree_store_update(model, &info->node, COL_DISK_WRITE_TOTAL, info->disk_write_bytes_total);
tree_store_update(model, &info->node, COL_DISK_READ_CURRENT, info->disk_read_bytes_current);
tree_store_update(model, &info->node, COL_DISK_WRITE_CURRENT, info->disk_write_bytes_current);
tree_store_update(model, &info->node, COL_START_TIME, info->start_time);
tree_store_update(model, &info->node, COL_NICE, info->nice);
tree_store_update(model, &info->node, COL_MEM, info->mem);
Expand Down Expand Up @@ -785,6 +823,7 @@ update_info (ProcData *procdata, ProcInfo *info)
glibtop_proc_uid procuid;
glibtop_proc_time proctime;
glibtop_proc_kernel prockernel;
glibtop_proc_io procio;

glibtop_get_proc_kernel(&prockernel, info->pid);
g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
Expand All @@ -794,6 +833,7 @@ update_info (ProcData *procdata, ProcInfo *info)

glibtop_get_proc_uid (&procuid, info->pid);
glibtop_get_proc_time (&proctime, info->pid);
glibtop_get_proc_io (&procio, info->pid);

get_process_memory_info(info);

Expand All @@ -813,6 +853,15 @@ update_info (ProcData *procdata, ProcInfo *info)
ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
info->nice = procuid.nice;

gdouble update_interval_seconds = procdata->config.update_interval / 1000.0;
difference = procio.disk_wbytes - info->disk_write_bytes_total;
info->disk_write_bytes_current = difference > update_interval_seconds ? difference/update_interval_seconds : 0ULL;
difference = procio.disk_rbytes - info->disk_read_bytes_total;
info->disk_read_bytes_current = difference > update_interval_seconds ? difference/update_interval_seconds : 0ULL;

info->disk_write_bytes_total = procio.disk_wbytes;
info->disk_read_bytes_total = procio.disk_rbytes;

// set the ppid only if one can exist
// i.e. pid=0 can never have a parent
if (info->pid > 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/proctable.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ enum
COL_SESSION,
COL_SEAT,
COL_OWNER,
COL_DISK_WRITE_TOTAL,
COL_DISK_READ_TOTAL,
COL_DISK_WRITE_CURRENT,
COL_DISK_READ_CURRENT,
COL_PRIORITY,
COL_PIXBUF,
COL_POINTER,
Expand Down
43 changes: 42 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,47 @@ namespace procman
}
}

void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data)
{
const guint index = GPOINTER_TO_UINT(user_data);

guint64 size;
GValue value = { 0 };

gtk_tree_model_get_value(model, iter, index, &value);

switch (G_VALUE_TYPE(&value)) {
case G_TYPE_ULONG:
size = g_value_get_ulong(&value);
break;

case G_TYPE_UINT64:
size = g_value_get_uint64(&value);
break;

default:
g_assert_not_reached();
}

g_value_unset(&value);

if (size == 0) {
char *str = g_strdup_printf ("<i>%s</i>", _("N/A"));
g_object_set(renderer, "markup", str, NULL);
g_free(str);
}
else {
char *str = g_format_size(size);
char *formatted_str = g_strdup_printf(_("%s/s"), str);
g_object_set(renderer, "text", formatted_str, NULL);
g_free(formatted_str);
g_free(str);
}

}

void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data)
Expand Down Expand Up @@ -568,4 +609,4 @@ namespace procman

g_free(current_value);
}
}
}
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace procman
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);

void io_rate_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);

void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
Expand Down

0 comments on commit fc1f63b

Please sign in to comment.