Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Nov 1998 18:24:09 -0800
From:      Ben Jackson <ben@ben.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   why does getrusage ru_utime jump backwards sometimes?
Message-ID:  <199811230224.SAA08999@pulsar.ben.com>

next in thread | raw e-mail | index | archive | help
I'm trying to use getrusage(RUSAGE_SELF) to measure how much CPU time
something is taking (no, I can't use regular profiling for this).  I'm
running into a problem with occasional *negative* deltas between two
calls to getrusage.  The following program illustrates it:

	#include <sys/time.h>
	#include <sys/resource.h>

	main()
	{
		struct rusage ru;

		while (1) {
			getrusage(RUSAGE_SELF, &ru);
			printf("%d %d\n", ru.ru_utime.tv_sec,
					  ru.ru_utime.tv_usec);
		}
	}

If you run this (and pipe to uniq to cut the output a bit) you'll see
places where the ru.utime.tv_usec goes backwards...  Here's an example:

	0 14090
	0 14092
	0 14094
	0 14096
	0 14098
	0 14100
	0 11283
	0 11285
	0 11286
	0 11288
	0 11290
	0 11291
	0 11293
	0 11294

so each call normally goes up 2us, but sometimes jumps back 3ms!  This
happens on my PII 350 and my P120.  My system info:

FreeBSD pulsar.ben.com 2.2.7-RELEASE FreeBSD 2.2.7-RELEASE #0: Sun Sep 13 04:49:04 PDT 1998     bjj@pulsar.ben.com:/usr/src/sys/compile/PULSAR  i386

--Ben

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811230224.SAA08999>