[Xfce4-commits] [apps/xfce4-taskmanager] 01/02: Properly use float for constants where appropriate (bug 14401, bug 14403)
noreply at xfce.org
noreply at xfce.org
Sat May 26 23:53:09 CEST 2018
This is an automated email from the git hooks/post-receive script.
l a n d r y p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-taskmanager.
commit 704411a38b906e4a70d6cff3afe60d281ef8ebc7
Author: rim <rozhuk.im at gmail.com>
Date: Sat May 26 23:51:32 2018 +0200
Properly use float for constants where appropriate (bug 14401, bug 14403)
---
src/main.c | 4 ++--
src/process-monitor.c | 4 ++--
src/process-window.c | 4 ++--
src/task-manager-bsd.c | 6 +++---
src/task-manager-freebsd.c | 10 +++++-----
src/task-manager-linux.c | 12 ++++++------
src/task-manager-skel.c | 2 +-
src/task-manager-solaris.c | 8 ++++----
8 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/src/main.c b/src/main.c
index 914ea3a..3960f6d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -93,8 +93,8 @@ init_timeout (void)
xtm_task_manager_get_system_info (task_manager, &num_processes, &cpu, &memory_used, &memory_total, &swap_used, &swap_total);
- memory_percent = (memory_total != 0) ? memory_used * 100 / (gdouble)memory_total : 0;
- swap_percent = (swap_total != 0) ? swap_used * 100 / (gdouble)swap_total : 0;
+ memory_percent = (memory_total != 0) ? ((memory_used * 100.0f) / (float)memory_total) : 0.0f;
+ swap_percent = (swap_total != 0) ? ((swap_used * 100.0f) / (float)swap_total) : 0.0f;
g_object_get (settings, "show-memory-in-xbytes", &show_memory_in_xbytes, NULL);
if (show_memory_in_xbytes) {
diff --git a/src/process-monitor.c b/src/process-monitor.c
index 726b85d..4d48223 100644
--- a/src/process-monitor.c
+++ b/src/process-monitor.c
@@ -63,7 +63,7 @@ xtm_process_monitor_class_init (XtmProcessMonitorClass *klass)
widget_class->expose_event = xtm_process_monitor_expose;
#endif
g_object_class_install_property (class, PROP_STEP_SIZE,
- g_param_spec_float ("step-size", "StepSize", "Step size", 0.1, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
+ g_param_spec_float ("step-size", "StepSize", "Step size", 0.1f, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_TYPE,
g_param_spec_int ("type", "Type", "Type of graph to render", 0, G_MAXINT, 0, G_PARAM_READWRITE));
}
@@ -267,7 +267,7 @@ void
xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak)
{
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
- g_return_if_fail (peak >= 0.0 && peak <= 1.0);
+ g_return_if_fail (peak >= 0.0f && peak <= 1.0f);
g_array_prepend_val (monitor->history, peak);
if (monitor->history->len > 1)
diff --git a/src/process-window.c b/src/process-window.c
index 4e907a3..b079e05 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -565,12 +565,12 @@ xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processe
g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, NULL);
- xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0);
+ xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0f);
g_snprintf (value, sizeof(value), "%.0f", cpu);
g_snprintf (text, sizeof(text), _("CPU: %s%%"), value);
gtk_widget_set_tooltip_text (window->cpu_monitor, text);
- xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0);
+ xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0f);
g_snprintf (text, sizeof(text), _("Memory: %s"), memory_str);
gtk_widget_set_tooltip_text (window->mem_monitor, text);
}
diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c
index fcdeec5..48b9e88 100644
--- a/src/task-manager-bsd.c
+++ b/src/task-manager-bsd.c
@@ -142,7 +142,7 @@ gboolean get_task_list (GArray *task_list)
}
t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE));
- t.cpu_system = 0; /* TODO ? */
+ t.cpu_system = 0.0f; /* TODO ? */
/* get username from uid */
passwdp = getpwuid(t.uid);
if(passwdp != NULL && passwdp->pw_name != NULL)
@@ -208,8 +208,8 @@ gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system
cur_system = cp_time[CP_SYS] + cp_time[CP_INTR];
cur_total = cur_user + cur_system + cp_time[CP_IDLE];
- *cpu_user = (old_total > 0) ? (cur_user - old_user) * 100 / (gdouble)(cur_total - old_total) : 0;
- *cpu_system = (old_total > 0) ? (cur_system - old_system) * 100 / (gdouble)(cur_total - old_total) : 0;
+ *cpu_user = (old_total > 0) ? (((cur_user - old_user) * 100.0f) / (float)(cur_total - old_total)) : 0.0f;
+ *cpu_system = (old_total > 0) ? (((cur_system - old_system) * 100.0f) / (float)(cur_total - old_total)) : 0.0f;
/* get #cpu */
size = sizeof(&cpu_count);
diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c
index 3fc52fe..f3f642d 100644
--- a/src/task-manager-freebsd.c
+++ b/src/task-manager-freebsd.c
@@ -104,11 +104,11 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
cp_system = cpu_state[CP_SYS] + cpu_state[CP_INTR];
cp_total = cpu_state[CP_IDLE] + cp_user + cp_system;
- *cpu_user = *cpu_system = 0.0;
+ *cpu_user = *cpu_system = 0.0f;
if (cp_total > cp_total_old)
{
- *cpu_user = (cp_user - cp_user_old) * 100 / (gdouble)(cp_total - cp_total_old);
- *cpu_system = (cp_system - cp_system_old) * 100 / (gdouble)(cp_total - cp_total_old);
+ *cpu_user = (((cp_user - cp_user_old) * 100.0f) / (float)(cp_total - cp_total_old));
+ *cpu_system = (((cp_system - cp_system_old) * 100.0f) / (float)(cp_total - cp_total_old));
}
}
@@ -125,8 +125,8 @@ get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task)
bzero(task, sizeof(Task));
task->pid = kp->ki_pid;
task->ppid = kp->ki_ppid;
- task->cpu_user = 100 * ((double)kp->ki_pctcpu / FSCALE);
- task->cpu_system = 0;
+ task->cpu_user = 100.0f * ((float)kp->ki_pctcpu / FSCALE);
+ task->cpu_system = 0.0f;
task->vsz = kp->ki_size;
task->rss = kp->ki_rssize * getpagesize ();
pw = getpwuid (kp->ki_uid);
diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index 3828e10..0ae3b0b 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -98,12 +98,12 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
jiffies_system = system;
jiffies_total = jiffies_user + jiffies_system + idle;
- *cpu_user = *cpu_system = 0.0;
+ *cpu_user = *cpu_system = 0.0f;
if (jiffies_total > jiffies_total_old)
{
jiffies_total_delta = jiffies_total - jiffies_total_old;
- *cpu_user = (jiffies_user - jiffies_user_old) * 100 / (gdouble)(jiffies_total_delta);
- *cpu_system = (jiffies_system - jiffies_system_old) * 100 / (gdouble)(jiffies_total_delta);
+ *cpu_user = (((jiffies_user - jiffies_user_old) * 100.0f) / (float)jiffies_total_delta);
+ *cpu_system = (((jiffies_system - jiffies_system_old) * 100.0f) / (float)jiffies_total_delta);
}
*cpu_count = _cpu_count;
@@ -178,12 +178,12 @@ get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffie
if (_cpu_count > 0 && jiffies_total_delta > 0)
{
- *cpu_user = (jiffies_user - jiffies_user_old) * 100 / (gdouble)jiffies_total_delta;
- *cpu_system = (jiffies_system - jiffies_system_old) * 100 / (gdouble)jiffies_total_delta;
+ *cpu_user = (((jiffies_user - jiffies_user_old) * 100.0f) / (float)jiffies_total_delta);
+ *cpu_system = (((jiffies_system - jiffies_system_old) * 100.0f) / (float)jiffies_total_delta);
}
else
{
- *cpu_user = *cpu_system = 0;
+ *cpu_user = *cpu_system = 0.0f;
}
}
diff --git a/src/task-manager-skel.c b/src/task-manager-skel.c
index 4f085da..8ca6d7e 100644
--- a/src/task-manager-skel.c
+++ b/src/task-manager-skel.c
@@ -41,7 +41,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_c
gboolean
get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
{
- *cpu_user = *cpu_system = 0.0;
+ *cpu_user = *cpu_system = 0.0f;
*cpu_count = 0; /*_cpu_count;*/
return TRUE;
diff --git a/src/task-manager-solaris.c b/src/task-manager-solaris.c
index ae0edd0..1f1b106 100644
--- a/src/task-manager-solaris.c
+++ b/src/task-manager-solaris.c
@@ -112,12 +112,12 @@ get_cpu_percent (guint pid, gulong ticks_user, gfloat *cpu_user, gulong ticks_sy
if (_cpu_count > 0 && ticks_total_delta > 0)
{
- *cpu_user = (ticks_user - ticks_user_old) * 100 / (gdouble)ticks_total_delta;
- *cpu_system = (ticks_system - ticks_system_old) * 100 / (gdouble)ticks_total_delta;
+ *cpu_user = (((ticks_user - ticks_user_old) * 100.0f) / (float)ticks_total_delta);
+ *cpu_system = (((ticks_system - ticks_system_old) * 100.0f) / (float)ticks_total_delta);
}
else
{
- *cpu_user = *cpu_system = 0;
+ *cpu_user = *cpu_system = 0.0f;
}
}
@@ -198,7 +198,7 @@ get_task_details (guint pid, Task *task)
pw = getpwuid (process.pr_uid);
task->uid = (guint)process.pr_uid;
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
- get_cpu_percent (task->pid, process.pr_time.tv_sec * 1000 + process.pr_time.tv_nsec / 100000, &task->cpu_user, 0, &task->cpu_system);
+ get_cpu_percent (task->pid, (process.pr_time.tv_sec * 1000 + process.pr_time.tv_nsec / 100000), &task->cpu_user, 0, &task->cpu_system);
fclose (file);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list