summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/messages.h9
-rw-r--r--source3/include/profile.h9
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/profile/profile.c28
-rw-r--r--source3/utils/smbcontrol.c61
5 files changed, 99 insertions, 9 deletions
diff --git a/source3/include/messages.h b/source3/include/messages.h
index 4ddb82ee30..b5e4f62593 100644
--- a/source3/include/messages.h
+++ b/source3/include/messages.h
@@ -23,9 +23,12 @@
#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
diff --git a/source3/include/profile.h b/source3/include/profile.h
index d18f598021..c196a63c62 100644
--- a/source3/include/profile.h
+++ b/source3/include/profile.h
@@ -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); \
}
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 6c87c429c0..b29e3aa788 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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 */
diff --git a/source3/profile/profile.c b/source3/profile/profile.c
index 5b8b280c29..87f5e2c9b2 100644
--- a/source3/profile/profile.c
+++ b/source3/profile/profile.c
@@ -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;
}
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index cedb13620d..306f7ee269 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -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);
}