X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconditions%2Fevent-rule-matches.c;h=d91a2c3e781de6904d2b78d9c72893e0de8d2c8c;hb=ca806b0b247f89c62ac628a7779ae84049a8c2d7;hp=b2abcc7648e072f2225a5cf50b472278d2f84989;hpb=4f7da553ae57a6c947da2b9668c06418b2d50e99;p=lttng-tools.git diff --git a/src/common/conditions/event-rule-matches.c b/src/common/conditions/event-rule-matches.c index b2abcc764..d91a2c3e7 100644 --- a/src/common/conditions/event-rule-matches.c +++ b/src/common/conditions/event-rule-matches.c @@ -5,10 +5,9 @@ * */ -#include #include -#include #include +#include #include #include #include @@ -434,6 +433,81 @@ void destroy_capture_descriptor(void *ptr) free(desc); } +static enum lttng_error_code lttng_condition_event_rule_matches_mi_serialize( + const struct lttng_condition *condition, + struct mi_writer *writer) +{ + int ret; + enum lttng_error_code ret_code; + enum lttng_condition_status status; + const struct lttng_event_rule *rule = NULL; + unsigned int capture_descriptor_count, i; + + LTTNG_ASSERT(condition); + LTTNG_ASSERT(writer); + LTTNG_ASSERT(IS_EVENT_RULE_MATCHES_CONDITION(condition)); + + status = lttng_condition_event_rule_matches_get_rule(condition, &rule); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + LTTNG_ASSERT(rule != NULL); + + status = lttng_condition_event_rule_matches_get_capture_descriptor_count( + condition, &capture_descriptor_count); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + + /* Open condition event rule matches element. */ + ret = mi_lttng_writer_open_element( + writer, mi_lttng_element_condition_event_rule_matches); + if (ret) { + goto mi_error; + } + + /* Serialize the event rule. */ + ret_code = lttng_event_rule_mi_serialize(rule, writer); + if (ret_code != LTTNG_OK) { + goto end; + } + + /* Open the capture descriptors element. */ + ret = mi_lttng_writer_open_element( + writer, mi_lttng_element_capture_descriptors); + if (ret) { + goto mi_error; + } + + for (i = 0; i < capture_descriptor_count; i++) { + const struct lttng_event_expr *descriptor = NULL; + + descriptor = lttng_condition_event_rule_matches_get_capture_descriptor_at_index( + condition, i); + LTTNG_ASSERT(descriptor); + + ret_code = lttng_event_expr_mi_serialize(descriptor, writer); + if (ret_code != LTTNG_OK) { + goto end; + } + } + + /* Close capture descriptors element. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + + /* Close condition_event_rule_matches. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + ret_code = LTTNG_OK; + goto end; + +mi_error: + ret_code = LTTNG_ERR_MI_IO_FAIL; +end: + return ret_code; +} + struct lttng_condition *lttng_condition_event_rule_matches_create( struct lttng_event_rule *rule) { @@ -457,6 +531,7 @@ struct lttng_condition *lttng_condition_event_rule_matches_create( lttng_condition_event_rule_matches_serialize, condition->parent.equal = lttng_condition_event_rule_matches_is_equal, condition->parent.destroy = lttng_condition_event_rule_matches_destroy, + condition->parent.mi_serialize = lttng_condition_event_rule_matches_mi_serialize, lttng_event_rule_get(rule); condition->rule = rule; @@ -627,7 +702,6 @@ end: return expr; } -LTTNG_HIDDEN ssize_t lttng_condition_event_rule_matches_create_from_payload( struct lttng_payload_view *view, struct lttng_condition **_condition) @@ -665,7 +739,7 @@ ssize_t lttng_condition_event_rule_matches_create_from_payload( } /* Capture descriptor count. */ - assert(event_rule_length >= 0); + LTTNG_ASSERT(event_rule_length >= 0); capture_descr_count = uint_from_buffer(&view->buffer, sizeof(uint32_t), &offset); if (capture_descr_count == UINT32_C(-1)) { goto error; @@ -705,7 +779,6 @@ end: return consumed_length; } -LTTNG_HIDDEN enum lttng_condition_status lttng_condition_event_rule_matches_borrow_rule_mutable( const struct lttng_condition *condition, @@ -745,7 +818,6 @@ enum lttng_condition_status lttng_condition_event_rule_matches_get_rule( return status; } -LTTNG_HIDDEN void lttng_condition_event_rule_matches_set_error_counter_index( struct lttng_condition *condition, uint64_t error_counter_index) { @@ -758,7 +830,6 @@ void lttng_condition_event_rule_matches_set_error_counter_index( error_counter_index); } -LTTNG_HIDDEN uint64_t lttng_condition_event_rule_matches_get_error_counter_index( const struct lttng_condition *condition) { @@ -797,7 +868,11 @@ lttng_condition_event_rule_matches_append_capture_descriptor( } switch(lttng_event_rule_get_type(rule)) { - case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: + case LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT: + case LTTNG_EVENT_RULE_TYPE_KERNEL_TRACEPOINT: + case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING: + case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING: + case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING: case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL: /* Supported. */ status = LTTNG_CONDITION_STATUS_OK; @@ -879,7 +954,6 @@ end: return expr; } -LTTNG_HIDDEN ssize_t lttng_evaluation_event_rule_matches_create_from_payload( const struct lttng_condition_event_rule_matches *condition, struct lttng_payload_view *view, @@ -971,7 +1045,7 @@ bool msgpack_str_is_equal(const struct msgpack_object *obj, const char *str) { bool is_equal = true; - assert(obj->type == MSGPACK_OBJECT_STR); + LTTNG_ASSERT(obj->type == MSGPACK_OBJECT_STR); if (obj->via.str.size != strlen(str)) { is_equal = false; @@ -994,12 +1068,12 @@ const msgpack_object *get_msgpack_map_obj(const struct msgpack_object *map_obj, const msgpack_object *ret = NULL; size_t i; - assert(map_obj->type == MSGPACK_OBJECT_MAP); + LTTNG_ASSERT(map_obj->type == MSGPACK_OBJECT_MAP); for (i = 0; i < map_obj->via.map.size; i++) { const struct msgpack_object_kv *kv = &map_obj->via.map.ptr[i]; - assert(kv->key.type == MSGPACK_OBJECT_STR); + LTTNG_ASSERT(kv->key.type == MSGPACK_OBJECT_STR); if (msgpack_str_is_equal(&kv->key, name)) { ret = &kv->val; @@ -1029,8 +1103,8 @@ int event_field_value_from_obj(const msgpack_object *obj, { int ret = 0; - assert(obj); - assert(field_val); + LTTNG_ASSERT(obj); + LTTNG_ASSERT(field_val); switch (obj->type) { case MSGPACK_OBJECT_NIL: @@ -1212,8 +1286,8 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( size_t i; size_t count; - assert(condition); - assert(capture_payload); + LTTNG_ASSERT(condition); + LTTNG_ASSERT(capture_payload); /* Initialize value. */ msgpack_unpacked_init(&unpacked); @@ -1258,7 +1332,7 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( */ count = lttng_dynamic_pointer_array_get_count( &condition->capture_descriptors); - assert(count > 0); + LTTNG_ASSERT(count > 0); for (i = 0; i < count; i++) { const struct lttng_capture_descriptor *capture_descriptor = @@ -1268,7 +1342,7 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( struct lttng_event_field_value *elem_field_val; int iret; - assert(capture_descriptor); + LTTNG_ASSERT(capture_descriptor); elem_obj = &root_array_obj->ptr[i]; iret = event_field_value_from_obj(elem_obj, @@ -1302,7 +1376,6 @@ end: return ret; } -LTTNG_HIDDEN struct lttng_evaluation *lttng_evaluation_event_rule_matches_create( const struct lttng_condition_event_rule_matches *condition, const char *capture_payload, @@ -1385,7 +1458,6 @@ end: return status; } -LTTNG_HIDDEN enum lttng_error_code lttng_condition_event_rule_matches_generate_capture_descriptor_bytecode( struct lttng_condition *condition) @@ -1433,7 +1505,6 @@ end: return ret; } -LTTNG_HIDDEN const struct lttng_bytecode * lttng_condition_event_rule_matches_get_capture_bytecode_at_index( const struct lttng_condition *condition, unsigned int index)