Hi,
this is an unfortunate intrusive patch, but I don't see an easier way
out without adding a lot of hacks around. IMHO better do it clean now
than having to carry a lot of dirt around.
It changes the internal API and the amount of data are stored from the
flight recorder (to add tag tracking).
the patch does:
- clearly divide tags from priority. Before this was an incredible mix
that lead to tons of little hacks around when handling priority (see a
bunch of level+1 level-1).
- clearly define what TAG_LOG means.
- rewrite ENTER and LEAVE macro to use _logsys_log_printf rather than
_logsys_log_rec and have consistent behavior across tracing messages.
- set priority to LOGSYS_LEVEL_DEBUG to all tracing messages.
- add tag filter check to print to logs.
- don't automatically init subsystem tags to LOGSYS_TAG_LOG since
expected behaviour says that everything that goes via log_printf should
go to all logs (and hence set TAG_LOG).
- update flight recorder to handle tag and remove duplicate code.
- cleanup a couple of white spaces here and there.
- fix tracing messages that were sent with
LOGSYS_LEVEL_OMGTHEWORLDISFALLINGAPART priority everywhere
- allow OR`ed tags as it is supposed to be and not exclusive (in
configuration)
Fabio
Index: include/corosync/engine/logsys.h
===================================================================
--- include/corosync/engine/logsys.h (revision 2179)
+++ include/corosync/engine/logsys.h (working copy)
@@ -76,17 +76,17 @@
* LOG is mandatory, but enforced, for subsystems.
* Be careful if/when changing tags at runtime.
*/
-#define LOGSYS_TAG_LOG (0xff<<28)
-#define LOGSYS_TAG_ENTER (1<<27)
-#define LOGSYS_TAG_LEAVE (1<<26)
-#define LOGSYS_TAG_TRACE1 (1<<25)
-#define LOGSYS_TAG_TRACE2 (1<<24)
-#define LOGSYS_TAG_TRACE3 (1<<23)
-#define LOGSYS_TAG_TRACE4 (1<<22)
-#define LOGSYS_TAG_TRACE5 (1<<21)
-#define LOGSYS_TAG_TRACE6 (1<<20)
-#define LOGSYS_TAG_TRACE7 (1<<19)
-#define LOGSYS_TAG_TRACE8 (1<<18)
+#define LOGSYS_TAG_LOG (1<<0)
+#define LOGSYS_TAG_ENTER (1<<1)
+#define LOGSYS_TAG_LEAVE (1<<2)
+#define LOGSYS_TAG_TRACE1 (1<<3)
+#define LOGSYS_TAG_TRACE2 (1<<4)
+#define LOGSYS_TAG_TRACE3 (1<<5)
+#define LOGSYS_TAG_TRACE4 (1<<6)
+#define LOGSYS_TAG_TRACE5 (1<<7)
+#define LOGSYS_TAG_TRACE6 (1<<8)
+#define LOGSYS_TAG_TRACE7 (1<<9)
+#define LOGSYS_TAG_TRACE8 (1<<10)
/*
* Internal APIs that must be globally exported
@@ -125,8 +125,9 @@
const char *file_name,
int file_line,
unsigned int level,
+ unsigned int tag,
const char *format,
- va_list ap) __attribute__((format(printf, 6, 0)));
+ va_list ap) __attribute__((format(printf, 7, 0)));
extern void _logsys_log_printf (
int subsysid,
@@ -134,8 +135,9 @@
const char *file_name,
int file_line,
unsigned int level,
+ unsigned int tag,
const char *format,
- ...) __attribute__((format(printf, 6, 7)));
+ ...) __attribute__((format(printf, 7, 8)));
extern void _logsys_log_rec (
int subsysid,
@@ -143,6 +145,7 @@
const char *file_name,
int file_line,
unsigned int rec_ident,
+ unsigned int tag,
...);
extern int _logsys_wthread_create (void);
@@ -315,63 +318,75 @@
#define log_rec(rec_ident, args...) \
do { \
_logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, rec_ident, ##args); \
+ __FILE__, __LINE__, rec_ident, 0, ##args); \
} while(0)
#define log_printf(lvl, format, args...) \
do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, lvl, format, ##args); \
+ __FILE__, __LINE__, lvl, 0, format, ##args); \
} while(0)
#define ENTER() do { \
- _logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_ENTER, LOGSYS_REC_END); \
+ _logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_ENTER, "ENTERING function [%s] line [%d]\n", \
+ __FUNCTION__, __LINE__); \
} while(0)
#define LEAVE() do { \
- _logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_LEAVE, LOGSYS_REC_END); \
+ _logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_LEAVE, "LEAVING function [%s] line [%d]\n", \
+ __FUNCTION__, __LINE__); \
} while(0)
#define TRACE1(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE1, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE1, format, ##args); \
} while(0)
#define TRACE2(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE2, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE2, format, ##args); \
} while(0)
#define TRACE3(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE3, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE3, format, ##args); \
} while(0)
#define TRACE4(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE4, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE4, format, ##args); \
} while(0)
#define TRACE5(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE5, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE5, format, ##args); \
} while(0)
#define TRACE6(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE6, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE6, format, ##args); \
} while(0)
#define TRACE7(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE7, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE7, format, ##args); \
} while(0)
#define TRACE8(format, args...) do { \
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
- __FILE__, __LINE__, LOGSYS_TAG_TRACE8, format, ##args);\
+ __FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
+ LOGSYS_TAG_TRACE8, format, ##args); \
} while(0)
#ifdef __cplusplus
Index: exec/logsys.c
===================================================================
--- exec/logsys.c (revision 2179)
+++ exec/logsys.c (working copy)
@@ -421,6 +421,7 @@
const char *function_name,
int file_line,
unsigned int level,
+ unsigned int tag,
const char *buffer)
{
char output_buffer[COMBINE_BUFFER_SIZE];
@@ -432,13 +433,23 @@
size_t cutoff;
unsigned int len;
int subsysid;
+ int c, i, has_tag = 0;
subsysid = _logsys_config_subsys_get(subsys);
if (subsysid <= - 1) {
return;
}
- int c;
+ for (i = 1; tagnames[i].c_name != NULL; i++) {
+ if (tag & tagnames[i].c_val) {
+ if ((logsys_loggers[subsysid].tags & tag) == 0) {
+ return;
+ } else {
+ has_tag = 1;
+ }
+ }
+ }
+
while ((c = format_buffer[format_buffer_idx])) {
cutoff = 0;
if (c != '%') {
@@ -507,7 +518,7 @@
*/
if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_SYSLOG) &&
((level <= logsys_loggers[subsysid].syslog_priority) ||
- (logsys_loggers[subsysid].debug != 0))) {
+ (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
syslog (level | logsys_loggers[subsysid].syslog_facility, "%s", output_buffer);
}
@@ -523,7 +534,7 @@
if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE) &&
(logsys_loggers[subsysid].logfile_fp != NULL)) &&
((level <= logsys_loggers[subsysid].logfile_priority) ||
- (logsys_loggers[subsysid].debug != 0))) {
+ (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
/*
* Output to a file
*/
@@ -546,7 +557,7 @@
pthread_mutex_unlock (&logsys_config_mutex);
log_printf_to_logs(logsys_loggers[subsysid].subsys,
__FILE__, __FUNCTION__, __LINE__,
- LOGSYS_LEVEL_EMERG, tmpbuffer);
+ LOGSYS_LEVEL_EMERG, 0, tmpbuffer);
}
}
@@ -555,7 +566,7 @@
*/
if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_STDERR) &&
((level <= logsys_loggers[subsysid].logfile_priority) ||
- (logsys_loggers[subsysid].debug != 0))) {
+ (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
if (write (STDERR_FILENO, output_buffer, strlen (output_buffer)) < 0) {
char tmpbuffer[1024];
/*
@@ -571,7 +582,7 @@
logsys_loggers[subsysid].subsys);
log_printf_to_logs(logsys_loggers[subsysid].subsys,
__FILE__, __FUNCTION__, __LINE__,
- LOGSYS_LEVEL_EMERG, tmpbuffer);
+ LOGSYS_LEVEL_EMERG, 0, tmpbuffer);
}
}
}
@@ -580,17 +591,17 @@
{
const int *buf_uint32t = (const int *)buf;
unsigned int rec_size = buf_uint32t[0];
- unsigned int rec_ident = buf_uint32t[1];
- unsigned int file_line = buf_uint32t[2];
- unsigned int level = rec_ident >> 28;
+ unsigned int level = buf_uint32t[1];
+ unsigned int tag = buf_uint32t[2];
+ unsigned int file_line = buf_uint32t[3];
unsigned int i;
unsigned int words_processed;
unsigned int arg_size_idx;
const void *arguments[64];
unsigned int arg_count;
- arg_size_idx = 4;
- words_processed = 4;
+ arg_size_idx = 5;
+ words_processed = 5;
arg_count = 0;
for (i = 0; words_processed < rec_size; i++) {
@@ -611,22 +622,25 @@
(char *)arguments[1],
(char *)arguments[2],
file_line,
- (level-1),
+ level,
+ tag,
(char *)arguments[3]);
}
static int record_read (char *buf, int rec_idx, int *log_msg) {
- unsigned int rec_size;
- unsigned int rec_ident;
- int firstcopy, secondcopy;
+ unsigned int rec_size;
+ unsigned int rec_ident;
+ unsigned int tag;
+ int firstcopy, secondcopy;
rec_size = flt_data[rec_idx];
rec_ident = flt_data[(rec_idx + 1) % flt_data_size];
+ tag = flt_data[(rec_idx + 2) % flt_data_size];
/*
* Not a log record
*/
- if ((rec_ident & LOGSYS_TAG_LOG) == 0) {
+ if ((tag & LOGSYS_TAG_LOG) == 0) {
*log_msg = 0;
return ((rec_idx + rec_size) % flt_data_size);
}
@@ -898,7 +912,6 @@
memcpy(&logsys_loggers[subsysid],
&logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT],
sizeof(logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT]));
- logsys_loggers[subsysid].tags = LOGSYS_TAG_LOG;
logsys_loggers[subsysid].init_status =
LOGSYS_LOGGER_INIT_DONE;
}
@@ -1051,12 +1064,14 @@
* buffer arg1
* ... repeats length & arg
*/
+
void _logsys_log_rec (
int subsysid,
const char *function_name,
const char *file_name,
int file_line,
unsigned int rec_ident,
+ unsigned int tag,
...)
{
va_list ap;
@@ -1074,7 +1089,7 @@
/*
* Decode VA Args
*/
- va_start (ap, rec_ident);
+ va_start (ap, tag);
arguments = 3;
for (;;) {
buf_args[arguments] = va_arg (ap, void *);
@@ -1109,7 +1124,7 @@
/*
* Reclaim data needed for record including 4 words for the header
*/
- records_reclaim (idx, record_reclaim_size + 4);
+ records_reclaim (idx, record_reclaim_size + 5);
/*
* Write record size of zero and rest of header information
@@ -1120,6 +1135,9 @@
flt_data[idx++] = rec_ident;
idx_word_step(idx);
+ flt_data[idx++] = tag;
+ idx_word_step(idx);
+
flt_data[idx++] = file_line;
idx_word_step(idx);
@@ -1194,7 +1212,7 @@
* the new head position and commit the new head.
*/
logsys_lock();
- if (rec_ident & LOGSYS_TAG_LOG) {
+ if (tag & LOGSYS_TAG_LOG) {
log_requests_pending += 1;
}
if (log_requests_pending == 0) {
@@ -1211,6 +1229,7 @@
const char *file_name,
int file_line,
unsigned int level,
+ unsigned int tag,
const char *format,
va_list ap)
{
@@ -1240,7 +1259,8 @@
function_name,
file_name,
file_line,
- (level+1) << 28,
+ level,
+ tag |= LOGSYS_TAG_LOG,
logsys_print_buffer, len + 1,
LOGSYS_REC_END);
@@ -1250,7 +1270,7 @@
* expect the worker thread to output the log data once signaled
*/
log_printf_to_logs (logsys_loggers[subsysid].subsys,
- file_name, function_name, file_line, level,
+ file_name, function_name, file_line, level, tag,
logsys_print_buffer);
} else {
/*
@@ -1266,6 +1286,7 @@
const char *file_name,
int file_line,
unsigned int level,
+ unsigned int tag,
const char *format,
...)
{
@@ -1298,7 +1319,8 @@
function_name,
file_name,
file_line,
- (level+1) << 28,
+ level,
+ tag |= LOGSYS_TAG_LOG,
logsys_print_buffer, len + 1,
LOGSYS_REC_END);
@@ -1308,7 +1330,7 @@
* expect the worker thread to output the log data once signaled
*/
log_printf_to_logs (logsys_loggers[subsysid].subsys,
- file_name, function_name, file_line, level,
+ file_name, function_name, file_line, level, tag,
logsys_print_buffer);
} else {
/*
Index: exec/main.c
===================================================================
--- exec/main.c (revision 2179)
+++ exec/main.c (working copy)
@@ -547,14 +547,14 @@
va_start (ap, format);
_logsys_log_vprintf (ipc_subsys_id, __FUNCTION__,
- __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, format, ap);
+ __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, format, ap);
va_end (ap);
}
static void ipc_fatal_error(const char *error_msg) {
_logsys_log_printf (ipc_subsys_id, __FUNCTION__,
- __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, "%s", error_msg);
+ __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, "%s", error_msg);
exit(EXIT_FAILURE);
}
Index: tools/corosync-fplay.c
===================================================================
--- tools/corosync-fplay.c (revision 2179)
+++ tools/corosync-fplay.c (working copy)
@@ -371,6 +371,7 @@
const unsigned int *buf_uint32t = record;
unsigned int rec_size;
unsigned int rec_ident;
+ unsigned int tag;
unsigned int line;
unsigned int arg_size_idx;
unsigned int i;
@@ -384,12 +385,13 @@
rec_size = buf_uint32t[rec_idx];
rec_ident = buf_uint32t[rec_idx+1];
- line = buf_uint32t[rec_idx+2];
- record_number = buf_uint32t[rec_idx+3];
+ tag = buf_uint32t[rec_idx+2];
+ line = buf_uint32t[rec_idx+3];
+ record_number = buf_uint32t[rec_idx+4];
-printf ("rec=[%d] ", record_number);
- arg_size_idx = rec_idx + 4;
- words_processed = 4;
+ printf ("rec=[%d] ", record_number);
+ arg_size_idx = rec_idx + 5;
+ words_processed = 5;
for (i = 0; words_processed < rec_size; i++) {
arguments[arg_count++] =
(const char *)&buf_uint32t[arg_size_idx + 1];
@@ -409,38 +411,26 @@
}
}
}
- if (rec_ident & LOGSYS_TAG_LOG) {
- printf ("Log Message=%s\n", arguments[3]);
- found = 1;
- }
- if (rec_ident & LOGSYS_TAG_ENTER) {
+ if (tag & LOGSYS_TAG_ENTER) {
printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
found = 1;
}
- if (rec_ident & LOGSYS_TAG_LEAVE) {
+ if (tag & LOGSYS_TAG_LEAVE) {
printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
found = 1;
}
- if (found == 0) {
- printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
- arguments[0], rec_ident);
+ if (found == 1) {
+ tag &= ~LOGSYS_TAG_LOG;
}
-
-
- if (rec_ident == 999) {
- printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
+ if (tag & LOGSYS_TAG_LOG) {
+ printf ("Log Message=%s\n", arguments[3]);
found = 1;
}
- if (rec_ident == 1000) {
- printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
- found = 1;
- }
if (found == 0) {
printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
arguments[0], rec_ident);
}
-
#ifdef COMPILE_OUT
printf ("\n");
#endif
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais