[PATCH] Some patches around profiling

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Oct 2 09:00:12 MDT 2014


Hi!

Review&push would be appreciated.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 81fed679095496376a9bb4e31ccb178cd30545de Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 2 Oct 2014 12:52:05 +0000
Subject: [PATCH 1/7] profiling: Move some #defines to profile.c

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/smbprofile.h | 4 ----
 source3/profile/profile.c    | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h
index fd17b7a..3040aa0 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -24,10 +24,6 @@
 /* this file defines the profile structure in the profile shared
    memory area */
 
-#define PROF_SHMEM_KEY ((key_t)0x07021999)
-#define PROF_SHM_MAGIC 0x6349985
-#define PROF_SHM_VERSION 13
-
 /* time values in the following structure are in microseconds */
 
 #define __profile_stats_value(which, domain) domain[which]
diff --git a/source3/profile/profile.c b/source3/profile/profile.c
index e0e4684..9ef2c69 100644
--- a/source3/profile/profile.c
+++ b/source3/profile/profile.c
@@ -25,6 +25,10 @@
 #include "messages.h"
 #include "smbprofile.h"
 
+#define PROF_SHMEM_KEY ((key_t)0x07021999)
+#define PROF_SHM_MAGIC 0x6349985
+#define PROF_SHM_VERSION 13
+
 #ifdef WITH_PROFILE
 #define IPC_PERMS ((S_IRUSR | S_IWUSR) | S_IRGRP | S_IROTH)
 #endif /* WITH_PROFILE */
-- 
1.8.1.2


From 55d36f389b512fbb30f9be6823bde2bc3f6b04cc Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 2 Oct 2014 13:05:07 +0000
Subject: [PATCH 2/7] profiling: Fix a typo

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/smbprofile.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h
index 3040aa0..97e7c70 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -880,7 +880,7 @@ extern bool do_profile_times;
 
 /* these are helper macros - do not call them directly in the code
  * use the DO_PROFILE_* START_PROFILE and END_PROFILE ones
- * below which test for the profile flage first
+ * below which test for the profile flags first
  */
 #define INC_PROFILE_COUNT(x) profile_p->x++
 #define DEC_PROFILE_COUNT(x) profile_p->x--
-- 
1.8.1.2


From 9abbd2cb1f6f0c31ee279791e69d083acbeacf23 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 30 Sep 2014 15:08:20 +0000
Subject: [PATCH 3/7] profiling: Only compile utils/status_profile.c if
 profiling is enabled

This conditional compile avoids some #ifdef WITH_PROFILE, which makes the code
more readable

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/status_profile.c       | 21 ---------------------
 source3/utils/status_profile_dummy.c | 33 +++++++++++++++++++++++++++++++++
 source3/wscript_build                | 11 ++++++++---
 3 files changed, 41 insertions(+), 24 deletions(-)
 create mode 100644 source3/utils/status_profile_dummy.c

diff --git a/source3/utils/status_profile.c b/source3/utils/status_profile.c
index 0923bae..153fba6 100644
--- a/source3/utils/status_profile.c
+++ b/source3/utils/status_profile.c
@@ -24,7 +24,6 @@
 bool status_profile_dump(bool be_verbose);
 bool status_profile_rates(bool be_verbose);
 
-#ifdef WITH_PROFILE
 static void profile_separator(const char * title)
 {
     char line[79 + 1];
@@ -39,14 +38,12 @@ static void profile_separator(const char * title)
     line[sizeof(line) - 1] = '\0';
     d_printf("%s\n", line);
 }
