Merge of Herb's profiling code.
authorJeremy Allison <jra@samba.org>
Sat, 11 Nov 2000 00:33:33 +0000 (00:33 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 11 Nov 2000 00:33:33 +0000 (00:33 +0000)
Jeremy.
(This used to be commit 3be056c71aa8e0a4ba70d397107199004bdb7d3f)

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

index b5e4f625931f6c90faeebd0e94186487ce3c4933..513f7b24a18d5cc65f723cec75bb403a959c7162 100644 (file)
@@ -29,6 +29,8 @@
 #define MSG_PROFILE            4
 #define MSG_REQ_DEBUGLEVEL     5
 #define MSG_DEBUGLEVEL         6
+#define MSG_REQ_PROFILELEVEL   7
+#define MSG_PROFILELEVEL       8
 
 /* nmbd messages */
 #define MSG_FORCE_ELECTION 1001
index 1cc6700ea9b265de70f57cbae2508c968dacb0b4..126ca768b7b7f8cdb154b59c082e2dd3cf3f79e0 100644 (file)
@@ -334,6 +334,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
 
        memcpy(&crec, dbuf.dptr, sizeof(crec));
 
+       if (crec.cnum == -1) return 0;
        message_send_pid(crec.pid, msg_all.msg_type, msg_all.buf, msg_all.len);
        return 0;
 }
index f1d2310ce18a09f547d5fd8abecc33ba868c61a1..80584adfa2a9818d109e638ed4731eaed8e09afc 100644 (file)
@@ -73,6 +73,22 @@ void profile_message(int msg_type, pid_t src, void *buf, size_t len)
        }
 }
 
+/****************************************************************************
+receive a request profile level message
+****************************************************************************/
+void reqprofile_message(int msg_type, pid_t src, void *buf, size_t len)
+{
+        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 %d\n",src));
+       message_send_pid(src, MSG_PROFILELEVEL, &level, sizeof(int));
+}
+
 /*******************************************************************
   open the profiling shared memory area
   ******************************************************************/
@@ -140,6 +156,7 @@ BOOL profile_setup(BOOL rdonly)
 
        profile_p = &profile_h->stats;
        message_register(MSG_PROFILE, profile_message);
+       message_register(MSG_REQ_PROFILELEVEL, reqprofile_message);
        return True;
 }
 
index c059ccb6ec84d41d90b0942b58f3c791d7edafd0..a273f82151c7715ee8a5c9a4f6cbd6e5efe02364 100644 (file)
@@ -29,6 +29,7 @@ static struct {
        {"force-election", MSG_FORCE_ELECTION},
        {"ping", MSG_PING},
        {"profile", MSG_PROFILE},
+       {"profilelevel", MSG_REQ_PROFILELEVEL},
        {"debuglevel", MSG_REQ_DEBUGLEVEL},
        {"printer-notify", MSG_PRINTER_NOTIFY},
        {NULL, -1}
@@ -59,6 +60,7 @@ static int pong_count;
 static BOOL got_level;
 static BOOL pong_registered = False;
 static BOOL debuglevel_registered = False;
+static BOOL profilelevel_registered = False;
 
 
 /****************************************************************************
@@ -82,6 +84,34 @@ void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len)
        got_level = True;
 }
 
+/****************************************************************************
+Prints out the current Profile level returned by MSG_PROFILELEVEL
+****************************************************************************/
+void profilelevel_function(int msg_type, pid_t src, void *buf, size_t len)
+{
+        int level;
+       char *s;
+        memcpy(&level, buf, sizeof(int));
+
+       if (level) {
+           switch (level) {
+           case 1:
+               s = "off";
+               break;
+           case 3:
+               s = "count only";
+               break;
+           case 7:
+               s = "count and time";
+               break;
+           }
+           printf("Profiling %s on PID %d\n",s,src);
+       } else {
+           printf("Profiling not available on PID %d\n",src);
+       }
+       got_level = True;
+}
+
 /****************************************************************************
 send a message to a named destination
 ****************************************************************************/
@@ -176,6 +206,25 @@ static BOOL do_command(char *dest, char *msg_name, char *params)
                send_message(dest, MSG_FORCE_ELECTION, NULL, 0);
                break;
 
+       case MSG_REQ_PROFILELEVEL:
+               if (!profilelevel_registered) {
+                   message_register(MSG_PROFILELEVEL, profilelevel_function);
+                   profilelevel_registered = True;
+               }
+               got_level = False;
+               retval = send_message(dest, MSG_REQ_PROFILELEVEL, NULL, 0);
+               if (retval) {
+                       timeout_start = time(NULL);
+                       while (!got_level) {
+                               message_dispatch();
+                               if ((time(NULL) - timeout_start) > MAX_WAIT) {
+                                       fprintf(stderr,"profilelevel timeout\n");
+                                       break;
+                               }
+                       }
+               }
+               break;
+
        case MSG_REQ_DEBUGLEVEL:
                if (!debuglevel_registered) {
                    message_register(MSG_DEBUGLEVEL, debuglevel_function);