Permalink
Browse files

linux-core.c: return CPU times in ms, not ticks

  • Loading branch information...
1 parent 4b115f8 commit 38032ecda66223be365d755b754b20b6c506249a @tfeb tfeb committed Dec 31, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/unix/linux/linux-core.c
@@ -640,11 +640,17 @@ static void read_times(unsigned int numcpus, uv_cpu_info_t* ci) {
&irq))
abort();
- ts.user = clock_ticks * user;
- ts.nice = clock_ticks * nice;
- ts.sys = clock_ticks * sys;
- ts.idle = clock_ticks * idle;
- ts.irq = clock_ticks * irq;
+ /* we want values in milliseconds, not clock ticks. This is the
+ * most accurate way of doing this but is more liable to overflow.
+ * I don't think this matters as anything using these values needs
+ * to cope with potential overflows.
+ */
+
+ ts.user = (1000 * user + clock_ticks/2) / clock_ticks;
+ ts.nice = (1000 * nice + clock_ticks/2) / clock_ticks;
+ ts.sys = (1000 * sys + clock_ticks/2) / clock_ticks;
+ ts.idle = (1000 * idle + clock_ticks/2) / clock_ticks;
+ ts.irq = (1000 * irq + clock_ticks/2) / clock_ticks;
ci[num++].cpu_times = ts;
}
fclose(fp);

0 comments on commit 38032ec

Please sign in to comment.