static void profiling_msg_snapshot (flux_t *h, const flux_msg_t *msg, int flags, const char *msg_action) { h = lookup_clone_ancestor (h); cali_id_t attributes[3]; const void * data[3]; size_t size[3]; // This can get called before the handle is really ready if(! h->prof.initialized) return; int len = 0; if (msg_action) { attributes[len] = h->prof.msg_action; data[len] = msg_action; size[len] = strlen(msg_action); ++len; } int type; flux_msg_get_type (msg, &type); const char *msg_type = flux_msg_typestr (type); if (msg_type) { attributes[len] = h->prof.msg_type; data[len] = msg_type; size[len] = strlen(msg_type); ++len; } const char *msg_topic; if (type != FLUX_MSGTYPE_KEEPALIVE) flux_msg_get_topic (msg, &msg_topic); else msg_topic = "NONE"; /* attributes[len] = h->prof.msg_topic; */ /* data[len] = msg_topic; */ /* size[len] = strlen(msg_topic); */ /* ++len; */ if (type == FLUX_MSGTYPE_EVENT) { uint32_t seq; flux_msg_get_seq (msg, &seq); cali_begin_int (h->prof.msg_seq, seq); } cali_push_snapshot (CALI_SCOPE_PROCESS | CALI_SCOPE_THREAD, len /* n_entries */, attributes /* event_attributes */, data /* event_data */, size /* event_size */); if (type == FLUX_MSGTYPE_EVENT) cali_end (h->prof.msg_seq); }
int main() { cali_config_preset("CALI_CALIPER_FLUSH_ON_EXIT", "false"); cali_id_t iter_attr = cali_create_attribute("iteration", CALI_TYPE_INT, CALI_ATTR_ASVALUE); cali_begin_string_byname("phase", "loop"); for (int i = 0; i < 4; ++i) { cali_begin_int(iter_attr, i); cali_end(iter_attr); } cali_end_byname("phase"); cali_begin_byname("ci_test_c_ann.meta-attr"); cali_id_t meta_attr = cali_create_attribute("meta-attr", CALI_TYPE_INT, CALI_ATTR_DEFAULT); int val = 47; size_t meta_sizes = sizeof(int); const void* meta_val[1] = { &val }; cali_id_t test_attr = cali_create_attribute_with_metadata("test-attr-with-metadata", CALI_TYPE_STRING, CALI_ATTR_DEFAULT, 1, &meta_attr, meta_val, &meta_sizes); cali_set_string(test_attr, "abracadabra"); cali_end_byname("ci_test_c_ann.meta-attr"); cali_begin_byname("ci_test_c_ann.setbyname"); cali_set_int_byname("attr.int", 20); cali_set_double_byname("attr.dbl", 1.25); cali_set_string_byname("attr.str", "fidibus"); cali_end_byname("ci_test_c_ann.setbyname"); cali_flush(CALI_FLUSH_CLEAR_BUFFERS); }
/* If this function is called without the NONBLOCK flag from a reactor * handler running in coprocess context, the call to flux_sleep_on() * will allow the reactor to run until a message matching 'match' arrives. * The flux_sleep_on() call will then resume, and the next call to recv() * will return the matching message. If not running in coprocess context, * flux_sleep_on() will fail with EINVAL. In that case, the do loop * reading messages and comparing them to match criteria may have to read * a few non-matching messages before finding a match. On return, those * non-matching messages have to be requeued in the handle, hence the * defer_*() helper calls. */ flux_msg_t *flux_recv (flux_t h, struct flux_match match, int flags) { zlist_t *l = NULL; flux_msg_t *msg = NULL; int saved_errno; flags |= h->flags; if (!(flags & FLUX_O_NONBLOCK) && (flags & FLUX_O_COPROC) && flux_sleep_on (h, match) < 0) { if (errno != EINVAL) goto fatal; errno = 0; } do { if (!(msg = flux_recv_any (h, flags))) { if (errno != EAGAIN && errno != EWOULDBLOCK) goto fatal; if (defer_requeue (&l, h) < 0) goto fatal; defer_destroy (&l); errno = EWOULDBLOCK; return NULL; } if (!flux_msg_cmp (msg, match)) { if (defer_enqueue (&l, msg) < 0) goto fatal; msg = NULL; } } while (!msg); update_rx_stats (h, msg); if ((flags & FLUX_O_TRACE)) flux_msg_fprint (stderr, msg); if (defer_requeue (&l, h) < 0) goto fatal; defer_destroy (&l); #if HAVE_CALIPER cali_begin_int (h->prof.msg_match_type, match.typemask); cali_begin_int (h->prof.msg_match_tag, match.matchtag); cali_begin_string (h->prof.msg_match_glob, match.topic_glob ? match.topic_glob : "NONE"); char *sender = NULL; flux_msg_get_route_first (msg, &sender); if (sender) cali_begin_string (h->prof.msg_sender, sender); profiling_msg_snapshot (h, msg, flags, "recv"); if (sender) cali_end (h->prof.msg_sender); cali_end (h->prof.msg_match_type); cali_end (h->prof.msg_match_tag); cali_end (h->prof.msg_match_glob); free (sender); #endif return msg; fatal: saved_errno = errno; FLUX_FATAL (h); if (msg) flux_msg_destroy (msg); defer_destroy (&l); errno = saved_errno; return NULL; }