Time gets % CPU time for a task wrong for long jobs

Bug #941925 reported by Richard Earnshaw
This bug affects 2 people
Affects Status Importance Assigned to Milestone
time (Ubuntu)

Bug Description

Ubuntu OS version: oneiric
Description: Linaro 12.01
Release: 12.01

Package: time
Priority: standard
Section: utils
Installed-Size: 148
Maintainer: Ubuntu Developers <email address hidden>
Architecture: armel
Version: 1.7-23.1
Depends: libc6 (>= 2.4)

When time is used to measure the resources used for a long job the results returned do not match up; the manual says that the %-age CPU used is the elapsed time divided by the (user+system) time consumed by the job.
The example below shows that for a job that took 34 hours to run the claimed CPU utilization was only 25%, but in reality it should be 95%.

93186.56user 24134.59system 34:07:55elapsed 25%CPU (0avgtext+0avgdata 3268608maxresident)k
0inputs+0outputs (11010major+702900386minor)pagefaults 0swaps
$ expr 93186 + 24134
$ expr 117320 / 36

ie ~32 1/2 hours

Shorter jobs (a few minutes) seem to show the correct %-age, so I suspect an overflow somewhere.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in time (Ubuntu):
status: New → Confirmed
Revision history for this message
Richard Earnshaw (richard-earnshaw) wrote :

34548.03user 2220.37system 10:26:49elapsed 97%CPU (0avgtext+0avgdata 1651664maxresident)k

Which looks fine.

10 * 3600 is 0x8ca0
20 * 3600 is 0x11940

That might suggest the overflow starts to happen at about 18:12:16

Revision history for this message
Richard Earnshaw (richard-earnshaw) wrote :

Erm, not quite. If time captures the time in milliseconds, overflow in the percentage calculation will occur after 2^32 ms, which is 11:55:49.67

Revision history for this message
Richard Earnshaw (richard-earnshaw) wrote :

Still not quite there. it's 11:55:49.67 is 2^32 / 100 ms

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers