summaryrefslogtreecommitdiff
path: root/source3/profile/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/profile/profile.c')
-rw-r--r--source3/profile/profile.c21
1 files changed, 21 insertions, 0 deletions
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);