-#endif
 
 /*******************************************************************
  dump the elements of the profile structure
   ******************************************************************/
 bool status_profile_dump(bool verbose)
 {
-#ifdef WITH_PROFILE
 	if (!profile_setup(NULL, True)) {
 		fprintf(stderr,"Failed to initialise profile memory\n");
 		return False;
@@ -437,16 +434,9 @@ bool status_profile_dump(bool verbose)
 	d_printf("smb2_break_count:               %u\n", profile_p->smb2_break_count);
 	d_printf("smb2_break_time:                %u\n", profile_p->smb2_break_time);
 
-#else /* WITH_PROFILE */
-
-	fprintf(stderr, "Profile data unavailable\n");
-#endif /* WITH_PROFILE */
-
 	return True;
 }
 
-#ifdef WITH_PROFILE
-
 /* Convert microseconds to milliseconds. */
 #define usec_to_msec(s) ((s) / 1000)
 /* Convert microseconds to seconds. */
@@ -566,14 +556,3 @@ bool status_profile_rates(bool verbose)
 
 	return True;
 }
-
-#else /* WITH_PROFILE */
-
-bool status_profile_rates(bool verbose)
-{
-	fprintf(stderr, "Profile data unavailable\n");
-	return False;
-}
-
-#endif /* WITH_PROFILE */
-
diff --git a/source3/utils/status_profile_dummy.c b/source3/utils/status_profile_dummy.c
new file mode 100644
index 0000000..c58f696
--- /dev/null
+++ b/source3/utils/status_profile_dummy.c
@@ -0,0 +1,33 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba internal messaging functions
+ * Copyright (C) 2013 by Volker Lendecke
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "smbprofile.h"
+
+bool status_profile_dump(bool be_verbose)
+{
+	fprintf(stderr, "Profile data unavailable\n");
+	return true;
+}
+
+bool status_profile_rates(bool be_verbose)
+{
+	fprintf(stderr, "Profile data unavailable\n");
+	return true;
+}
diff --git a/source3/wscript_build b/source3/wscript_build
index 7394a57..d3979e8 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -1164,10 +1164,15 @@ bld.SAMBA3_BINARY('smbta-util',
                  secrets3
                  param''')
 
+smbstatus_source = 'utils/status.c smbd/notify_internal.c'
+
+if bld.CONFIG_GET("WITH_PROFILE"):
+    smbstatus_source += ' utils/status_profile.c'
+else:
+    smbstatus_source += ' utils/status_profile_dummy.c'
+
 bld.SAMBA3_BINARY('smbstatus',
-                 source='''utils/status.c
-                 utils/status_profile.c
-                 smbd/notify_internal.c''',
+                 source=smbstatus_source,
                  deps='''
                  talloc
                  param
-- 
1.8.1.2


From 2f4986fc999d1b2323ea2e46a24904eabe42b7c0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 30 Sep 2014 15:08:20 +0000
Subject: [PATCH 4/7] profiling: Only compile profile/profile.c if profiling is
 enabled

This conditional compile avoids some #ifdef WITH_PROFILE, which makes the code
more readable

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/profile/profile.c       | 17 +----------------
 source3/profile/profile_dummy.c | 31 +++++++++++++++++++++++++++++++
 source3/wscript_build           | 11 ++++++++---
 3 files changed, 40 insertions(+), 19 deletions(-)
 create mode 100644 source3/profile/profile_dummy.c

diff --git a/source3/profile/profile.c b/source3/profile/profile.c
index 9ef2c69..9367ff4 100644
--- a/source3/profile/profile.c
+++ b/source3/profile/profile.c
@@ -29,14 +29,10 @@
 #define PROF_SHM_MAGIC 0x6349985
 #define PROF_SHM_VERSION 13
 
-#ifdef WITH_PROFILE
 #define IPC_PERMS ((S_IRUSR | S_IWUSR) | S_IRGRP | S_IROTH)
-#endif /* WITH_PROFILE */
 
-#ifdef WITH_PROFILE
 static int shm_id;
 static bool read_only;
-#endif
 
 struct profile_header {
 	int prof_shm_magic;
@@ -55,7 +51,6 @@ Set a profiling level.
 ****************************************************************************/
 void set_profile_level(int level, struct server_id src)
 {
-#ifdef WITH_PROFILE
 	switch (level) {
 	case 0:		/* turn off profiling */
 		do_profile_flag = False;
@@ -81,13 +76,8 @@ void set_profile_level(int level, struct server_id src)
 			 (int)procid_to_pid(&src)));
 		break;
 	}
-#else /* WITH_PROFILE */
-	DEBUG(1,("INFO: Profiling support unavailable in this build.\n"));
-#endif /* WITH_PROFILE */
 }
 
