[PATCH] Some patches around profiling
Volker Lendecke
Volker.Lendecke at SerNet.DE
Thu Oct 2 13:38:37 MDT 2014
On Thu, Oct 02, 2014 at 08:31:27AM -0700, Richard Sharpe wrote:
> While I don't have strong feelings about this, it does seem that it
> complicates the lives of people who are learning their way around the
> code. This means they need to read the wscript to understand what is
> going on.
Maybe we should better comment it? Or maybe develop naming
conventions for the file names? I've started this quite a
while ago with source3/lib/pthreadpool/. There we have a
sync dummy implementation for systems where pthreads should
not be used.
Nevertheless, attached find a corrected patchset. I started
the git format-patch at the wrong hash and thus missed two
patches.
Sorry for that,
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 af14f9db573d48c86e7fe84cd3e983d77fcb0522 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 29 Sep 2014 15:06:37 +0000
Subject: [PATCH 1/9] profiling: Make "struct profile_header" static
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbprofile.h | 7 -------
source3/profile/profile.c | 8 +++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h
index 8ecbc30..9ffcfc4 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -876,13 +876,6 @@ struct profile_stats {
unsigned writecache_allocated_write_caches;
};
-struct profile_header {
- int prof_shm_magic;
- int prof_shm_version;
- struct profile_stats stats;
-};
-
-extern struct profile_header *profile_h;
extern struct profile_stats *profile_p;
extern bool do_profile_flag;
extern bool do_profile_times;
diff --git a/source3/profile/profile.c b/source3/profile/profile.c
index 5f9433f..e0e4684 100644
--- a/source3/profile/profile.c
+++ b/source3/profile/profile.c
@@ -34,7 +34,13 @@ static int shm_id;
static bool read_only;
#endif
-struct profile_header *profile_h;
+struct profile_header {
+ int prof_shm_magic;
+ int prof_shm_version;
+ struct profile_stats stats;
+};
+
+static struct profile_header *profile_h;
struct profile_stats *profile_p;
bool do_profile_flag = False;
--
1.8.1.2
From 0520aca27716b88aac3c3cfe224115c5fbf2b4cb Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 30 Sep 2014 13:06:02 +0000
Subject: [PATCH 2/9] profiling: Fix a typo
---
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 9ffcfc4..fd17b7a 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -835,7 +835,7 @@ enum profile_stats_values
#define smb2_break_count __profile_stats_value(PR_VALUE_SMB2_BREAK, count)
#define smb2_break_time __profile_stats_value(PR_VALUE_SMB2_BREAK, time)
- /* This mist remain the last value. */
+ /* This must remain the last value. */
PR_VALUE_MAX
}; /* enum profile_stats_values */
--
1.8.1.2
From 40de1f7008bcec2e16ae02c8ec9f7c614e213f75 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 3/9] 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 0940bd4095f63be032cff949f7f24fc01afb1844 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 4/9] 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 e7a145c08312716b58d70adab9f71e2a33ec7ac7 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 5/9] 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 0d1e6671d598ef9ae0d3408987b9fb1a8e1c40d4 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 6/9] 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 e20649d02bd6c0d80b3d3b6332b055c357891796 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 7/9] 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 be5c3ca9107a181dd03366c9b91b95c1eda250ef 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 8/9] 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 13566d4b0c5adc5f2c0aa0d26a94a34a6db3981f 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 9/9] 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