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
}
#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); \
}
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
******************************************************************/
DEBUG(3,("Initialised profile area\n"));
}
- do_profile_flag = True; /* temp for now */
+ message_register(MSG_PROFILE, profile_message);
return True;
}
{"debug", MSG_DEBUG},
{"force-election", MSG_FORCE_ELECTION},
{"ping", MSG_PING},
+ {"profile", MSG_PROFILE},
+ {"debuglevel", MSG_REQ_DEBUGLEVEL},
{NULL, -1}
};
}
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
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;
}
/****************************************************************************
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");
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);
}