[gnome-system-monitor] Revert some changes introduces by Artem's patches in e9173fbc..42d939e1.
- From: Benoît Dejean <bdejean src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Revert some changes introduces by Artem's patches in e9173fbc..42d939e1.
- Date: Thu, 15 Jun 2017 05:54:26 +0000 (UTC)
commit a535df9252633561d4898ed0ae0cc867b95d9cf2
Author: Benoît Dejean <bdejean gmail com>
Date: Tue Jun 13 15:29:52 2017 +0200
Revert some changes introduces by Artem's patches in e9173fbc..42d939e1.
Make ProcList::find(pid) return a pointer instead of having to deal with
exceptions. Not finding a process is common. And having big try/catch blocks
may silent legit exception.
Also move back ProcInfo initialization back to its contructor.
The whole point of having a seperate ProcList class was not to move ProcInfo
code there.
src/application.h | 8 ++---
src/openfiles.cpp | 8 +++--
src/prettytable.cpp | 3 +-
src/procproperties.cpp | 2 +-
src/proctable.cpp | 95 +++++++++++++++++++++++++-----------------------
5 files changed, 60 insertions(+), 56 deletions(-)
---
diff --git a/src/application.h b/src/application.h
index 9b70c9c..3190298 100644
--- a/src/application.h
+++ b/src/application.h
@@ -160,16 +160,14 @@ public:
typedef List::iterator Iterator;
Iterator begin() { return std::begin(data); }
Iterator end() { return std::end(data); }
- Iterator erase(List::iterator it) {
+ Iterator erase(Iterator it) {
std::lock_guard<std::mutex> lg(data_lock);
return data.erase(it);
}
- std::pair<Iterator, bool> emplace(pid_t pid);
+ ProcInfo* add(pid_t pid) { return &data.emplace(pid, pid).first->second; }
void clear() { return data.clear(); }
- ProcInfo& find(pid_t pid) {
- return data.at(pid);
- }
+ ProcInfo* find(pid_t pid);
};
class GsmApplication : public Gtk::Application, private procman::NonCopyable
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 1f6b5d2..9516f06 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -177,9 +177,11 @@ update_openfiles_dialog (GsmTreeView *tree)
guint i;
pid_t pid = GPOINTER_TO_UINT(static_cast<pid_t*>(g_object_get_data (G_OBJECT (tree), "selected_info")));
- try {
- info = &GsmApplication::get()->processes.find(pid);
- } catch (const std::out_of_range&) { return; }
+ info = GsmApplication::get()->processes.find(pid);
+
+
+ if (!info)
+ return;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
diff --git a/src/prettytable.cpp b/src/prettytable.cpp
index fe99f1a..52b9524 100644
--- a/src/prettytable.cpp
+++ b/src/prettytable.cpp
@@ -104,8 +104,7 @@ PrettyTable::register_application(pid_t pid, Glib::RefPtr<Gdk::Pixbuf> icon)
{
/* If process already exists then set the icon. Otherwise put into hash
** table to be added later */
- try {
- auto& info = GsmApplication::get()->processes.find(pid);
+ if (ProcInfo* info = GsmApplication::get()->processes.find(pid))
{
info.set_icon(icon);
// move the ref to the map
diff --git a/src/procproperties.cpp b/src/procproperties.cpp
index 216e1b2..5e751a5 100644
--- a/src/procproperties.cpp
+++ b/src/procproperties.cpp
@@ -108,7 +108,7 @@ update_procproperties_dialog (GtkTreeView *tree)
ProcInfo *info;
pid_t pid = GPOINTER_TO_UINT(static_cast<pid_t*>(g_object_get_data (G_OBJECT (tree), "selected_info")));
- try { info = &GsmApplication::get()->processes.find(pid); } catch (const std::out_of_range&) { info =
nullptr; }
+ info = GsmApplication::get()->processes.find(pid);
fill_proc_properties(tree, info);
}
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 4255262..9525587 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -63,6 +63,12 @@
#include <gdk/gdkx.h>
#endif
+ProcInfo* ProcList::find(pid_t pid)
+{
+ auto it = data.find(pid);
+ return (it == data.end() ? nullptr : &it->second);
+}
+
static void
cb_save_tree_state(gpointer, gpointer data)
{
@@ -619,42 +625,6 @@ get_process_name (ProcInfo *info,
info->name = cmd;
}
-std::pair<ProcList::Iterator, bool> ProcList::emplace(pid_t pid) {
- std::lock_guard<std::mutex> lg(data_lock);
- auto res = data.emplace(pid, pid);
- if (res.second) {
- auto& entry = res.first->second;
- glibtop_proc_state procstate;
- glibtop_proc_args procargs;
- gchar** arguments;
- glibtop_get_proc_state (&procstate, pid);
- arguments = glibtop_get_proc_argv (&procargs, pid, 0);
- /* FIXME : wrong. name and arguments may change with exec* */
- get_process_name (&entry, procstate.cmd, static_cast<const GStrv>(arguments));
- std::string tooltip = make_string(g_strjoinv(" ", arguments));
- if (tooltip.empty())
- tooltip = procstate.cmd;
- entry.tooltip = g_markup_escape_text(tooltip.c_str(), -1);
- entry.arguments = g_strescape(tooltip.c_str(), "\\\"");
- g_strfreev(arguments);
- get_process_selinux_context (&entry);
- get_process_cgroup_info(entry);
- get_process_systemd_info(&entry);
- glibtop_proc_time proctime;
- glibtop_get_proc_time (&proctime, pid);
- guint64 cpu_time = proctime.rtime;
- auto it = cpu_times.find(pid);
- if (it != std::end(cpu_times))
- {
- if (proctime.rtime >= it->second)
- cpu_time = it->second;
- }
- entry.cpu_time = cpu_time;
- entry.start_time = proctime.start_time;
- }
- return res;
-}
-
std::string
ProcInfo::lookup_user(guint uid)
{
@@ -796,7 +766,7 @@ insert_info_to_tree (ProcInfo *info, GsmApplication *app, bool forced = false)
ProcInfo *parent = 0;
if (not forced)
- try { parent = &app->processes.find(info->ppid); } catch (const std::out_of_range&) { parent =
nullptr; }
+ parent = app->processes.find(info->ppid);
if (parent) {
GtkTreePath *parent_node = gtk_tree_model_get_path(model, &parent->node);
@@ -940,6 +910,43 @@ ProcInfo::ProcInfo(pid_t pid)
ppid(-1),
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;
+ auto app = GsmApplication::get();
+ auto it = app->processes.cpu_times.find(pid);
+ if (it != app->processes.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);
+ get_process_cgroup_info(*info);
+
+ get_process_systemd_info(info);
}
static void
@@ -954,12 +961,11 @@ refresh_list (GsmApplication *app, const pid_t* pid_list, const guint n)
guint i;
// Add or update processes in the process list
- for (i = 0; i < n; ++i) {
- ProcInfo* info;
- try {
- info = &app->processes.find(pid_list[i]);
- } catch (const std::out_of_range&) {
- info = &app->processes.emplace(pid_list[i]).first->second;
+ for(i = 0; i < n; ++i) {
+ ProcInfo *info = app->processes.find(pid_list[i]);
+
+ if (!info) {
+ info = app->processes.add(pid_list[i]);
addition.push_back(info);
}
@@ -1035,8 +1041,7 @@ refresh_list (GsmApplication *app, const pid_t* pid_list, const guint n)
continue;
}
- ProcInfo* parent;
- try { parent = &app->processes.find((*it)->ppid); } catch (const std::out_of_range& e) {
parent = nullptr; }
+ ProcInfo *parent = app->processes.find((*it)->ppid);
// if the parent is unreachable
if (not parent) {
// or std::find(addition.begin(), addition.end(), parent) == addition.end()) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]