Add two more memory-debug smbcontrol messages: these ones should
authorMartin Pool <mbp@samba.org>
Wed, 9 Jan 2002 08:27:15 +0000 (08:27 +0000)
committerMartin Pool <mbp@samba.org>
Wed, 9 Jan 2002 08:27:15 +0000 (08:27 +0000)
prompt dmalloc to log information about what happening, so you can see
in flight why smbd is getting bloated.
(This used to be commit bcb443c5c4bf97fe6b5b0993e42496c2e64f0124)

source3/Makefile.in
source3/include/messages.h
source3/lib/dmallocmsg.c [new file with mode: 0644]
source3/smbd/server.c
source3/utils/smbcontrol.c

index ed1f4687112604308e1e96fcd9a5f2d899e3be22..8920cea648afb8a6cf476234ed374f95a190add8 100644 (file)
@@ -121,7 +121,7 @@ LIB_OBJ = lib/charcnv.o lib/debug.o lib/fault.o \
          lib/util.o lib/util_sock.o lib/util_sec.o smbd/ssl.o \
          lib/talloc.o lib/hash.o lib/substitute.o lib/fsusage.o \
          lib/ms_fnmatch.o lib/select.o lib/error.o lib/messages.o \
-         lib/tallocmsg.o \
+         lib/tallocmsg.o lib/dmallocmsg.o \
          lib/md5.o lib/hmacmd5.o lib/iconv.o lib/smbpasswd.o \
          nsswitch/wb_client.o nsswitch/wb_common.o \
          intl/lang_tdb.o lib/account_pol.o $(TDB_OBJ) 
index f1cfb508369296392c6d5f7b897d120a1e8f8f8c..2b0c1ad1af1893d007eeb986b0803407606ea0ee 100644 (file)
@@ -3,6 +3,7 @@
    Version 3.0
    messages.c header
    Copyright (C) Andrew Tridgell 2000
+   Copyright (C) 2001, 2002 by Martin Pool
    
    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
 #define MSG_REQ_POOL_USAGE     9
 #define MSG_POOL_USAGE         10
 
+/* If dmalloc is included, set a steady-state mark */
+#define MSG_REQ_DMALLOC_MARK   11
+
+/* If dmalloc is included, dump to the dmalloc log a description of
+ * what has changed since the last MARK */
+#define MSG_REQ_DMALLOC_LOG_CHANGED    12
+
 /* nmbd messages */
 #define MSG_FORCE_ELECTION 1001
 
diff --git a/source3/lib/dmallocmsg.c b/source3/lib/dmallocmsg.c
new file mode 100644 (file)
index 0000000..9d6ac87
--- /dev/null
@@ -0,0 +1,70 @@
+/* 
+   samba -- Unix SMB/Netbios implementation.
+   Copyright (C) 2002 by Martin Pool
+   
+   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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+/**
+ * @file dmallocmsg.c
+ *
+ * Glue code to cause dmalloc info to come out when we receive a prod
+ * over samba messaging.
+ **/
+
+static unsigned long our_dm_mark = 0;
+
+
+/**
+ * Respond to a POOL_USAGE message by sending back string form of memory
+ * usage stats.
+ **/
+static void msg_req_dmalloc_mark(int UNUSED(msg_type), pid_t UNUSED(src_pid),
+                         void *UNUSED(buf), size_t UNUSED(len))
+{
+#ifdef ENABLE_DMALLOC
+       our_dm_mark = dmalloc_mark();
+       DEBUG(2,("Got MSG_REQ_DMALLOC_MARK: mark set\n"));
+#else
+       DEBUG(2,("Got MSG_REQ_DMALLOC_MARK but dmalloc not in this process\n"));
+#endif
+}
+
+
+
+static void msg_req_dmalloc_log_changed(int UNUSED(msg_type),
+                                       pid_t UNUSED(src_pid),
+                                       void *UNUSED(buf), size_t UNUSED(len))
+{
+#ifdef ENABLE_DMALLOC
+       dmalloc_log_changed(our_dm_mark, True, True, True);
+       DEBUG(2,("Got MSG_REQ_DMALLOC_LOG_CHANGED: done\n"));
+#else
+       DEBUG(2,("Got MSG_REQ_DMALLOC_LOG_CHANGED but dmalloc not in this process\n"));
+#endif
+}
+
+
+/**
+ * Register handler for MSG_REQ_POOL_USAGE
+ **/
+void register_dmalloc_msgs(void)
+{
+       message_register(MSG_REQ_DMALLOC_MARK, msg_req_dmalloc_mark);
+       message_register(MSG_REQ_DMALLOC_LOG_CHANGED, msg_req_dmalloc_log_changed);
+       DEBUG(2, ("Registered MSG_REQ_DMALLOC_MARK and LOG_CHANGED\n"));
+}      
index b523659dbf5ec56160b2540d282810e5646ab589..2f831cdd97a8e856b71097b91b6fa43b8a9e92be 100644 (file)
@@ -809,6 +809,7 @@ static void usage(char *pname)
                exit(1);
        }
        register_msg_pool_usage();
