diff options
author | Stefan Metzmacher <metze@samba.org> | 2014-11-14 12:52:33 +0100 |
---|---|---|
committer | Ralph Böhme <slow@samba.org> | 2015-03-06 12:31:10 +0100 |
commit | b9f9869d1bec7cff6682d3cda774dcbb2464223b (patch) | |
tree | 2bb1d14b684945bd653398097214cdde33fdf9ca | |
parent | 74a16a1094278d2c5c8ac800a4f7ed4553d7ac85 (diff) | |
download | samba-b9f9869d1bec7cff6682d3cda774dcbb2464223b.tar.gz samba-b9f9869d1bec7cff6682d3cda774dcbb2464223b.tar.xz samba-b9f9869d1bec7cff6682d3cda774dcbb2464223b.zip |
s3:smbprofile: profile the system and user space cpu time
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r-- | source3/include/smbprofile.h | 2 | ||||
-rw-r--r-- | source3/profile/profile.c | 22 | ||||
-rw-r--r-- | source3/wscript | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h index b32d938306..76d9d2b6f6 100644 --- a/source3/include/smbprofile.h +++ b/source3/include/smbprofile.h @@ -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) \ diff --git a/source3/profile/profile.c b/source3/profile/profile.c index 7002537354..67b1fc765b 100644 --- a/source3/profile/profile.c +++ b/source3/profile/profile.c @@ -22,12 +22,17 @@ #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; diff --git a/source3/wscript b/source3/wscript index 63bca9d060..2c03c304db 100644 --- a/source3/wscript +++ b/source3/wscript @@ -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'): |