[m-rev.] diff/review: deep profiler enhancements
Zoltan Somogyi
zs at cs.mu.OZ.AU
Fri Jul 13 14:28:26 AEST 2001
On 03-Jul-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> This set of signals is not portable. The only ones mandated by the C
> standard are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, and SIGTERM.
> All the others should be inside #ifdefs, e.g.
>
> #ifdef SIGBUS
> SIGBUS,
> #endif
> #ifdef SIGPIPE
> SIGPIPE,
> #endif
> ...
> By the way, shouldn't all the externally visible C identifiers in the
> deep profiler (e.g. `signal_numbers') have a prefix (e.g. `MDPROF_') on them?
This diff addresses those comments.
Zoltan.
deep_profiler/timeout.m:
Do not assume that signals with specific names exist, except the one we
can't do without.
Use an MP_ (Mercury profiler) prefix on the names of global variables
and of functions.
deep_profiler/server.m:
Add an MP_ prefix.
Index: timeout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/timeout.m,v
retrieving revision 1.3
diff -u -b -r1.3 timeout.m
--- timeout.m 2001/07/08 08:29:57 1.3
+++ timeout.m 2001/07/13 04:25:27
@@ -61,18 +61,16 @@
extern char *MP_timeout_file2;
extern char *MP_timeout_file3;
-#define MDPROF_NUM_SIGNAL_NUMBERS 11
+extern const int MP_signal_numbers[];
-extern const int signal_numbers[MDPROF_NUM_SIGNAL_NUMBERS];
-
-extern void delete_timeout_files(void);
-extern void delete_timeout_files_and_exit_success(void);
-extern void delete_timeout_files_and_exit_failure(void);
+extern void MP_delete_timeout_files(void);
+extern void MP_delete_timeout_files_and_exit_success(void);
+extern void MP_delete_timeout_files_and_exit_failure(void);
").
:- pragma foreign_code("C",
"
-bool process_is_detached_server = FALSE;
+bool MP_process_is_detached_server = FALSE;
char *MP_timeout_file1;
char *MP_timeout_file2;
char *MP_timeout_file3;
@@ -83,33 +81,58 @@
** during development, both intentional ones where the programmer sends the
** signal and those caused by bugs in the server code. We would like to include
** all catchable, fatal signals in this list, but that set is somewhat OS
-** dependent. The set here is the widely portable subset.
+** dependent. The set whose existence we test for here includes all the
+** signals that are at all likely to be sent to server process.
+**
+** We don't test for the existence of SIGALRM, because we want compilation to
+** fail if it does not exist. Without alarm signals, server processes will
+** never be timed out, and thus constitute a resource leak (mostly of virtual
+** memory/swap space).
**
** We could avoid this problem if we had a version of atexit that executed
** its actions even when the program exits after a signal.
*/
-const int signal_numbers[MDPROF_NUM_SIGNAL_NUMBERS] =
+const int MP_signal_numbers[] =
{
SIGALRM,
+#ifdef SIGTERM
SIGTERM,
+#endif
+#ifdef SIGHUP
SIGHUP,
+#endif
+#ifdef SIGINT
SIGINT,
+#endif
+#ifdef SIGQUIT
SIGQUIT,
-
+#endif
+#ifdef SIGILL
SIGILL,
+#endif
+#ifdef SIGABRT
SIGABRT,
+#endif
+#ifdef SIGBUS
SIGBUS,
+#endif
+#ifdef SIGFPE
SIGFPE,
-
+#endif
+#ifdef SIGSEGV
SIGSEGV,
- SIGPIPE
+#endif
+#ifdef SIGPIPE
+ SIGPIPE,
+#endif
+ -1
};
void
-delete_timeout_files(void)
+MP_delete_timeout_files(void)
{
- if (! process_is_detached_server) {
+ if (! MP_process_is_detached_server) {
if (remove(MP_timeout_file1) != 0) {
perror(MP_timeout_file1);
}
@@ -125,16 +148,16 @@
}
void
-delete_timeout_files_and_exit_success(void)
+MP_delete_timeout_files_and_exit_success(void)
{
- delete_timeout_files();
+ MP_delete_timeout_files();
exit(EXIT_SUCCESS);
}
void
-delete_timeout_files_and_exit_failure(void)
+MP_delete_timeout_files_and_exit_failure(void)
{
- delete_timeout_files();
+ MP_delete_timeout_files();
exit(EXIT_FAILURE);
}
").
@@ -150,18 +173,18 @@
MP_timeout_file2 = File2;
MP_timeout_file3 = File3;
- for (i = 0; i < MDPROF_NUM_SIGNAL_NUMBERS; i++) {
- if (signal_numbers[i] == SIGALRM) {
- handler = delete_timeout_files_and_exit_success;
+ for (i = 0; MP_signal_numbers[i] >= 0; i++) {
+ if (MP_signal_numbers[i] == SIGALRM) {
+ handler = MP_delete_timeout_files_and_exit_success;
} else {
- handler = delete_timeout_files_and_exit_failure;
+ handler = MP_delete_timeout_files_and_exit_failure;
}
- MR_setup_signal(signal_numbers[i], handler, FALSE,
+ MR_setup_signal(MP_signal_numbers[i], handler, FALSE,
""Mercury deep profiler: cannot setup signal exit"");
}
- if (atexit(delete_timeout_files) != 0) {
+ if (atexit(MP_delete_timeout_files) != 0) {
MR_fatal_error(""Mercury deep profiler: cannot setup exit"");
}
Index: server.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/server.m,v
retrieving revision 1.4
diff -u -b -r1.4 server.m
--- server.m 2001/07/03 08:16:19 1.4
+++ server.m 2001/07/12 13:55:36
@@ -133,9 +133,9 @@
** now to let the io__call_system in the cgi script succeed.
*/
- extern bool process_is_detached_server;
+ extern bool MP_process_is_detached_server;
- process_is_detached_server = TRUE;
+ MP_process_is_detached_server = TRUE;
exit(0);
}
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list