1
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* Process properties dialog
3
* Copyright (C) 2010 Krishnan Parthasarathi <krishnan.parthasarathi@gmail.com>
4
* Robert Ancell <robert.ancell@canonical.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
23
#include <glib/gi18n.h>
24
#include <glibtop/procmem.h>
25
#include <glibtop/procmap.h>
26
#include <glibtop/procstate.h>
27
#if defined (__linux__)
28
#include <asm/param.h>
29
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
30
#include <sys/param.h>
31
#include <sys/sysctl.h>
34
#include "application.h"
35
#include "procproperties.h"
36
#include "proctable.h"
46
typedef struct _proc_arg {
52
format_memsize(guint64 size)
55
return g_strdup(_("N/A"));
57
return g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
61
fill_proc_properties (GtkWidget *tree, ProcInfo *info)
69
get_process_memory_writable (info);
71
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
72
struct clockinfo cinf;
73
size_t size = sizeof (cinf);
75
int mib[] = { CTL_KERN, KERN_CLOCKRATE };
77
if (sysctl (mib, G_N_ELEMENTS (mib), &cinf, &size, NULL, 0) == -1)
80
HZ = (cinf.stathz ? cinf.stathz : cinf.hz);
82
proc_arg proc_props[] = {
83
{ N_("Process Name"), g_strdup_printf("%s", info->name)},
84
{ N_("User"), g_strdup_printf("%s (%d)", info->user.c_str(), info->uid)},
85
{ N_("Status"), g_strdup(format_process_state(info->status))},
86
{ N_("Memory"), format_memsize(info->mem)},
87
{ N_("Virtual Memory"), format_memsize(info->vmsize)},
88
{ N_("Resident Memory"), format_memsize(info->memres)},
89
{ N_("Writable Memory"), format_memsize(info->memwritable)},
90
{ N_("Shared Memory"), format_memsize(info->memshared)},
92
{ N_("X Server Memory"), format_memsize(info->memxserver)},
94
{ N_("CPU"), g_strdup_printf("%d%%", info->pcpu)},
95
{ N_("CPU Time"), g_strdup_printf(ngettext("%lld second", "%lld seconds", info->cpu_time/HZ), (unsigned long long)info->cpu_time/HZ) },
96
{ N_("Started"), g_strdup_printf("%s", ctime((const time_t*)(&info->start_time)))},
97
{ N_("Nice"), g_strdup_printf("%d", info->nice)},
98
{ N_("Priority"), g_strdup_printf("%s", procman::get_nice_level(info->nice)) },
99
{ N_("ID"), g_strdup_printf("%d", info->pid)},
100
{ N_("Security Context"), info->security_context?g_strdup_printf("%s", info->security_context):g_strdup(_("N/A"))},
101
{ N_("Command Line"), g_strdup_printf("%s", info->arguments)},
102
{ N_("Waiting Channel"), g_strdup_printf("%s", info->wchan)},
103
{ N_("Control Group"), info->cgroup_name?g_strdup_printf("%s", info->cgroup_name):g_strdup(_("N/A"))},
107
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree)));
108
for (i = 0; proc_props[i].prop; i++) {
111
if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(store), &iter, NULL, i)) {
112
gtk_list_store_append(store, &iter);
113
gtk_list_store_set(store, &iter, COL_PROP, gettext(proc_props[i].prop), -1);
116
gtk_list_store_set(store, &iter, COL_VAL, g_strstrip(proc_props[i].val), -1);
117
g_free(proc_props[i].val);
122
update_procproperties_dialog (GtkWidget *tree)
126
pid_t pid = GPOINTER_TO_UINT(static_cast<pid_t*>(g_object_get_data (G_OBJECT (tree), "selected_info")));
127
info = ProcInfo::find(pid);
129
fill_proc_properties(tree, info);
133
close_procprop_dialog (GtkDialog *dialog, gint id, gpointer data)
135
GtkWidget *tree = static_cast<GtkWidget*>(data);
138
timer = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tree), "timer"));
139
g_source_remove (timer);
141
gtk_widget_destroy (GTK_WIDGET (dialog));
145
create_procproperties_tree (GsmApplication *app, ProcInfo *info)
149
GtkTreeViewColumn *column;
150
GtkCellRenderer *cell;
153
model = gtk_list_store_new (NUM_COLS,
154
G_TYPE_STRING, /* Property */
155
G_TYPE_STRING /* Value */
158
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
159
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree), TRUE);
160
g_object_unref (G_OBJECT (model));
162
for (i = 0; i < NUM_COLS; i++) {
163
cell = gtk_cell_renderer_text_new ();
165
column = gtk_tree_view_column_new_with_attributes (NULL,
169
gtk_tree_view_column_set_resizable (column, TRUE);
170
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
173
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(tree), FALSE);
174
fill_proc_properties(tree, info);
180
procprop_timer (gpointer data)
182
GtkWidget *tree = static_cast<GtkWidget*>(data);
185
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
188
update_procproperties_dialog (tree);
194
create_single_procproperties_dialog (GtkTreeModel *model, GtkTreePath *path,
195
GtkTreeIter *iter, gpointer data)
197
GsmApplication *app = static_cast<GsmApplication *>(data);
199
GtkWidget *procpropdialog;
200
GtkWidget *dialog_vbox, *vbox;
208
gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
213
procpropdialog = gtk_dialog_new_with_buttons (_("Process Properties"), NULL,
214
GTK_DIALOG_DESTROY_WITH_PARENT,
215
_("_Close"), GTK_RESPONSE_CLOSE,
217
gtk_window_set_resizable (GTK_WINDOW (procpropdialog), TRUE);
218
gtk_window_set_default_size (GTK_WINDOW (procpropdialog), 575, 400);
219
gtk_container_set_border_width (GTK_CONTAINER (procpropdialog), 5);
221
vbox = gtk_dialog_get_content_area (GTK_DIALOG (procpropdialog));
222
gtk_box_set_spacing (GTK_BOX (vbox), 2);
223
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
225
dialog_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
226
gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
227
gtk_box_pack_start (GTK_BOX (vbox), dialog_vbox, TRUE, TRUE, 0);
229
cmd_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
230
gtk_box_pack_start (GTK_BOX (dialog_vbox), cmd_hbox, FALSE, FALSE, 0);
232
label = procman_make_label_for_mmaps_or_ofiles (
233
_("Properties of process \"%s\" (PID %u):"),
237
gtk_box_pack_start (GTK_BOX (cmd_hbox),label, FALSE, FALSE, 0);
239
scrolled = gtk_scrolled_window_new (NULL, NULL);
240
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
241
GTK_POLICY_AUTOMATIC,
242
GTK_POLICY_AUTOMATIC);
243
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
246
tree = create_procproperties_tree (app, info);
247
gtk_container_add (GTK_CONTAINER (scrolled), tree);
248
g_object_set_data (G_OBJECT (tree), "selected_info", GUINT_TO_POINTER (info->pid));
250
gtk_box_pack_start (GTK_BOX (dialog_vbox), scrolled, TRUE, TRUE, 0);
251
gtk_widget_show_all (scrolled);
253
g_signal_connect (G_OBJECT (procpropdialog), "response",
254
G_CALLBACK (close_procprop_dialog), tree);
256
gtk_widget_show_all (procpropdialog);
258
timer = g_timeout_add_seconds (5, procprop_timer, tree);
259
g_object_set_data (G_OBJECT (tree), "timer", GUINT_TO_POINTER (timer));
261
update_procproperties_dialog (tree);
265
create_procproperties_dialog (GsmApplication *app)
267
gtk_tree_selection_selected_foreach (app->selection, create_single_procproperties_dialog,