hyptop: Use util_time helpers for time calculations

Use the common helpers in lib/util_time instead of using hardcoded
values for time calculations.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Mete Durlu <meted@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Mete Durlu
2025-12-03 12:48:32 +01:00
committed by Steffen Eiden
parent 44fdf586e1
commit 7b3add9389
5 changed files with 13 additions and 14 deletions

View File

@@ -18,6 +18,7 @@
#include "lib/util_base.h"
#include "lib/util_libc.h"
#include "lib/util_time.h"
#include "lib/zt_common.h"
#define G0(x) MAX(0, (s64) (x))

View File

@@ -112,7 +112,7 @@ static enum hyptop_win_action l_sleep(time_t time_s, long time_us)
struct timespec ts;
ts.tv_sec = time_s;
ts.tv_nsec = time_us * 1000;
ts.tv_nsec = util_usecs_to_nsecs(time_us);
nanosleep(&ts, NULL);
return WIN_KEEP;

View File

@@ -48,7 +48,7 @@ static double l_cpu_diff(struct sd_cpu_item *item, struct sd_cpu *cpu, int sign)
if (online_time_diff_us == 0)
return 0;
factor = ((double) online_time_diff_us) / 1000000 * cpu->cnt;
factor = util_usecs_to_secs(online_time_diff_us) * cpu->cnt;
if (sign)
diff_us = l_cpu_info_s64(cpu->d_cur, item->offset) -
l_cpu_info_s64(cpu->d_prev, item->offset);

View File

@@ -171,7 +171,7 @@ static double l_cpu_info_diff_u64(struct sd_sys_item *item, struct sd_cpu *cpu,
diff_us = l_sub_64(l_cpu_info_u64(cpu->d_cur, item->offset),
l_cpu_info_u64(cpu->d_prev, item->offset));
}
factor = ((double) online_time_diff_us) / 1000000;
factor = util_usecs_to_secs(online_time_diff_us);
diff_us /= factor;
return diff_us;
}
@@ -237,7 +237,7 @@ static double l_phys_cpu_info_diff_u64(struct sd_sys_item *item,
return 0;
diff_us = l_sub_64(l_cpu_info_u64(cpu->d_cur, item->offset),
l_cpu_info_u64(cpu->d_prev, item->offset));
factor = ((double)time_diff_us) / 1000000;
factor = util_usecs_to_secs(time_diff_us);
diff_us /= factor;
return diff_us;
}

View File

@@ -153,7 +153,7 @@ struct table_col_unit table_col_unit_us = {
*/
static int l_unit_ms(struct table_col *col, struct table_entry *e)
{
return l_unit_raw_div(col, e, 1000, L_COL_FMT_STR_2);
return l_unit_raw_div(col, e, USEC_PER_MSEC, L_COL_FMT_STR_2);
}
struct table_col_unit table_col_unit_ms = {
@@ -167,7 +167,7 @@ struct table_col_unit table_col_unit_ms = {
*/
static int l_unit_perc(struct table_col *col, struct table_entry *e)
{
return l_unit_raw_div(col, e, 10000, L_COL_FMT_STR_2);
return l_unit_raw_div(col, e, (USEC_PER_SEC / 100), L_COL_FMT_STR_2);
}
struct table_col_unit table_col_unit_perc = {
@@ -182,7 +182,7 @@ struct table_col_unit table_col_unit_perc = {
*/
static int l_unit_s(struct table_col *col, struct table_entry *e)
{
return l_unit_raw_div(col, e, 1000000, L_COL_FMT_STR_2);
return l_unit_raw_div(col, e, USEC_PER_SEC, L_COL_FMT_STR_2);
}
struct table_col_unit table_col_unit_s = {
@@ -197,7 +197,7 @@ struct table_col_unit table_col_unit_s = {
*/
static int l_unit_m(struct table_col *col, struct table_entry *e)
{
return l_unit_raw_div(col, e, 1000000 * 60, L_COL_FMT_STR_0);
return l_unit_raw_div(col, e, USEC_PER_SEC * 60, L_COL_FMT_STR_0);
}
static struct table_col_unit table_col_unit_m = {
@@ -214,7 +214,7 @@ static int l_unit_hm_u64(char *str, u64 v1, int negative)
{
u64 time_tmp, time_h, time_m;
time_tmp = v1 / (1000000 * 60);
time_tmp = v1 / (USEC_PER_SEC * 60);
time_h = time_tmp / 60;
time_m = time_tmp - time_h * 60;
@@ -259,7 +259,7 @@ static int l_unit_dhm_u64(char *str, u64 v1, int negative)
{
u64 time_tmp, time_d, time_h, time_m;
time_tmp = v1 / (1000000 * 60);
time_tmp = v1 / (USEC_PER_SEC * 60);
time_d = time_tmp / (60 * 24);
time_h = time_tmp / 60 - time_d * 24;
time_m = time_tmp - time_h * 60 - time_d * 60 * 24;
@@ -312,10 +312,8 @@ static int l_unit_vis(struct table_col *col, struct table_entry *e)
assert(col->type == TABLE_COL_TYPE_U64);
sprintf(e->str, "|");
val1_perc = e->d.u64.v1;
val1_perc /= 1000000;
val2_perc = e->d.u64.v2;
val2_perc /= 1000000;
val1_perc = util_usecs_to_secs(e->d.u64.v1);
val2_perc = util_usecs_to_secs(e->d.u64.v2);
val1_nr = (val1_perc * L_VISUAL_ROW_CNT) + 0.5;
val2_nr = (val2_perc * L_VISUAL_ROW_CNT) + 0.5;