Skip to content

Commit

Permalink
darwin: nanoseconds to centi-seconds minor improvement
Browse files Browse the repository at this point in the history
Avoid the use of floating point division when integer division can do
it.
A follow-up of commit 9944d55.
  • Loading branch information
Explorer09 committed Feb 25, 2025
1 parent 77132de commit 5570fe4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ static void DarwinProcess_updateCmdLine(const struct kinfo_proc* k, Process* pro
Process_updateCmdline(proc, k->kp_proc.p_comm, 0, strlen(k->kp_proc.p_comm));
}

// Converts nanoseconds to hundredths of a second (centiseconds) as needed by the "time" field of the Process struct.
static inline unsigned long long int nanosecondsToCentiseconds(uint64_t nanoseconds) {
return nanoseconds / 10000000U;
}

static char* DarwinProcess_getDevname(dev_t dev) {
if (dev == NODEV) {
return NULL;
Expand Down Expand Up @@ -383,7 +388,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
Process_updateCPUFieldWidths(proc->super.percent_cpu);

proc->super.state = pti.pti_numrunning > 0 ? RUNNING : SLEEPING;
proc->super.time = total_current_time_ns / 1e7;
proc->super.time = nanosecondsToCentiseconds(total_current_time_ns);
proc->super.nlwp = pti.pti_threadnum;
proc->super.m_virt = pti.pti_virtual_size / ONE_K;
proc->super.m_resident = pti.pti_resident_size / ONE_K;
Expand Down

0 comments on commit 5570fe4

Please sign in to comment.