Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.4:Update
powerpc-utils.21082
lparstat-Use-get_delta_value-helper.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File lparstat-Use-get_delta_value-helper.patch of Package powerpc-utils.21082
From 72feeecfdf381078a555d2841008409950da6c9f Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Date: Fri, 15 May 2020 11:13:11 +0530 Subject: [PATCH] lparstat: Use get_delta_value() helper Patch-mainline: v1.3.8 Git-commit: c6c0a86c41d81e85a2e68587ce280bdcff40d079 Use get_delta_value(), helper, to calculate the delta of interested values instead of duplicating it in various functions. This reduces the amount of duplication and makes code more readable. Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com> --- src/lparstat.c | 58 +++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/lparstat.c b/src/lparstat.c index 350155b1cd26..b01f28a7e59c 100644 --- a/src/lparstat.c +++ b/src/lparstat.c @@ -100,18 +100,6 @@ void get_time() (long long)t.tv_sec * 1000000LL + (long long)t.tv_usec); } -long long elapsed_time() -{ - long long newtime, oldtime = 0; - struct sysentry *se; - - se = get_sysentry("time"); - newtime = strtoll(se->value, NULL, 0); - oldtime = strtoll(se->old_value, NULL, 0); - - return newtime - oldtime; -} - int get_time_base() { FILE *f; @@ -171,27 +159,25 @@ void get_cpu_physc(struct sysentry *unused_se, char *buf) { struct sysentry *se; float elapsed; - float new_purr, old_purr; + float delta_purr; float timebase, physc; - float new_tb, old_tb; + float delta_tb; - se = get_sysentry("purr"); - new_purr = strtoll(se->value, NULL, 0); - old_purr = strtoll(se->old_value, NULL, 0); + delta_purr = get_delta_value("purr"); se = get_sysentry("tbr"); if (se->value[0] != '\0') { - new_tb = strtoll(se->value, NULL, 0); - old_tb = strtoll(se->old_value, NULL, 0); + delta_tb = get_delta_value("tbr"); - physc = (new_purr - old_purr) / (new_tb - old_tb); + physc = delta_purr / delta_tb; } else { - elapsed = elapsed_time() / 1000000.0; + elapsed = get_delta_value("time"); + elapsed = elapsed / 1000000.0; se = get_sysentry("timebase"); timebase = atoi(se->value); - physc = (new_purr - old_purr)/timebase/elapsed; + physc = delta_purr/timebase/elapsed; } sprintf(buf, "%.2f", physc); @@ -213,7 +199,7 @@ void get_cpu_app(struct sysentry *unused_se, char *buf) { struct sysentry *se; float timebase, app, elapsed_time; - long long new_app, old_app, newtime, oldtime; + long long new_app, old_app, delta_time; char *descr, uptime[32]; se = get_sysentry("time"); @@ -227,9 +213,8 @@ void get_cpu_app(struct sysentry *unused_se, char *buf) } elapsed_time = atof(uptime); } else { - newtime = strtoll(se->value, NULL, 0); - oldtime = strtoll(se->old_value, NULL, 0); - elapsed_time = (newtime - oldtime) / 1000000.0; + delta_time = get_delta_value("time"); + elapsed_time = delta_time / 1000000.0; } se = get_sysentry("timebase"); @@ -565,27 +550,14 @@ void get_smt_mode(struct sysentry *se, char *buf) sprintf(buf, "%c", line[4]); } -long long get_cpu_time_diff() -{ - long long old_total = 0, new_total = 0; - struct sysentry *se; - - se = get_sysentry("cpu_total"); - new_total = strtoll(se->value, NULL, 0); - old_total = strtoll(se->old_value, NULL, 0); - - return new_total - old_total; -} - void get_cpu_stat(struct sysentry *se, char *buf) { float percent; - long long total, old_val, new_val; + long long total, delta_val; - total = get_cpu_time_diff(); - new_val = atoll(se->value); - old_val = atoll(se->old_value); - percent = ((new_val - old_val)/(long double)total) * 100; + total = get_delta_value("cpu_total"); + delta_val = get_delta_value(se->name); + percent = (delta_val/(long double)total) * 100; sprintf(buf, "%.2f", percent); } -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor