1
1

Add a suffix to the opal_output stream descriptor object - we can now output both a prefix and a suffix for a given stream. Default the suffix to NULL.

Remove lingering references to a filtering system as this will no longer be implemented.

This commit was SVN r18586.
Этот коммит содержится в:
Ralph Castain 2008-06-04 20:52:20 +00:00
родитель 91a281080a
Коммит ca91ec525b
3 изменённых файлов: 128 добавлений и 108 удалений

Просмотреть файл

@ -68,6 +68,9 @@ typedef struct {
char *ldi_prefix;
int ldi_prefix_len;
char *ldi_suffix;
int ldi_suffix_len;
bool ldi_stdout;
bool ldi_stderr;
@ -76,8 +79,6 @@ typedef struct {
char *ldi_file_suffix;
int ldi_fd;
int ldi_file_num_lines_lost;
int ldi_filter_flags;
} output_desc_t;
/*
@ -92,7 +93,7 @@ static int make_string(char **no_newline_string, output_desc_t *ldi,
static int output(int output_id, const char *format, va_list arglist);
#define OPAL_OUTPUT_MAX_STREAMS 32
#define OPAL_OUTPUT_MAX_STREAMS 64
#if defined(__WINDOWS__) || defined(HAVE_SYSLOG)
#define USE_SYSLOG 1
#else
@ -145,8 +146,6 @@ bool opal_output_init(void)
info[i].ldi_file_want_append = false;
info[i].ldi_fd = -1;
info[i].ldi_file_num_lines_lost = 0;
info[i].ldi_filter_flags =
OPAL_OUTPUT_FILTER_STDOUT | OPAL_OUTPUT_FILTER_STDERR;
}
/* Initialize the mutex that protects the output */
@ -235,13 +234,13 @@ void opal_output_reopen_all(void)
lds.lds_want_syslog = false;
#endif
lds.lds_prefix = info[i].ldi_prefix;
lds.lds_suffix = info[i].ldi_suffix;
lds.lds_want_stdout = info[i].ldi_stdout;
lds.lds_want_stderr = info[i].ldi_stderr;
lds.lds_want_file = (-1 == info[i].ldi_fd) ? false : true;
/* open all streams in append mode */
lds.lds_want_file_append = true;
lds.lds_file_suffix = info[i].ldi_file_suffix;
lds.lds_filter_flags = info[i].ldi_filter_flags;
/*
* call opal_output_open to open the stream. The return value
@ -460,6 +459,7 @@ static void construct(opal_object_t *obj)
stream->lds_syslog_priority = 0;
stream->lds_syslog_ident = NULL;
stream->lds_prefix = NULL;
stream->lds_suffix = NULL;
stream->lds_is_debugging = false;
stream->lds_want_syslog = false;
stream->lds_want_stdout = false;
@ -467,8 +467,6 @@ static void construct(opal_object_t *obj)
stream->lds_want_file = false;
stream->lds_want_file_append = false;
stream->lds_file_suffix = NULL;
stream->lds_filter_flags =
OPAL_OUTPUT_FILTER_STDOUT | OPAL_OUTPUT_FILTER_STDERR;
}
/*
@ -562,6 +560,14 @@ static int do_open(int output_id, opal_output_stream_t * lds)
info[i].ldi_prefix_len = 0;
}
if (NULL != lds->lds_suffix) {
info[i].ldi_suffix = strdup(lds->lds_suffix);
info[i].ldi_suffix_len = (int)strlen(lds->lds_suffix);
} else {
info[i].ldi_suffix = NULL;
info[i].ldi_suffix_len = 0;
}
info[i].ldi_stdout = lds->lds_want_stdout;
info[i].ldi_stderr = lds->lds_want_stderr;
@ -572,8 +578,6 @@ static int do_open(int output_id, opal_output_stream_t * lds)
info[i].ldi_file_want_append = lds->lds_want_file_append;
info[i].ldi_file_num_lines_lost = 0;
info[i].ldi_filter_flags = lds->lds_filter_flags;
/* Don't open a file in the session directory now -- do that lazily
* so that if there's no output, we don't have an empty file */
@ -658,7 +662,12 @@ static void free_descriptor(int output_id)
}
ldi->ldi_prefix = NULL;
if (NULL != ldi->ldi_file_suffix) {
if (NULL != ldi->ldi_suffix) {
free(ldi->ldi_suffix);
}
ldi->ldi_suffix = NULL;
if (NULL != ldi->ldi_file_suffix) {
free(ldi->ldi_file_suffix);
}
ldi->ldi_file_suffix = NULL;
@ -686,10 +695,22 @@ static int make_string(char **no_newline_string, output_desc_t *ldi,
if ('\n' != (*no_newline_string)[len - 1]) {
want_newline = true;
++total_len;
} else if (NULL != ldi->ldi_suffix) {
/* if we have a suffix, then we don't want a
* newline to appear before it
*/
(*no_newline_string)[len - 1] = '\0';
want_newline = true; /* add newline to end after suffix */
/* total_len won't change since we just moved the newline
* to appear after the suffix
*/
}
if (NULL != ldi->ldi_prefix) {
total_len += strlen(ldi->ldi_prefix);
}
if (NULL != ldi->ldi_suffix) {
total_len += strlen(ldi->ldi_suffix);
}
if (temp_str_len < total_len + want_newline) {
if (NULL != temp_str) {
free(temp_str);
@ -700,14 +721,30 @@ static int make_string(char **no_newline_string, output_desc_t *ldi,
}
temp_str_len = total_len * 2;
}
if (NULL != ldi->ldi_prefix) {
if (NULL != ldi->ldi_prefix && NULL != ldi->ldi_suffix) {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s%s\n", ldi->ldi_prefix,
*no_newline_string);
snprintf(temp_str, temp_str_len, "%s%s%s\n",
ldi->ldi_prefix, *no_newline_string, ldi->ldi_suffix);
} else {
snprintf(temp_str, temp_str_len, "%s%s%s", ldi->ldi_prefix,
*no_newline_string, ldi->ldi_suffix);
}
} else if (NULL != ldi->ldi_prefix) {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s%s\n",
ldi->ldi_prefix, *no_newline_string);
} else {
snprintf(temp_str, temp_str_len, "%s%s", ldi->ldi_prefix,
*no_newline_string);
}
} else if (NULL != ldi->ldi_suffix) {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s%s\n",
*no_newline_string, ldi->ldi_suffix);
} else {
snprintf(temp_str, temp_str_len, "%s%s",
*no_newline_string, ldi->ldi_suffix);
}
} else {
if (want_newline) {
snprintf(temp_str, temp_str_len, "%s\n", *no_newline_string);
@ -752,20 +789,7 @@ static int output(int output_id, const char *format, va_list arglist)
/* Syslog output -- does not use the newline-appended string */
#if defined(HAVE_SYSLOG)
if (ldi->ldi_syslog) {
char *out = str;
if (ldi->ldi_filter_flags & OPAL_OUTPUT_FILTER_SYSLOG) {
#if 0
/* JMS call the filter, perhaps like this */
out = filter(str);
if (NULL == out) {
out = str;
}
#endif
}
syslog(ldi->ldi_syslog_priority, "%s", str);
if (out != str) {
free(out);
}
}
#endif
@ -773,20 +797,6 @@ static int output(int output_id, const char *format, va_list arglist)
with a newline appended */
out = temp_str;
if ((ldi->ldi_stdout &&
ldi->ldi_filter_flags & OPAL_OUTPUT_FILTER_STDOUT) ||
(ldi->ldi_stderr &&
ldi->ldi_filter_flags & OPAL_OUTPUT_FILTER_STDERR) ||
(ldi->ldi_file &&
ldi->ldi_filter_flags & OPAL_OUTPUT_FILTER_FILE)) {
#if 0
/* JMS call the filter, perhaps like this */
out = filter(temp_str);
if (NULL == out) {
out = temp_str;
}
#endif
}
/* stdout output */
if (ldi->ldi_stdout) {
@ -816,16 +826,7 @@ static int output(int output_id, const char *format, va_list arglist)
snprintf(buffer, BUFSIZ - 1,
"[WARNING: %d lines lost because the Open MPI process session directory did\n not exist when opal_output() was invoked]\n",
ldi->ldi_file_num_lines_lost);
if (ldi->ldi_filter_flags & OPAL_OUTPUT_FILTER_FILE) {
#if 0
/* JMS call the filter */
out = filter(buffer);
if (NULL == out) {
out = buffer;
}
#endif
}
write(ldi->ldi_fd, buffer, (int)strlen(buffer));
write(ldi->ldi_fd, buffer, (int)strlen(buffer));
ldi->ldi_file_num_lines_lost = 0;
if (out != buffer) {
free(out);

Просмотреть файл

@ -80,15 +80,6 @@
BEGIN_C_DECLS
/** Flag to filter syslog output */
#define OPAL_OUTPUT_FILTER_SYSLOG 0x01
/** Flag to filter stdout output */
#define OPAL_OUTPUT_FILTER_STDOUT 0x02
/** Flag to filter stderr output */
#define OPAL_OUTPUT_FILTER_STDERR 0x04
/** Flag to filter file output */
#define OPAL_OUTPUT_FILTER_FILE 0x08
/**
* \class opal_output_stream_t
*
@ -153,6 +144,16 @@ struct opal_output_stream_t {
*/
char *lds_prefix;
/**
* String suffix added to all output on the stream.
*
* When this field is non-NULL, it is appended to all lines of
* output on the stream. When this field is NULL, no suffix is
* added to each line of output in the stream. The suffix is copied
* to an internal structure in the call to opal_output_open()!
*/
char *lds_suffix;
/**
* Indicates whether the output of the stream is
* debugging/developer-only output or not.
@ -224,15 +225,6 @@ struct opal_output_stream_t {
*/
char *lds_file_suffix;
/**
* What outputs do we want passed through the filter first?
*
* Bit field indicating which of syslog, stdout, stderr, and file
* you want passed through the filter before sending to the
* output. Default is stdout, stderr filtered; syslog and file
* are not filtered.
*/
int lds_filter_flags;
};
/**

Просмотреть файл

@ -111,10 +111,12 @@ int orte_output_open(opal_output_stream_t *lds)
void orte_output(int output_id, const char *format, ...)
{
/* just call opal_output_vverbose with a verbosity of 0 */
/* just call opal_output_vverbose with a negative verbosity to
* ensure the message gets out
*/
va_list arglist;
va_start(arglist, format);
opal_output_vverbose(0, output_id, format, arglist);
opal_output_vverbose(-1, output_id, format, arglist);
va_end(arglist);
}
@ -166,8 +168,6 @@ int orte_show_help(const char *filename, const char *topic,
#define ORTE_OUTPUT_STDERR 0x02
#define ORTE_OUTPUT_SHOW_HELP 0x04
#define ORTE_OUTPUT_MAX_TAGS 10
/* List items for holding process names */
typedef struct {
opal_list_item_t super;
@ -297,7 +297,6 @@ static int get_tli(const char *filename, const char *topic,
static void output_vverbose(int verbose_level, int output_id,
int major_id, int minor_id,
const char *format, va_list arglist)
{
char *output = NULL;
@ -325,7 +324,32 @@ static void output_vverbose(int verbose_level, int output_id,
return;
}
/* Per a soon-to-be-filed trac ticket: because this function calls
/* lookup the flags for this stream */
flags = OPAL_VALUE_ARRAY_GET_ITEM(&orte_output_streams, uint8_t, output_id);
/* if I am the HNP, then I need to output this via
* the appropriate channel
*/
if (orte_process_info.hnp) {
if (ORTE_OUTPUT_STDOUT & flags) {
OPAL_OUTPUT_VERBOSE((5, orte_debug_output,
"%s output %s to stdout",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
output));
opal_output(stdout_stream, output);
} else {
OPAL_OUTPUT_VERBOSE((5, orte_debug_output,
"%s output %s to stderr",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
output));
opal_output(stderr_stream, output);
}
goto cleanup;
}
/* If I am NOT the HNP...
Per a soon-to-be-filed trac ticket: because this function calls
RML send, recursion is possible in two places:
1. RML send itself calls orte_output()
@ -354,21 +378,6 @@ static void output_vverbose(int verbose_level, int output_id,
}
am_inside = true;
/* if I am the HNP, then I need to just pass this on to the
* opal_output_verbose function using the provided stream
*/
if (orte_process_info.hnp) {
OPAL_OUTPUT_VERBOSE((5, orte_debug_output,
"%s output to stream %d",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
output_id));
opal_output(output_id, output);
goto cleanup;
}
/* lookup the flags for this stream */
flags = OPAL_VALUE_ARRAY_GET_ITEM(&orte_output_streams, uint8_t, output_id);
/* If there's other flags besides STDOUT and STDERR set, then also
output this locally via opal_output */
if ((~(ORTE_OUTPUT_STDOUT | ORTE_OUTPUT_STDERR)) & flags) {
@ -631,6 +640,15 @@ int orte_output_init(void)
/* define the default stream that has everything off */
OBJ_CONSTRUCT(&orte_output_default, opal_output_stream_t);
orte_output_default.lds_want_stdout = false;
if (orte_process_info.hnp) {
orte_output_default.lds_want_stderr = true;
} else {
/* if we are not the HNP, route stderr through
* the HNP - don't open it here
*/
orte_output_default.lds_want_stderr = false;
}
/* Show help duplicate detection */
OBJ_CONSTRUCT(&abd_tuples, opal_list_t);
@ -663,6 +681,15 @@ int orte_output_init(void)
OBJ_CONSTRUCT(&stdout_lds, opal_output_stream_t);
/* deliver to stdout only */
stdout_lds.lds_want_stdout = true;
if (orte_xml_output) {
/* define an appropriate prefix/suffix */
stdout_lds.lds_prefix = strdup("<stdout>");
stdout_lds.lds_suffix = strdup("</stdout>");
} else {
/* turn off the prefix/suffix */
stdout_lds.lds_prefix = NULL;
stdout_lds.lds_suffix = NULL;
}
stdout_stream = opal_output_open(&stdout_lds);
OPAL_VALUE_ARRAY_SET_ITEM(&orte_output_streams, uint8_t, stdout_stream, ORTE_OUTPUT_STDOUT);
/* setup stderr stream - we construct our own
@ -671,8 +698,15 @@ int orte_output_init(void)
OBJ_CONSTRUCT(&stderr_lds, opal_output_stream_t);
/* deliver to stderr only */
stderr_lds.lds_want_stderr = true;
/* we filter the stderr */
stderr_lds.lds_filter_flags = OPAL_OUTPUT_FILTER_STDERR;
if (orte_xml_output) {
/* define an appropriate prefix/suffix */
stderr_lds.lds_prefix = strdup("<stderr>");
stderr_lds.lds_suffix = strdup("</stderr>");
} else {
/* turn off the prefix/suffix */
stderr_lds.lds_prefix = NULL;
stderr_lds.lds_suffix = NULL;
}
stderr_stream = opal_output_open(&stderr_lds);
OPAL_VALUE_ARRAY_SET_ITEM(&orte_output_streams, uint8_t, stderr_stream, ORTE_OUTPUT_STDERR);
}
@ -757,22 +791,14 @@ int orte_output_open(opal_output_stream_t *lds)
return ORTE_ERROR;
}
/* if we are the HNP, this function just acts as
* a wrapper around the corresponding opal_output fn
*/
if (orte_process_info.hnp) {
stream = opal_output_open(lds);
OPAL_OUTPUT_VERBOSE((5, orte_debug_output, "HNP opened stream %d", stream));
goto track;
}
/* if we not the HNP, then we need to open the stream
/* open a stream
* and also record whether or not it is sending
* output to stdout/stderr
*/
if (NULL == lds) {
/* we have to ensure that the opal_output stream
* doesn't open stdout and stderr, so setup the
* doesn't open stdout and stderr unless we are
* the HNP, so setup the
* stream here and ensure the settings are
* correct - otherwise, opal_output will default
* the stream to having stderr active!
@ -784,6 +810,7 @@ int orte_output_open(opal_output_stream_t *lds)
if (lds->lds_want_stdout) {
flag |= ORTE_OUTPUT_STDOUT;
lds->lds_want_stdout = false;
lds->lds_prefix = NULL; /* turn off the prefix! */
}
/* does it involve stderr? */
if (lds->lds_want_stderr) {
@ -799,7 +826,6 @@ int orte_output_open(opal_output_stream_t *lds)
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
stream));
track:
/* track the settings - can't use macro as this may adjust size of array */
opal_value_array_set_item(&orte_output_streams, stream, (void*)&flag);
@ -836,7 +862,8 @@ void orte_output(int output_id, const char *format, ...)
/* just call output_vverbose with a verbosity of 0 */
va_start(arglist, format);
output_vverbose(0, output_id, ORTE_PROC_MY_NAME->jobid, ORTE_PROC_MY_NAME->vpid, format, arglist);
/* orte_output -always- gets printed, so set verbosity to neg value */
output_vverbose(-1, output_id, format, arglist);
va_end(arglist);
}
@ -872,7 +899,7 @@ void orte_output_verbose(int verbose_level, int output_id, const char *format, .
/* just call output_verbose with the specified verbosity */
va_start(arglist, format);
output_vverbose(verbose_level, output_id, ORTE_PROC_MY_NAME->jobid, ORTE_PROC_MY_NAME->vpid, format, arglist);
output_vverbose(verbose_level, output_id, format, arglist);
va_end(arglist);
}