From 826614ed16e0fb23d30305990dbfa357b4366de2 Mon Sep 17 00:00:00 2001 From: James Peach Date: Mon, 8 May 2006 03:20:49 +0000 Subject: r15508: Use clock_gettime for profiling timstamps if it is available. Use the fastest clock available on uniprocessors. (This used to be commit d44862928206b524f826bd7c2997ab5353c0b6a0) --- source3/profile/profile.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source3/profile') diff --git a/source3/profile/profile.c b/source3/profile/profile.c index db8a643042..bacf00eb01 100644 --- a/source3/profile/profile.c +++ b/source3/profile/profile.c @@ -28,6 +28,9 @@ #ifdef WITH_PROFILE static int shm_id; static BOOL read_only; +#if defined(HAVE_CLOCK_GETTIME) +clockid_t __profile_clock; +#endif #endif struct profile_header *profile_h; @@ -103,6 +106,24 @@ BOOL profile_setup(BOOL rdonly) read_only = rdonly; +#if defined(HAVE_CLOCK_GETTIME) + if (this_is_smp()) { + /* This is faster that gettimeofday, but not fast enough to + * leave it enabled in production. + */ + __profile_clock = CLOCK_MONOTONIC; + } else { + /* CLOCK_PROCESS_CPUTIME_ID is sufficiently fast that the + * always profiling times is plausible. Unfortunately it is + * only accurate if we can guarantee we will not be scheduled + * onto a different CPU between samples. Until there is some + * way to set processor affinity, we can only use this on + * uniprocessors. + */ + __profile_clock = CLOCK_PROCESS_CPUTIME_ID; + } +#endif + again: /* try to use an existing key */ shm_id = shmget(PROF_SHMEM_KEY, 0, 0); -- cgit