PIDS_TICS_ALL_DELTA returns 0
Hi, I encountered an issue when using the procps library. The PIDS_TICS_ALL_DELTA
value returns 0 when the PIDS_UTILIZATION_C
output is commented out. When the PIDS_UTILIZATION_C output is printed, the PIDS_TICS_ALL_DELTA value returns as expected.
propc version:4.0.4
Here is my code, is something wrong?
#include <libproc2/pids.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
struct pids_info *info = NULL;
unsigned pids[] = {getpid()};
enum pids_item items[] = {
PIDS_ID_PID,
PIDS_UTILIZATION,
PIDS_UTILIZATION_C,
PIDS_TICS_ALL_DELTA,
};
enum rel_items
{
pid,
utilization,
utilization_c,
delta,
};
procps_pids_new(&info, items, sizeof(items) / sizeof(items[0]));
for (int n = 0; n < 1000000; n++)
{
struct pids_fetch *result = procps_pids_select(info, pids, 1, PIDS_SELECT_PID);
for (int i = 0; i < result->counts->total; i++)
{
printf("PID: %lld\n", PIDS_VAL(pid, s_int, result->stacks[i], NULL));
// if not printf utilization_c, the delta value is 0.
printf("PIDS_UTILIZATION_C:%f\n",PIDS_VAL(utilization_c, real, result->stacks[i], NULL));
printf("delta:%f\n", PIDS_VAL(delta, u_int, result->stacks[i], NULL));
}
procps_pids_reset(info, items, sizeof(items) / sizeof(items[0]));
}
procps_pids_unref(&info);
return 0;
}
Edited by Cherilyn Buren