Skip to content

Commit

Permalink
libflux: make flux_msg_fprint() output clearer
Browse files Browse the repository at this point in the history
Problem: With zmsg_t being removed from the internals of the
flux_msg_t data structure (commit XXX), flux_msg_fprint() is no
longer beholden to the output format from zframe_fprint().  A more
clear format for debugging can be output.

Solution: Update flux_msg_fprint() to output all fields in the
message using clear key=value output and prefixes indicating the
"section" they belong to in the message.
  • Loading branch information
chu11 committed Jun 24, 2021
1 parent f373cf9 commit 7ae5a60
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
55 changes: 42 additions & 13 deletions src/common/libflux/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,6 @@ void flux_msg_fprint (FILE *f, const flux_msg_t *msg)
{
int hops;
const char *prefix;
uint8_t proto[PROTO_SIZE];
int i;

fprintf (f, "--------------------------------------\n");
if (!msg) {
Expand All @@ -1538,36 +1536,67 @@ void flux_msg_fprint (FILE *f, const flux_msg_t *msg)
*/
hops = flux_msg_get_route_count (msg); /* -1 if no route stack */
if (hops >= 0) {
int len = flux_msg_get_route_size (msg);
char *rte = flux_msg_get_route_string (msg);
assert (rte != NULL);
fprintf (f, "%s[%3.3d] |%s|\n", prefix, len, rte);
fprintf (f, "%s[routes] |%s|\n", prefix, rte);
free (rte);
};
/* Topic (keepalive has none)
*/
if (msg->topic)
fprintf (f, "%s[%3.3zu] %s\n", prefix, strlen (msg->topic), msg->topic);
fprintf (f, "%s[topic] %s\n", prefix, msg->topic);
/* Payload
*/
if (flux_msg_has_payload (msg)) {
const char *s;
const void *buf;
int size;
if (flux_msg_get_string (msg, &s) == 0)
fprintf (f, "%s[%3.3zu] %s\n", prefix, strlen (s), s);
fprintf (f, "%s[payload] size=%zu %s\n", prefix, strlen (s), s);
else if (flux_msg_get_payload (msg, &buf, &size) == 0)
fprintf (f, "%s[%3.3d] ...\n", prefix, size);
fprintf (f, "%s[payload] size=%d ...\n", prefix, size);
else
fprintf (f, "malformed payload\n");
}
/* Proto block
/* Proto info
*/
msg_proto_setup (msg, proto, PROTO_SIZE);
fprintf (f, "%s[%03d] ", prefix, PROTO_SIZE);
for (i = 0; i < PROTO_SIZE; i++)
fprintf (f, "%02X", proto[i]);
fprintf (f, "\n");
fprintf (f, "%s[proto header] type=%s flags=0x%X userid=%u rolemask=0x%X\n",
prefix,
flux_msg_typestr (msg->type),
msg->flags,
msg->userid,
msg->rolemask);
switch (msg->type) {
case FLUX_MSGTYPE_REQUEST:
fprintf (f, "%s[proto aux] nodeid=%u matchtag=%u\n",
prefix,
msg->nodeid,
msg->matchtag);
break;
case FLUX_MSGTYPE_RESPONSE:
fprintf (f, "%s[proto aux] errnum=%u matchtag=%u\n",
prefix,
msg->errnum,
msg->matchtag);
break;
case FLUX_MSGTYPE_EVENT:
fprintf (f, "%s[proto aux] sequence=%u\n",
prefix,
msg->sequence);
break;
case FLUX_MSGTYPE_KEEPALIVE:
fprintf (f, "%s[proto aux] errnum=%u status=%u\n",
prefix,
msg->errnum,
msg->status);
break;
default:
fprintf (f, "%s[proto aux] aux1=0x%X aux2=0x%X\n",
prefix,
msg->aux1,
msg->aux2);
break;
}
}

static zmsg_t *msg_to_zmsg (const flux_msg_t *msg)
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/test/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ void check_print (void)
{
flux_msg_t *msg;
char buf[] = "xxxxxxxx";
FILE *f = fopen ("/dev/null", "w");
FILE *f = stderr;
if (!f)
BAIL_OUT ("cannot open /dev/null for writing");

Expand Down

0 comments on commit 7ae5a60

Please sign in to comment.