+       register_dmalloc_msgs();
 
        /* Setup the main smbd so that we can get messages. */
        claim_connection(NULL,"",MAXSTATUS,True);
index f03387c6e0dd02df746cece5618b263b16cd9b7f..318e1657cc1e8367b26792bbf2913caa088f6fda 100644 (file)
@@ -3,7 +3,7 @@
    Version 3.0
    program to send control messages to Samba processes
    Copyright (C) Andrew Tridgell 1994-1998
-   Copyright (C) 2001 by Martin Pool
+   Copyright (C) 2001, 2002 by Martin Pool
    
    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
@@ -39,6 +39,8 @@ static struct {
         {"samsync", MSG_SMB_SAM_SYNC},
         {"samrepl", MSG_SMB_SAM_REPL},
        {"pool-usage", MSG_REQ_POOL_USAGE },
+       {"dmalloc-mark", MSG_REQ_DMALLOC_MARK },
+       {"dmalloc-log-changed", MSG_REQ_DMALLOC_LOG_CHANGED },
        {NULL, -1}
 };
 
@@ -68,7 +70,6 @@ static BOOL got_level;
 static BOOL pong_registered = False;
 static BOOL debuglevel_registered = False;
 static BOOL profilelevel_registered = False;
-static BOOL pool_usage_registered = False;
 
 
 /**
@@ -216,6 +217,12 @@ static int parse_type(char *mtype)
 }
 
 
+static void register_all(void)
+{
+       message_register(MSG_POOL_USAGE, pool_usage_cb);
+}
+
+
 /****************************************************************************
 do command
 ****************************************************************************/
@@ -404,15 +411,17 @@ static BOOL do_command(char *dest, char *msg_name, int iparams, char **params)
                break;
 
        case MSG_REQ_POOL_USAGE:
-               if (!pool_usage_registered) {
-                       message_register(MSG_POOL_USAGE, pool_usage_cb);
-                       pool_usage_registered = True;
-               }
                if (!send_message(dest, MSG_REQ_POOL_USAGE, NULL, 0, True))
                        return False;
                wait_for_replies(MAX_WAIT, NULL);
                
                break;
+
+       case MSG_REQ_DMALLOC_LOG_CHANGED:
+       case MSG_REQ_DMALLOC_MARK:
+               if (!send_message(dest, mtype, NULL, 0, False))
+                       return False;
+               break;
        }
 
        return (True);
@@ -453,6 +462,8 @@ static BOOL do_command(char *dest, char *msg_name, int iparams, char **params)
        argc -= optind;
        argv = &argv[optind];
 
+       register_all();
+
        if (!interactive) {
                if (argc < 2) usage(True);
                /* Need to invert sense of return code -- samba