s3:smbprofile: profile the system and user space cpu time
authorStefan Metzmacher <metze@samba.org>
Fri, 14 Nov 2014 11:52:33 +0000 (12:52 +0100)
committerRalph Böhme <slow@samba.org>
Fri, 6 Mar 2015 11:31:10 +0000 (12:31 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/smbprofile.h
source3/profile/profile.c
source3/wscript

index b32d938306188a3ac6a984198ab644e591fd2ed1..76d9d2b6f6fd75f750da9965f2939e3c330af5b0 100644 (file)
@@ -32,6 +32,8 @@ struct tevent_context;
        SMBPROFILE_STATS_COUNT(connect) \
        SMBPROFILE_STATS_COUNT(disconnect) \
        SMBPROFILE_STATS_BASIC(idle) \
+       SMBPROFILE_STATS_TIME(cpu_user) \
+       SMBPROFILE_STATS_TIME(cpu_system) \
        SMBPROFILE_STATS_COUNT(request) \
        SMBPROFILE_STATS_BASIC(push_sec_ctx) \
        SMBPROFILE_STATS_BASIC(set_sec_ctx) \
index 7002537354cbfb4c772571e06cc77307e7eee0a7..67b1fc765b99a2ef297781ebb091a17579b62dd2 100644 (file)
 #include "includes.h"
 #include "system/shmem.h"
 #include "system/filesys.h"
+#include "system/time.h"
 #include "messages.h"
 #include "smbprofile.h"
 #include "lib/tdb_wrap/tdb_wrap.h"
 #include <tevent.h>
 #include "../lib/crypto/crypto.h"
 
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
 struct profile_stats *profile_p;
 struct smbprofile_global_state smbprofile_state;
 
@@ -260,6 +265,9 @@ void smbprofile_dump(void)
        TDB_DATA key = { .dptr = (uint8_t *)&pid, .dsize = sizeof(pid) };
        struct profile_stats s = {};
        int ret;
+#ifdef HAVE_GETRUSAGE
+       struct rusage rself;
+#endif /* HAVE_GETRUSAGE */
 
        TALLOC_FREE(smbprofile_state.internal.te);
 
@@ -267,6 +275,20 @@ void smbprofile_dump(void)
                return;
        }
 
+#ifdef HAVE_GETRUSAGE
+       ret = getrusage(RUSAGE_SELF, &rself);
+       if (ret != 0) {
+               ZERO_STRUCT(rself);
+       }
+
+       profile_p->values.cpu_user_stats.time =
+               (rself.ru_utime.tv_sec * 1000000) +
+               rself.ru_utime.tv_usec;
+       profile_p->values.cpu_system_stats.time =
+               (rself.ru_stime.tv_sec * 1000000) +
+               rself.ru_stime.tv_usec;
+#endif /* HAVE_GETRUSAGE */
+
        ret = tdb_chainlock(smbprofile_state.internal.db->tdb, key);
        if (ret != 0) {
                return;
index 63bca9d060623ef05dbe85afc4fd462663dcf7bd..2c03c304db250f87c912b12ce805e8881403d59d 100644 (file)
@@ -1484,6 +1484,7 @@ main() {
 
     if Options.options.with_profiling_data:
         conf.DEFINE('WITH_PROFILE', 1);
+        conf.CHECK_FUNCS('getrusage', headers="sys/time.h sys/resource.h")
 
     if Options.options.with_pthreadpool:
         if conf.CONFIG_SET('HAVE_PTHREAD'):