[gnome-system-monitor/wip/procinfo2: 3/6] Move ProcInfo class in a separate file
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor/wip/procinfo2: 3/6] Move ProcInfo class in a separate file
- Date: Thu, 8 May 2014 17:10:51 +0000 (UTC)
commit db91bfd5ed339df8880bd18106675578627750da
Author: Stefano Facchini <stefano facchini gmail com>
Date: Thu May 8 18:32:44 2014 +0200
Move ProcInfo class in a separate file
src/Makefile.am | 1 +
src/application.h | 95 ---------------
src/cgroups.cpp | 2 +-
src/lsof.cpp | 2 +-
src/memmaps.cpp | 1 +
src/openfiles.cpp | 1 +
src/prettytable.cpp | 1 +
src/procactions.cpp | 1 +
src/procdialogs.cpp | 1 +
src/procinfo.cpp | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
src/procinfo.h | 108 +++++++++++++++++
src/procproperties.cpp | 1 +
src/proctable.cpp | 290 +---------------------------------------------
src/proctable.h | 1 -
src/selinux.cpp | 2 +-
15 files changed, 423 insertions(+), 388 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 11fd5d4..98f52fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,6 +15,7 @@ gnome_system_monitor_cpp_files = \
argv.cpp \
interface.cpp \
load-graph.cpp \
+ procinfo.cpp \
proctable.cpp \
prettytable.cpp \
util.cpp \
diff --git a/src/application.h b/src/application.h
index 0819951..13b3278 100644
--- a/src/application.h
+++ b/src/application.h
@@ -5,7 +5,6 @@
#include <gtkmm.h>
#include <glibtop/cpu.h>
-struct ProcInfo;
struct LoadGraph;
#include "smooth_refresh.h"
@@ -43,100 +42,6 @@ struct ProcConfig
-struct MutableProcInfo
-{
-MutableProcInfo()
-: status(0)
- { }
-
- std::string user;
-
- gchar wchan[40];
-
- // all these members are filled with libgtop which uses
- // guint64 (to have fixed size data) but we don't need more
- // than an unsigned long (even for 32bit apps on a 64bit
- // kernel) as these data are amounts, not offsets.
- gulong vmsize;
- gulong memres;
- gulong memshared;
- gulong memwritable;
- gulong mem;
-
-#ifdef HAVE_WNCK
- // wnck gives an unsigned long
- gulong memxserver;
-#endif
-
- gulong start_time;
- guint64 cpu_time;
- guint status;
- guint pcpu;
- gint nice;
- gchar *cgroup_name;
-
- gchar *unit;
- gchar *session;
- gchar *seat;
-
- std::string owner;
-};
-
-
-class ProcInfo
-: public MutableProcInfo
-{
- /* undefined */ ProcInfo& operator=(const ProcInfo&);
- /* undefined */ ProcInfo(const ProcInfo&);
-
- typedef std::map<guint, std::string> UserMap;
- /* cached username */
- static UserMap users;
-
- public:
-
- // TODO: use a set instead
- // sorted by pid. The map has a nice property : it is sorted
- // by pid so this helps a lot when looking for the parent node
- // as ppid is nearly always < pid.
- typedef std::map<pid_t, ProcInfo*> List;
- typedef List::iterator Iterator;
-
- static List all;
-
- static ProcInfo* find(pid_t pid);
- static Iterator begin() { return ProcInfo::all.begin(); }
- static Iterator end() { return ProcInfo::all.end(); }
-
-
- ProcInfo(pid_t pid);
- ~ProcInfo();
- // adds one more ref to icon
- void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
- void set_user(guint uid);
- std::string lookup_user(guint uid);
-
- GtkTreeIter node;
- Glib::RefPtr<Gdk::Pixbuf> pixbuf;
- gchar *tooltip;
- gchar *name;
- gchar *arguments;
-
- gchar *security_context;
-
- const guint pid;
- guint ppid;
- guint uid;
-
-// private:
- // tracks cpu time per process keeps growing because if a
- // ProcInfo is deleted this does not mean that the process is
- // not going to be recreated on the next update. For example,
- // if dependencies + (My or Active), the proclist is cleared
- // on each update. This is a workaround
- static std::map<pid_t, guint64> cpu_times;
-};
-
class GsmApplication : public Gtk::Application
diff --git a/src/cgroups.cpp b/src/cgroups.cpp
index 603e95f..ffbf86b 100644
--- a/src/cgroups.cpp
+++ b/src/cgroups.cpp
@@ -6,7 +6,7 @@
#include <cstring>
#include "cgroups.h"
-#include "application.h"
+#include "procinfo.h"
#include "util.h"
gboolean
diff --git a/src/lsof.cpp b/src/lsof.cpp
index 9f6a3ec..658ce4a 100644
--- a/src/lsof.cpp
+++ b/src/lsof.cpp
@@ -14,7 +14,7 @@
#include <glibmm/regex.h>
-#include "application.h"
+#include "procinfo.h"
#include "lsof.h"
#include "util.h"
diff --git a/src/memmaps.cpp b/src/memmaps.cpp
index 2a7434f..cab35b8 100644
--- a/src/memmaps.cpp
+++ b/src/memmaps.cpp
@@ -17,6 +17,7 @@ using std::string;
#include "application.h"
#include "memmaps.h"
+#include "procinfo.h"
#include "proctable.h"
#include "settings-keys.h"
#include "treeview.h"
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index cba41f2..91665d5 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -12,6 +12,7 @@
#include "application.h"
#include "openfiles.h"
+#include "procinfo.h"
#include "proctable.h"
#include "util.h"
#include "settings-keys.h"
diff --git a/src/prettytable.cpp b/src/prettytable.cpp
index a4207e4..3b78db9 100644
--- a/src/prettytable.cpp
+++ b/src/prettytable.cpp
@@ -22,6 +22,7 @@
#include "prettytable.h"
#include "defaulttable.h"
#include "proctable.h"
+#include "procinfo.h"
#include "util.h"
diff --git a/src/procactions.cpp b/src/procactions.cpp
index b0c8b0d..6b26fbb 100644
--- a/src/procactions.cpp
+++ b/src/procactions.cpp
@@ -27,6 +27,7 @@
#include <sys/resource.h>
#include "procactions.h"
#include "application.h"
+#include "procinfo.h"
#include "proctable.h"
#include "procdialogs.h"
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index 9e2ffa0..6cad326 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -27,6 +27,7 @@
#include <stdio.h>
#include "procdialogs.h"
+#include "procinfo.h"
#include "proctable.h"
#include "prettytable.h"
#include "procactions.h"
diff --git a/src/procinfo.cpp b/src/procinfo.cpp
new file mode 100644
index 0000000..1207688
--- /dev/null
+++ b/src/procinfo.cpp
@@ -0,0 +1,304 @@
+/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#include <glib/gprintf.h>
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+#include <glibtop/proclist.h>
+#include <glibtop/procstate.h>
+#include <glibtop/procmem.h>
+#include <glibtop/procmap.h>
+#include <glibtop/proctime.h>
+#include <glibtop/procuid.h>
+#include <glibtop/procargs.h>
+#include <glibtop/prockernel.h>
+#include <glibtop/mem.h>
+#include <glibtop/swap.h>
+#include <sys/stat.h>
+#include <pwd.h>
+
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-login.h>
+#endif
+
+#ifdef HAVE_WNCK
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+#endif
+
+#include "procinfo.h"
+
+#include "cgroups.h"
+#include "selinux.h"
+#include "util.h"
+
+// FIXME
+#include "proctable.h"
+
+ProcInfo::UserMap ProcInfo::users;
+ProcInfo::List ProcInfo::all;
+std::map<pid_t, guint64> ProcInfo::cpu_times;
+
+ProcInfo* ProcInfo::find(pid_t pid)
+{
+ Iterator it(ProcInfo::all.find(pid));
+ return (it == ProcInfo::all.end() ? NULL : it->second);
+}
+
+ProcInfo::~ProcInfo()
+{
+ g_free(this->name);
+ g_free(this->tooltip);
+ g_free(this->arguments);
+ g_free(this->security_context);
+ g_free(this->cgroup_name);
+ // The following are allocated inside of the sd_pid_get_*
+ // functions using malloc(). Free with free() instead of g_free()
+ // to insure proper clean up.
+ free(this->unit);
+ free(this->session);
+ free(this->seat);
+}
+
+static void
+get_process_name (ProcInfo *info,
+ const gchar *cmd, const GStrv args)
+{
+ if (args) {
+ // look for /usr/bin/very_long_name
+ // and also /usr/bin/interpreter /usr/.../very_long_name
+ // which may have use prctl to alter 'cmd' name
+ for (int i = 0; i != 2 && args[i]; ++i) {
+ char* basename;
+ basename = g_path_get_basename(args[i]);
+
+ if (g_str_has_prefix(basename, cmd)) {
+ info->name = basename;
+ return;
+ }
+
+ g_free(basename);
+ }
+ }
+
+ info->name = g_strdup (cmd);
+}
+
+std::string
+ProcInfo::lookup_user(guint uid)
+{
+ typedef std::pair<ProcInfo::UserMap::iterator, bool> Pair;
+ ProcInfo::UserMap::value_type hint(uid, "");
+ Pair p(ProcInfo::users.insert(hint));
+
+ // procman_debug("User lookup for uid %u: %s", uid, (p.second ? "MISS" : "HIT"));
+
+ if (p.second) {
+ struct passwd* pwd;
+ pwd = getpwuid(uid);
+
+ if (pwd && pwd->pw_name)
+ p.first->second = pwd->pw_name;
+ else {
+ char username[16];
+ g_sprintf(username, "%u", uid);
+ p.first->second = username;
+ }
+ }
+
+ return p.first->second;
+}
+
+void
+ProcInfo::set_user(guint uid)
+{
+ if (G_LIKELY(this->uid == uid))
+ return;
+
+ this->uid = uid;
+ this->user = lookup_user(uid);
+}
+
+void
+get_process_memory_writable (ProcInfo *info)
+{
+ glibtop_proc_map buf;
+ glibtop_map_entry *maps;
+
+ maps = glibtop_get_proc_map(&buf, info->pid);
+
+ gulong memwritable = 0;
+ const unsigned number = buf.number;
+
+ for (unsigned i = 0; i < number; ++i) {
+#ifdef __linux__
+ memwritable += maps[i].private_dirty;
+#else
+ if (maps[i].perm & GLIBTOP_MAP_PERM_WRITE)
+ memwritable += maps[i].size;
+#endif
+ }
+
+ info->memwritable = memwritable;
+
+ g_free(maps);
+}
+
+static void
+get_process_memory_info(ProcInfo *info)
+{
+ glibtop_proc_mem procmem;
+#ifdef HAVE_WNCK
+ WnckResourceUsage xresources;
+
+ wnck_pid_read_resource_usage (gdk_screen_get_display (gdk_screen_get_default ()),
+ info->pid,
+ &xresources);
+
+ info->memxserver = xresources.total_bytes_estimate;
+#endif
+
+ glibtop_get_proc_mem(&procmem, info->pid);
+
+ info->vmsize = procmem.vsize;
+ info->memres = procmem.resident;
+ info->memshared = procmem.share;
+
+ info->mem = info->memres - info->memshared;
+#ifdef HAVE_WNCK
+ info->mem += info->memxserver;
+#endif
+}
+
+static void
+get_process_systemd_info(ProcInfo *info)
+{
+#ifdef HAVE_SYSTEMD
+ uid_t uid;
+
+ if (!LOGIND_RUNNING())
+ return;
+
+ free(info->unit);
+ info->unit = NULL;
+ sd_pid_get_unit(info->pid, &info->unit);
+
+ free(info->session);
+ info->session = NULL;
+ sd_pid_get_session(info->pid, &info->session);
+
+ free(info->seat);
+ info->seat = NULL;
+
+ if (info->session != NULL)
+ sd_session_get_seat(info->session, &info->seat);
+
+ if (sd_pid_get_owner_uid(info->pid, &uid) >= 0)
+ info->owner = info->lookup_user(uid);
+ else
+ info->owner = "";
+#endif
+}
+
+void
+update_info (GsmApplication *app, ProcInfo *info)
+{
+ glibtop_proc_state procstate;
+ glibtop_proc_uid procuid;
+ glibtop_proc_time proctime;
+ glibtop_proc_kernel prockernel;
+
+ glibtop_get_proc_kernel(&prockernel, info->pid);
+ g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
+
+ glibtop_get_proc_state (&procstate, info->pid);
+ info->status = procstate.state;
+
+ glibtop_get_proc_uid (&procuid, info->pid);
+ glibtop_get_proc_time (&proctime, info->pid);
+
+ get_process_memory_info(info);
+
+ info->set_user(procstate.uid);
+
+ // if the cpu time has increased reset the status to running
+ // regardless of kernel state (#606579)
+ guint64 difference = proctime.rtime - info->cpu_time;
+ if (difference > 0)
+ info->status = GLIBTOP_PROCESS_RUNNING;
+ info->pcpu = difference * 100 / app->cpu_total_time;
+ info->pcpu = MIN(info->pcpu, 100);
+
+ if (not app->config.solaris_mode)
+ info->pcpu *= app->config.num_cpus;
+
+ ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
+ info->nice = procuid.nice;
+ info->ppid = procuid.ppid;
+
+ /* get cgroup data */
+ get_process_cgroup_info(info);
+
+ get_process_systemd_info(info);
+}
+
+ProcInfo::ProcInfo(pid_t pid)
+ : tooltip(NULL),
+ name(NULL),
+ arguments(NULL),
+ security_context(NULL),
+ pid(pid),
+ uid(-1)
+{
+ ProcInfo * const info = this;
+ glibtop_proc_state procstate;
+ glibtop_proc_time proctime;
+ glibtop_proc_args procargs;
+ gchar** arguments;
+
+ glibtop_get_proc_state (&procstate, pid);
+ glibtop_get_proc_time (&proctime, pid);
+ arguments = glibtop_get_proc_argv (&procargs, pid, 0);
+
+ /* FIXME : wrong. name and arguments may change with exec* */
+ get_process_name (info, procstate.cmd, static_cast<const GStrv>(arguments));
+
+ std::string tooltip = make_string(g_strjoinv(" ", arguments));
+ if (tooltip.empty())
+ tooltip = procstate.cmd;
+
+ info->tooltip = g_markup_escape_text(tooltip.c_str(), -1);
+
+ info->arguments = g_strescape(tooltip.c_str(), "\\\"");
+ g_strfreev(arguments);
+
+ guint64 cpu_time = proctime.rtime;
+ std::map<pid_t, guint64>::iterator it(ProcInfo::cpu_times.find(pid));
+ if (it != ProcInfo::cpu_times.end())
+ {
+ if (proctime.rtime >= it->second)
+ cpu_time = it->second;
+ }
+ info->cpu_time = cpu_time;
+ info->start_time = proctime.start_time;
+
+ get_process_selinux_context (info);
+ info->cgroup_name = NULL;
+ get_process_cgroup_info(info);
+
+ info->unit = info->session = info->seat = NULL;
+ get_process_systemd_info(info);
+}
+
+void
+ProcInfo::set_icon(Glib::RefPtr<Gdk::Pixbuf> icon)
+{
+ this->pixbuf = icon;
+
+ GtkTreeModel *model;
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (
+ gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(
+ gtk_tree_view_get_model (GTK_TREE_VIEW(GsmApplication::get()->tree))))));
+ gtk_tree_store_set(GTK_TREE_STORE(model), &this->node,
+ COL_PIXBUF, (this->pixbuf ? this->pixbuf->gobj() : NULL),
+ -1);
+}
+
diff --git a/src/procinfo.h b/src/procinfo.h
new file mode 100644
index 0000000..a8c015a
--- /dev/null
+++ b/src/procinfo.h
@@ -0,0 +1,108 @@
+/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#ifndef _GSM_PROCINFO_H_
+#define _GSM_PROCINFO_H_
+
+#include <config.h>
+
+#include <gtkmm.h>
+
+#include <application.h>
+
+struct MutableProcInfo
+{
+MutableProcInfo()
+: status(0)
+ { }
+
+ std::string user;
+
+ gchar wchan[40];
+
+ // all these members are filled with libgtop which uses
+ // guint64 (to have fixed size data) but we don't need more
+ // than an unsigned long (even for 32bit apps on a 64bit
+ // kernel) as these data are amounts, not offsets.
+ gulong vmsize;
+ gulong memres;
+ gulong memshared;
+ gulong memwritable;
+ gulong mem;
+
+#ifdef HAVE_WNCK
+ // wnck gives an unsigned long
+ gulong memxserver;
+#endif
+
+ gulong start_time;
+ guint64 cpu_time;
+ guint status;
+ guint pcpu;
+ gint nice;
+ gchar *cgroup_name;
+
+ gchar *unit;
+ gchar *session;
+ gchar *seat;
+
+ std::string owner;
+};
+
+
+class ProcInfo
+: public MutableProcInfo
+{
+ /* undefined */ ProcInfo& operator=(const ProcInfo&);
+ /* undefined */ ProcInfo(const ProcInfo&);
+
+ typedef std::map<guint, std::string> UserMap;
+ /* cached username */
+ static UserMap users;
+
+ public:
+
+ // TODO: use a set instead
+ // sorted by pid. The map has a nice property : it is sorted
+ // by pid so this helps a lot when looking for the parent node
+ // as ppid is nearly always < pid.
+ typedef std::map<pid_t, ProcInfo*> List;
+ typedef List::iterator Iterator;
+
+ static List all;
+
+ static ProcInfo* find(pid_t pid);
+ static Iterator begin() { return ProcInfo::all.begin(); }
+ static Iterator end() { return ProcInfo::all.end(); }
+
+
+ ProcInfo(pid_t pid);
+ ~ProcInfo();
+ // adds one more ref to icon
+ void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
+ void set_user(guint uid);
+ std::string lookup_user(guint uid);
+
+ GtkTreeIter node;
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf;
+ gchar *tooltip;
+ gchar *name;
+ gchar *arguments;
+
+ gchar *security_context;
+
+ const guint pid;
+ guint ppid;
+ guint uid;
+
+// private:
+ // tracks cpu time per process keeps growing because if a
+ // ProcInfo is deleted this does not mean that the process is
+ // not going to be recreated on the next update. For example,
+ // if dependencies + (My or Active), the proclist is cleared
+ // on each update. This is a workaround
+ static std::map<pid_t, guint64> cpu_times;
+};
+
+void update_info (GsmApplication *app, ProcInfo *info);
+void get_process_memory_writable (ProcInfo *info);
+
+#endif /* _GSM_PROCINFO_H_ */
diff --git a/src/procproperties.cpp b/src/procproperties.cpp
index e7311a7..8fd036f 100644
--- a/src/procproperties.cpp
+++ b/src/procproperties.cpp
@@ -32,6 +32,7 @@
#endif
#include "application.h"
+#include "procinfo.h"
#include "procproperties.h"
#include "proctable.h"
#include "util.h"
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 7f97cd3..7c877c3 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -27,32 +27,13 @@
#include <glib/gprintf.h>
#include <glibtop.h>
#include <glibtop/proclist.h>
-#include <glibtop/procstate.h>
-#include <glibtop/procmem.h>
-#include <glibtop/procmap.h>
-#include <glibtop/proctime.h>
-#include <glibtop/procuid.h>
-#include <glibtop/procargs.h>
-#include <glibtop/prockernel.h>
-#include <glibtop/mem.h>
-#include <glibtop/swap.h>
-#include <sys/stat.h>
-#include <pwd.h>
#include <time.h>
#include <set>
#include <list>
-#ifdef HAVE_SYSTEMD
-#include <systemd/sd-login.h>
-#endif
-
-#ifdef HAVE_WNCK
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-#endif
-
#include "application.h"
+#include "procinfo.h"
#include "proctable.h"
#include "prettytable.h"
#include "util.h"
@@ -62,16 +43,6 @@
#include "cgroups.h"
#include "treeview.h"
-ProcInfo::UserMap ProcInfo::users;
-ProcInfo::List ProcInfo::all;
-std::map<pid_t, guint64> ProcInfo::cpu_times;
-
-
-ProcInfo* ProcInfo::find(pid_t pid)
-{
- Iterator it(ProcInfo::all.find(pid));
- return (it == ProcInfo::all.end() ? NULL : it->second);
-}
static void
cb_save_tree_state(gpointer, gpointer data)
@@ -605,131 +576,6 @@ proctable_new (GsmApplication * const app)
return proctree;
}
-ProcInfo::~ProcInfo()
-{
- g_free(this->name);
- g_free(this->tooltip);
- g_free(this->arguments);
- g_free(this->security_context);
- g_free(this->cgroup_name);
- // The following are allocated inside of the sd_pid_get_*
- // functions using malloc(). Free with free() instead of g_free()
- // to insure proper clean up.
- free(this->unit);
- free(this->session);
- free(this->seat);
-}
-
-static void
-get_process_name (ProcInfo *info,
- const gchar *cmd, const GStrv args)
-{
- if (args) {
- // look for /usr/bin/very_long_name
- // and also /usr/bin/interpreter /usr/.../very_long_name
- // which may have use prctl to alter 'cmd' name
- for (int i = 0; i != 2 && args[i]; ++i) {
- char* basename;
- basename = g_path_get_basename(args[i]);
-
- if (g_str_has_prefix(basename, cmd)) {
- info->name = basename;
- return;
- }
-
- g_free(basename);
- }
- }
-
- info->name = g_strdup (cmd);
-}
-
-std::string
-ProcInfo::lookup_user(guint uid)
-{
- typedef std::pair<ProcInfo::UserMap::iterator, bool> Pair;
- ProcInfo::UserMap::value_type hint(uid, "");
- Pair p(ProcInfo::users.insert(hint));
-
- // procman_debug("User lookup for uid %u: %s", uid, (p.second ? "MISS" : "HIT"));
-
- if (p.second) {
- struct passwd* pwd;
- pwd = getpwuid(uid);
-
- if (pwd && pwd->pw_name)
- p.first->second = pwd->pw_name;
- else {
- char username[16];
- g_sprintf(username, "%u", uid);
- p.first->second = username;
- }
- }
-
- return p.first->second;
-}
-
-void
-ProcInfo::set_user(guint uid)
-{
- if (G_LIKELY(this->uid == uid))
- return;
-
- this->uid = uid;
- this->user = lookup_user(uid);
-}
-
-void
-get_process_memory_writable (ProcInfo *info)
-{
- glibtop_proc_map buf;
- glibtop_map_entry *maps;
-
- maps = glibtop_get_proc_map(&buf, info->pid);
-
- gulong memwritable = 0;
- const unsigned number = buf.number;
-
- for (unsigned i = 0; i < number; ++i) {
-#ifdef __linux__
- memwritable += maps[i].private_dirty;
-#else
- if (maps[i].perm & GLIBTOP_MAP_PERM_WRITE)
- memwritable += maps[i].size;
-#endif
- }
-
- info->memwritable = memwritable;
-
- g_free(maps);
-}
-
-static void
-get_process_memory_info(ProcInfo *info)
-{
- glibtop_proc_mem procmem;
-#ifdef HAVE_WNCK
- WnckResourceUsage xresources;
-
- wnck_pid_read_resource_usage (gdk_screen_get_display (gdk_screen_get_default ()),
- info->pid,
- &xresources);
-
- info->memxserver = xresources.total_bytes_estimate;
-#endif
-
- glibtop_get_proc_mem(&procmem, info->pid);
-
- info->vmsize = procmem.vsize;
- info->memres = procmem.resident;
- info->memshared = procmem.share;
-
- info->mem = info->memres - info->memshared;
-#ifdef HAVE_WNCK
- info->mem += info->memxserver;
-#endif
-}
-
static void
update_info_mutable_cols(ProcInfo *info)
{
@@ -855,126 +701,6 @@ remove_info_from_tree (GsmApplication *app, GtkTreeModel *model,
}
static void
-get_process_systemd_info(ProcInfo *info)
-{
-#ifdef HAVE_SYSTEMD
- uid_t uid;
-
- if (!LOGIND_RUNNING())
- return;
-
- free(info->unit);
- info->unit = NULL;
- sd_pid_get_unit(info->pid, &info->unit);
-
- free(info->session);
- info->session = NULL;
- sd_pid_get_session(info->pid, &info->session);
-
- free(info->seat);
- info->seat = NULL;
-
- if (info->session != NULL)
- sd_session_get_seat(info->session, &info->seat);
-
- if (sd_pid_get_owner_uid(info->pid, &uid) >= 0)
- info->owner = info->lookup_user(uid);
- else
- info->owner = "";
-#endif
-}
-
-static void
-update_info (GsmApplication *app, ProcInfo *info)
-{
- glibtop_proc_state procstate;
- glibtop_proc_uid procuid;
- glibtop_proc_time proctime;
- glibtop_proc_kernel prockernel;
-
- glibtop_get_proc_kernel(&prockernel, info->pid);
- g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
-
- glibtop_get_proc_state (&procstate, info->pid);
- info->status = procstate.state;
-
- glibtop_get_proc_uid (&procuid, info->pid);
- glibtop_get_proc_time (&proctime, info->pid);
-
- get_process_memory_info(info);
-
- info->set_user(procstate.uid);
-
- // if the cpu time has increased reset the status to running
- // regardless of kernel state (#606579)
- guint64 difference = proctime.rtime - info->cpu_time;
- if (difference > 0)
- info->status = GLIBTOP_PROCESS_RUNNING;
- info->pcpu = difference * 100 / app->cpu_total_time;
- info->pcpu = MIN(info->pcpu, 100);
-
- if (not app->config.solaris_mode)
- info->pcpu *= app->config.num_cpus;
-
- ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
- info->nice = procuid.nice;
- info->ppid = procuid.ppid;
-
- /* get cgroup data */
- get_process_cgroup_info(info);
-
- get_process_systemd_info(info);
-}
-
-ProcInfo::ProcInfo(pid_t pid)
- : tooltip(NULL),
- name(NULL),
- arguments(NULL),
- security_context(NULL),
- pid(pid),
- uid(-1)
-{
- ProcInfo * const info = this;
- glibtop_proc_state procstate;
- glibtop_proc_time proctime;
- glibtop_proc_args procargs;
- gchar** arguments;
-
- glibtop_get_proc_state (&procstate, pid);
- glibtop_get_proc_time (&proctime, pid);
- arguments = glibtop_get_proc_argv (&procargs, pid, 0);
-
- /* FIXME : wrong. name and arguments may change with exec* */
- get_process_name (info, procstate.cmd, static_cast<const GStrv>(arguments));
-
- std::string tooltip = make_string(g_strjoinv(" ", arguments));
- if (tooltip.empty())
- tooltip = procstate.cmd;
-
- info->tooltip = g_markup_escape_text(tooltip.c_str(), -1);
-
- info->arguments = g_strescape(tooltip.c_str(), "\\\"");
- g_strfreev(arguments);
-
- guint64 cpu_time = proctime.rtime;
- std::map<pid_t, guint64>::iterator it(ProcInfo::cpu_times.find(pid));
- if (it != ProcInfo::cpu_times.end())
- {
- if (proctime.rtime >= it->second)
- cpu_time = it->second;
- }
- info->cpu_time = cpu_time;
- info->start_time = proctime.start_time;
-
- get_process_selinux_context (info);
- info->cgroup_name = NULL;
- get_process_cgroup_info(info);
-
- info->unit = info->session = info->seat = NULL;
- get_process_systemd_info(info);
-}
-
-static void
refresh_list (GsmApplication *app, const pid_t* pid_list, const guint n)
{
typedef std::list<ProcInfo*> ProcList;
@@ -1169,20 +895,6 @@ proctable_free_table (GsmApplication * const app)
}
void
-ProcInfo::set_icon(Glib::RefPtr<Gdk::Pixbuf> icon)
-{
- this->pixbuf = icon;
-
- GtkTreeModel *model;
- model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (
- gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(
- gtk_tree_view_get_model (GTK_TREE_VIEW(GsmApplication::get()->tree))))));
- gtk_tree_store_set(GTK_TREE_STORE(model), &this->node,
- COL_PIXBUF, (this->pixbuf ? this->pixbuf->gobj() : NULL),
- -1);
-}
-
-void
proctable_freeze (GsmApplication *app)
{
if (app->timeout) {
diff --git a/src/proctable.h b/src/proctable.h
index 7a9ea1f..70f43bd 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -63,7 +63,6 @@ void proctable_freeze (GsmApplication *app);
void proctable_thaw (GsmApplication *app);
void proctable_reset_timeout (GsmApplication *app);
-void get_process_memory_writable (ProcInfo *info);
void get_last_selected (GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data);
diff --git a/src/selinux.cpp b/src/selinux.cpp
index a9596d5..884e1c9 100644
--- a/src/selinux.cpp
+++ b/src/selinux.cpp
@@ -4,7 +4,7 @@
#include <glib.h>
#include "selinux.h"
-#include "application.h"
+#include "procinfo.h"
#include "util.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]