-#ifdef WITH_PROFILE
-
 /****************************************************************************
 receive a set profile level message
 ****************************************************************************/
@@ -119,11 +109,8 @@ static void reqprofile_message(struct messaging_context *msg_ctx,
 {
         int level;
 
-#ifdef WITH_PROFILE
 	level = 1 + (do_profile_flag?2:0) + (do_profile_times?4:0);
-#else
-	level = 0;
-#endif
+
 	DEBUG(1,("INFO: Received REQ_PROFILELEVEL message from PID %u\n",
 		 (unsigned int)procid_to_pid(&src)));
 	messaging_send_buf(msg_ctx, src, MSG_PROFILELEVEL,
@@ -413,5 +400,3 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
 	SMB_ASSERT(val < PR_VALUE_MAX);
 	return valnames[val];
 }
-
-#endif /* WITH_PROFILE */
diff --git a/source3/profile/profile_dummy.c b/source3/profile/profile_dummy.c
new file mode 100644
index 0000000..1f820ec
--- /dev/null
+++ b/source3/profile/profile_dummy.c
@@ -0,0 +1,31 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * profile.c implementation if profiles are not enabled
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "smbprofile.h"
+
+bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
+{
+	return true;
+}
+
+void set_profile_level(int level, struct server_id src)
+{
+	DEBUG(1,("INFO: Profiling support unavailable in this build.\n"));
+}
diff --git a/source3/wscript_build b/source3/wscript_build
index d3979e8..54ba3a7 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -638,9 +638,14 @@ bld.SAMBA3_SUBSYSTEM('LOCKING',
                     NDR_OPEN_FILES
                     FNAME_UTIL''')
 
-bld.SAMBA3_SUBSYSTEM('PROFILE',
-                    source='profile/profile.c',
-                    deps='samba-util')
+if bld.CONFIG_GET("WITH_PROFILE"):
+    bld.SAMBA3_SUBSYSTEM('PROFILE',
+                         source='profile/profile.c',
+                         deps='samba-util')
+else:
+    bld.SAMBA3_SUBSYSTEM('PROFILE',
+                         source='profile/profile_dummy.c',
+                         deps='')
 
 bld.SAMBA3_SUBSYSTEM('PRINTBASE',
                     source='''printing/notify.c printing/printing_db.c''',
-- 
1.8.1.2


From 61c04c651427a045f17c7abadef04020488223e6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 2 Oct 2014 13:36:22 +0000
Subject: [PATCH 5/7] profiling: Remove some #ifdefs

The DO_PROFILE_INC thingies already #define to nothing without
WITH_PROFILE, and any sane compiler will just not compile the if-condition
if there is no body to be executed.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/fileio.c | 6 ------
 source3/smbd/server.c | 2 --
 2 files changed, 8 deletions(-)

diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index b0da7a2..91b3102 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -345,12 +345,10 @@ ssize_t write_file(struct smb_request *req,
 
 	mark_file_modified(fsp);
 
-#ifdef WITH_PROFILE
 	DO_PROFILE_INC(writecache_total_writes);
 	if (!fsp->oplock_type) {
 		DO_PROFILE_INC(writecache_non_oplock_writes);
 	}
-#endif
 
 	/*
 	 * If this file is level II oplocked then we need
@@ -826,13 +824,11 @@ n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
 	 */
 
 	if (n) {
-#ifdef WITH_PROFILE
 		if (wcp->data_size) {
 			DO_PROFILE_INC(writecache_abutted_writes);
 		} else {
 			DO_PROFILE_INC(writecache_init_writes);
 		}
-#endif
 
 		if ((wcp->data_size == 0)
 		    && (pos > wcp->file_size)
@@ -997,11 +993,9 @@ ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
 	DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
 		fsp->fh->fd, (double)wcp->offset, (unsigned int)data_size));
 
-#ifdef WITH_PROFILE
 	if(data_size == wcp->alloc_size) {
 		DO_PROFILE_INC(writecache_num_perfect_writes);
 	}
-#endif
 
 	ret = real_write_file(NULL, fsp, wcp->data, wcp->offset, data_size);
 
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 658f268..8b9a1c1 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1304,7 +1304,6 @@ extern void build_options(bool screen);
 
 	init_structs();
 
-#ifdef WITH_PROFILE
 	if (!profile_setup(msg_ctx, False)) {
 		DEBUG(0,("ERROR: failed to setup profiling\n"));
 		return -1;
@@ -1317,7 +1316,6 @@ extern void build_options(bool screen);
 		src.pid = getpid();
 		set_profile_level(pl, src);
 	}
-#endif
 
 	if (!is_daemon && !is_a_socket(0)) {
 		if (!interactive) {
-- 
1.8.1.2


From 00d905fa346d3f99bf4463426670d9cdc77bbea0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 2 Oct 2014 13:40:35 +0000
Subject: [PATCH 6/7] profiling: Remove a big DEBUG statement

I would like to have the freedom to play with the profiling implementation.
This is kindof in the way.

This code is from pre-SVN days:

> commit 7914e9351abb5271ebb4990c3b1fe495d15a4eda
> Author:     Jeremy Allison <jra at samba.org>
> AuthorDate: Thu Oct 5 18:50:18 2000 +0000
> Commit:     Jeremy Allison <jra at samba.org>
> CommitDate: Thu Oct 5 18:50:18 2000 +0000
>
>     Herb's fixes for profiling & compiler warnings.
>     Jeremy.

Herb, please speak up quickly if you still need this :-)

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/fileio.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index 91b3102..37c3f66 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -362,31 +362,6 @@ ssize_t write_file(struct smb_request *req,
 	contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WRITE);
 	contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_WRITE);
 
-#ifdef WITH_PROFILE
-	if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
-		DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
-nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
-			profile_p->writecache_init_writes,
-			profile_p->writecache_abutted_writes,
-			profile_p->writecache_total_writes,
-			profile_p->writecache_non_oplock_writes,
-			profile_p->writecache_allocated_write_caches,
-			profile_p->writecache_num_write_caches,
-			profile_p->writecache_direct_writes,
-			profile_p->writecache_num_perfect_writes,
-			profile_p->writecache_read_hits ));
-
-		DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
-			profile_p->writecache_flushed_writes[SAMBA_SEEK_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_READ_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_WRITE_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_READRAW_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_OPLOCK_RELEASE_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_CLOSE_FLUSH],
-			profile_p->writecache_flushed_writes[SAMBA_SYNC_FLUSH] ));
-	}
-#endif
-
 	if (wcp && req->unread_bytes) {
 		/* If we're using receivefile don't
 		 * deal with a write cache.
-- 
1.8.1.2


From f8eac1819d17fb0ef46e507cfa6014fec8c3f7ea Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 2 Oct 2014 13:45:01 +0000
Subject: [PATCH 7/7] profiling: Make WITH_PROFILE span more in smbprofile.h

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/smbprofile.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h
index 97e7c70..a37ac4f 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -21,6 +21,8 @@
 
 */
 
+#ifdef WITH_PROFILE
+
 /* this file defines the profile structure in the profile shared
    memory area */
 
@@ -876,8 +878,6 @@ extern struct profile_stats *profile_p;
 extern bool do_profile_flag;
 extern bool do_profile_times;
 
-#ifdef WITH_PROFILE
-
 /* these are helper macros - do not call them directly in the code
  * use the DO_PROFILE_* START_PROFILE and END_PROFILE ones
  * below which test for the profile flags first
@@ -964,6 +964,7 @@ static inline uint64_t profile_timestamp(void)
 #define START_PROFILE_BYTES(x,n)
 #define END_PROFILE_STAMP(x, _stamp)
 #define END_PROFILE(x)
+
 #endif /* WITH_PROFILE */
 
 /* The following definitions come from profile/profile.c  */
-- 
1.8.1.2



More information about the samba-technical mailing list