Skip to content

Commit

Permalink
darwin: fix conversion from nano-seconds to centi-seconds
Browse files Browse the repository at this point in the history
Fixes: #1619
  • Loading branch information
aestriplex committed Feb 25, 2025
1 parent 802494f commit 9944d55
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ 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 long long int nanosecondsToCentiseconds(uint64_t nanoseconds) {
const uint64_t centiseconds_per_second = 100;
const uint64_t nanoseconds_per_second = 1e9;
return nanoseconds / nanoseconds_per_second * centiseconds_per_second;
}

static char* DarwinProcess_getDevname(dev_t dev) {
if (dev == NODEV) {
return NULL;
Expand Down Expand Up @@ -391,7 +384,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 = nanosecondsToCentiseconds(total_current_time_ns);
proc->super.time = total_current_time_ns / 1e7;

This comment has been minimized.

Copy link
@Explorer09

Explorer09 Feb 25, 2025

Contributor

@aestriplex Maybe I was too late to review this one, but what the point of removing the nanosecondsToCentiseconds function?

Isn't it more convenient to keep an inline function like this?

static long long int nanosecondsToCentiseconds(uint64_t nanoseconds) {
   return nanoseconds / (uint64_t)1e7;
}

By the way, note the (uint64_t) cast, because we don't need a floating point devision for this.

This comment has been minimized.

Copy link
@Explorer09

Explorer09 Feb 25, 2025

Contributor

I made this suggested change into #1623

This comment has been minimized.

Copy link
@aestriplex

aestriplex Feb 25, 2025

Author Contributor

Yes, thank you. I wrote it in the issue, but I forgot to make the change once I open the pr

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 9944d55

Please sign in to comment.