Added Herb's fixes to HEAD.
authorJeremy Allison <jra@samba.org>
Fri, 6 Oct 2000 23:01:47 +0000 (23:01 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 6 Oct 2000 23:01:47 +0000 (23:01 +0000)
Jeremy.
(This used to be commit 4862d2ab1163310d844b929fb17239b4f4cb1a99)

source3/include/messages.h
source3/include/profile.h
source3/include/proto.h
source3/profile/profile.c
source3/utils/smbcontrol.c

index 4ddb82ee305275aa5cac723748e3e07441d4ef3f..b5e4f625931f6c90faeebd0e94186487ce3c4933 100644 (file)
 #define _MESSAGES_H_
 
 /* general messages */
-#define MSG_DEBUG 1
-#define MSG_PING  2
-#define MSG_PONG  3
+#define MSG_DEBUG              1
+#define MSG_PING               2
+#define MSG_PONG               3
+#define MSG_PROFILE            4
+#define MSG_REQ_DEBUGLEVEL     5
+#define MSG_DEBUGLEVEL         6
 
 /* nmbd messages */
 #define MSG_FORCE_ELECTION 1001
index d18f598021e2f81f0e8dbac708163dd284fb80c9..c196a63c62febfb33b7b342cb2c547b21896ac6a 100644 (file)
@@ -319,6 +319,7 @@ extern struct profile_struct *profile_p;
 extern struct timeval profile_starttime;
 extern struct timeval profile_endtime;
 extern BOOL do_profile_flag;
+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
@@ -349,17 +350,19 @@ extern BOOL do_profile_flag;
        }
 #define START_PROFILE(x) \
        if (do_profile_flag) { \
-               GetTimeOfDay(&profile_starttime); \
+               if (do_profile_times) \
+                       GetTimeOfDay(&profile_starttime); \
                INC_PROFILE_COUNT(x##_count); \
        }
 #define START_PROFILE_BYTES(x,n) \
        if (do_profile_flag) { \
-               GetTimeOfDay(&profile_starttime); \
+               if (do_profile_times) \
+                       GetTimeOfDay(&profile_starttime); \
                INC_PROFILE_COUNT(x##_count); \
                ADD_PROFILE_COUNT(x##_bytes,n); \
        }
 #define END_PROFILE(x) \
-       if (do_profile_flag) { \
+       if (do_profile_times) { \
                GetTimeOfDay(&profile_endtime); \
                ADD_PROFILE_COUNT(x##_time,PROFILE_TIME); \
        }
index 6c87c429c024cbc5b6081801ea435c07bf31b0e3..b29e3aa788b0e65642cba6c502dd9869de8dc641 100644 (file)
@@ -1784,6 +1784,7 @@ BOOL print_queue_purge(struct current_user *user, int snum, int *errcode);
 
 /*The following definitions come from  profile/profile.c  */
 
+void profile_message(int msg_type, pid_t src, void *buf, size_t len);
 BOOL profile_setup(BOOL rdonly);
 
 /*The following definitions come from  rpc_client/cli_connect.c  */
index 5b8b280c293e6a7fc33cf0d5572eefd0245c2d25..87f5e2c9b22e2b824c7852fca0e74c4c31ec8ec5 100644 (file)
@@ -34,10 +34,36 @@ static BOOL read_only;
 struct profile_struct *profile_p;
 
 BOOL do_profile_flag = False;
+BOOL do_profile_times = False;
 
 struct timeval profile_starttime;
 struct timeval profile_endtime;
 
+/****************************************************************************
+receive a set profile level message
+****************************************************************************/
+void profile_message(int msg_type, pid_t src, void *buf, size_t len)
+{
+        int level;
+
+       memcpy(&level, buf, sizeof(int));
+       switch (level) {
+       case 0:
+               do_profile_flag = False;
+               do_profile_times = False;
+               break;
+       case 1:
+               do_profile_flag = True;
+               do_profile_times = False;
+               break;
+       case 2:
+               do_profile_flag = True;
+               do_profile_times = True;
+               break;
+       }
+       DEBUG(1,("Profile level set to %d from pid %d\n", level, (int)src));
+}
+
 /*******************************************************************
   open the profiling shared memory area
   ******************************************************************/
@@ -103,7 +129,7 @@ BOOL profile_setup(BOOL rdonly)
                DEBUG(3,("Initialised profile area\n"));
        }
 
-       do_profile_flag = True;         /* temp for now */
+       message_register(MSG_PROFILE, profile_message);
        return True;
 }
 
index cedb13620d5c5052d2516afc275a2b74d1ffd72d..306f7ee269c85183ab27762aa5ac657003c13aaf 100644 (file)
@@ -30,6 +30,8 @@ static struct {
        {"debug", MSG_DEBUG},
        {"force-election", MSG_FORCE_ELECTION},
        {"ping", MSG_PING},
+       {"profile", MSG_PROFILE},
+       {"debuglevel", MSG_REQ_DEBUGLEVEL},
        {NULL, -1}
 };
 
@@ -44,12 +46,17 @@ static void usage(BOOL doexit)
        }
        printf("\t<destination> is one of \"nmbd\", \"smbd\" or a process ID\n");
        printf("\t<message-type> is one of: ");
-       for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name);
+       for (i=0; msg_types[i].name; i++) 
+           printf("%s%s", i?", ":"",msg_types[i].name);
        printf("\n");
        if (doexit) exit(1);
 }
 
 static int pong_count;
