[gnome-system-monitor/wip/procinforefactor: 1/5] Start splitting ProcInfo in its own files
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor/wip/procinforefactor: 1/5] Start splitting ProcInfo in its own files
- Date: Sat, 3 Aug 2013 13:25:27 +0000 (UTC)
commit 0b018d966d6c3a802982deafffa3c1ba4f3b0060
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sat Aug 3 12:06:18 2013 +0200
Start splitting ProcInfo in its own files
src/Makefile.am | 1 +
src/cgroups.cpp | 2 +-
src/lsof.cpp | 2 +-
src/memmaps.cpp | 1 +
src/openfiles.cpp | 1 +
src/prettytable.cpp | 1 +
src/procactions.cpp | 2 +
src/procdialogs.cpp | 2 +
src/procinfo.cpp | 305 ++++++++++++++++++++++++++++++++++++++++++++++++
src/procinfo.h | 108 +++++++++++++++++
src/procman-app.h | 99 ----------------
src/procproperties.cpp | 1 +
src/proctable.cpp | 285 +-------------------------------------------
src/proctable.h | 1 -
src/selinux.cpp | 2 +-
src/smooth_refresh.cpp | 1 +
16 files changed, 433 insertions(+), 381 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 7969980..bb41f27 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ gnome_system_monitor_cpp_files = \
interface.cpp \
load-graph.cpp \
proctable.cpp \
+ procinfo.cpp \
prettytable.cpp \
util.cpp \
procactions.cpp \
diff --git a/src/cgroups.cpp b/src/cgroups.cpp
index 1d1d463..039b879 100644
--- a/src/cgroups.cpp
+++ b/src/cgroups.cpp
@@ -4,7 +4,7 @@
#include <glib.h>
#include <glib/gi18n.h>
-#include "procman-app.h"
+#include "procinfo.h"
#include "util.h"
gboolean
diff --git a/src/lsof.cpp b/src/lsof.cpp
index 69c93b0..7692249 100644
--- a/src/lsof.cpp
+++ b/src/lsof.cpp
@@ -17,7 +17,7 @@
#include <glibmm/regex.h>
-#include "procman-app.h"
+#include "procinfo.h"
#include "lsof.h"
#include "util.h"
diff --git a/src/memmaps.cpp b/src/memmaps.cpp
index cc8323c..38fadb8 100644
--- a/src/memmaps.cpp
+++ b/src/memmaps.cpp
@@ -18,6 +18,7 @@ using std::string;
#include "procman-app.h"
#include "memmaps.h"
#include "proctable.h"
+#include "procinfo.h"
#include "util.h"
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 7c2697c..4a784ee 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -13,6 +13,7 @@
#include "procman-app.h"
#include "openfiles.h"
#include "proctable.h"
+#include "procinfo.h"
#include "util.h"
#include "settings-keys.h"
diff --git a/src/prettytable.cpp b/src/prettytable.cpp
index 213861b..ca5b584 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 44db660..ba4764e 100644
--- a/src/procactions.cpp
+++ b/src/procactions.cpp
@@ -26,9 +26,11 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
+
#include "procactions.h"
#include "procman-app.h"
#include "proctable.h"
+#include "procinfo.h"
#include "procdialogs.h"
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index 2a1654e..8bca9c3 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -28,6 +28,8 @@
#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..9ee0ce3
--- /dev/null
+++ b/src/procinfo.cpp
@@ -0,0 +1,305 @@
+/* -*- 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);
+}
+
+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
+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
+}
+
+void
+update_info (ProcmanApp *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);
+}
+
+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);
+}
+
+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(ProcmanApp::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..c3bd791
--- /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 <procman-app.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 (ProcmanApp *app, ProcInfo *info);
+void get_process_memory_writable (ProcInfo *info);
+
+#endif /* _GSM_PROCINFO_H_ */
diff --git a/src/procman-app.h b/src/procman-app.h
index dcbd0fc..ec796f4 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -5,7 +5,6 @@
#include <gtkmm.h>
#include <glibtop/cpu.h>
-struct ProcInfo;
struct LoadGraph;
#include "smooth_refresh.h"
@@ -43,104 +42,6 @@ struct ProcConfig
bool network_in_bits;
};
-
-
-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 ProcmanApp : public Gtk::Application
{
private:
diff --git a/src/procproperties.cpp b/src/procproperties.cpp
index e9b8ca0..978012a 100644
--- a/src/procproperties.cpp
+++ b/src/procproperties.cpp
@@ -35,6 +35,7 @@
#include "procman-app.h"
#include "procproperties.h"
#include "proctable.h"
+#include "procinfo.h"
#include "util.h"
enum
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 266fa0c..55bd09d 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -39,40 +39,28 @@
#include <glibtop/mem.h>
#include <glibtop/swap.h>
#include <sys/stat.h>
-#include <pwd.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 "procman-app.h"
#include "proctable.h"
-#include "prettytable.h"
-#include "util.h"
+
+#include "cgroups.h"
#include "interface.h"
+#include "prettytable.h"
+#include "procinfo.h"
+#include "procman-app.h"
#include "selinux.h"
-#include "cgroups.h"
-
-ProcInfo::UserMap ProcInfo::users;
-ProcInfo::List ProcInfo::all;
-std::map<pid_t, guint64> ProcInfo::cpu_times;
+#include "util.h"
-ProcInfo* ProcInfo::find(pid_t pid)
-{
- Iterator it(ProcInfo::all.find(pid));
- return (it == ProcInfo::all.end() ? NULL : it->second);
-}
-
static void
cb_columns_changed(GtkTreeView *treeview, gpointer data)
{
@@ -678,131 +666,6 @@ proctable_new (ProcmanApp * 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)
{
@@ -928,126 +791,6 @@ remove_info_from_tree (ProcmanApp *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 (ProcmanApp *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 (ProcmanApp *app, const pid_t* pid_list, const guint n)
{
typedef std::list<ProcInfo*> ProcList;
@@ -1269,20 +1012,6 @@ make_loadavg_string(void)
}
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(ProcmanApp::get()->tree))))));
- gtk_tree_store_set(GTK_TREE_STORE(model), &this->node,
- COL_PIXBUF, (this->pixbuf ? this->pixbuf->gobj() : NULL),
- -1);
-}
-
-void
proctable_freeze (ProcmanApp *app)
{
if (app->timeout) {
diff --git a/src/proctable.h b/src/proctable.h
index 291b620..fee0f3c 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -70,7 +70,6 @@ void proctable_set_columns_order(GtkTreeView *treeview, GSList *order
char* make_loadavg_string(void);
-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 4c45cad..884e1c9 100644
--- a/src/selinux.cpp
+++ b/src/selinux.cpp
@@ -4,7 +4,7 @@
#include <glib.h>
#include "selinux.h"
-#include "procman-app.h"
+#include "procinfo.h"
#include "util.h"
diff --git a/src/smooth_refresh.cpp b/src/smooth_refresh.cpp
index 3138657..bad2015 100644
--- a/src/smooth_refresh.cpp
+++ b/src/smooth_refresh.cpp
@@ -13,6 +13,7 @@
#include "smooth_refresh.h"
#include "procman-app.h"
+#include "procinfo.h"
#include "util.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]