+static BOOL got_level;
+static BOOL pong_registered = False;
+static BOOL debuglevel_registered = False;
+
 
 /****************************************************************************
 a useful function for testing the message system
@@ -57,6 +64,19 @@ a useful function for testing the message system
 void pong_function(int msg_type, pid_t src, void *buf, size_t len)
 {
        pong_count++;
+       printf("PONG\n");
+}
+
+/****************************************************************************
+Prints out the current Debug level returned by MSG_DEBUGLEVEL
+****************************************************************************/
+void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len)
+{
+        int level;
+        memcpy(&level, buf, sizeof(int));
+
+       printf("Current debug level is %d\n",level);
+       got_level = True;
 }
 
 /****************************************************************************
@@ -123,6 +143,25 @@ static BOOL do_command(char *dest, char *msg_name, char *params)
                send_message(dest, MSG_DEBUG, &v, sizeof(int));
                break;
 
+       case MSG_PROFILE:
+               if (!params) {
+                       fprintf(stderr,"MSG_PROFILE needs a parameter\n");
+                       return(False);
+               }
+               if (strequal(params, "on")) {
+                       v = 2;
+               } else if (strequal(params, "off")) {
+                       v = 0;
+               } else if (strequal(params, "count")) {
+                       v = 1;
+               } else {
+                   fprintf(stderr,
+                       "MSG_PROFILE parameter must be on, off, or count\n");
+                   return(False);
+               }
+               send_message(dest, MSG_PROFILE, &v, sizeof(int));
+               break;
+
        case MSG_FORCE_ELECTION:
                if (!strequal(dest, "nmbd")) {
                        fprintf(stderr,"force-election can only be sent to nmbd\n");
@@ -131,13 +170,31 @@ static BOOL do_command(char *dest, char *msg_name, char *params)
                send_message(dest, MSG_FORCE_ELECTION, NULL, 0);
                break;
 
+       case MSG_REQ_DEBUGLEVEL:
+               if (!debuglevel_registered) {
+                   message_register(MSG_DEBUGLEVEL, debuglevel_function);
+                   debuglevel_registered = True;
+               }
+               if (strequal(dest, "nmbd") || strequal(dest, "smbd")) {
+                   fprintf(stderr,"debuglevel can only be sent to a PID\n");
+                   return(False);
+               }
+               got_level = False;
+               send_message(dest, MSG_REQ_DEBUGLEVEL, NULL, 0);
+               while (!got_level) message_dispatch();
+               break;
+
        case MSG_PING:
-               message_register(MSG_PONG, pong_function);
+               if (!pong_registered) {
+                   message_register(MSG_PONG, pong_function);
+                   pong_registered = True;
+               }
                if (!params) {
                        fprintf(stderr,"MSG_PING needs a parameter\n");
                        return(False);
                }
                n = atoi(params);
+               pong_count = 0;
                for (i=0;i<n;i++) {
                        send_message(dest, MSG_PING, NULL, 0);
                }