From: Francis Deslauriers Date: Wed, 27 Jun 2018 19:23:59 +0000 (-0400) Subject: Cleanup: move session saving of K(ret)probe and function tracing to dedicated functions X-Git-Tag: v2.11.0-rc1~87 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=83712c39736bc4edbd64ca7e83192c9877a80a8e;p=lttng-tools.git Cleanup: move session saving of K(ret)probe and function tracing to dedicated functions Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 5a70fe609..3e2627818 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -383,8 +383,105 @@ const char *get_loglevel_type_string( } static +int save_kernel_function_event(struct config_writer *writer, + struct ltt_kernel_event *event) +{ + int ret; + + ret = config_writer_open_element(writer, config_element_function_attributes); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_string(writer, config_element_name, + event->event->u.ftrace.symbol_name); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + /* /function attributes */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} + +static +int save_kernel_kprobe_event(struct config_writer *writer, + struct ltt_kernel_event *event) +{ + int ret; + const char *symbol_name; + uint64_t addr; + uint64_t offset; + + switch (event->event->instrumentation) { + case LTTNG_KERNEL_KPROBE: + /* + * Comments in lttng-kernel.h mention that + * either addr or symbol_name are set, not both. + */ + addr = event->event->u.kprobe.addr; + offset = event->event->u.kprobe.offset; + symbol_name = addr ? NULL : event->event->u.kprobe.symbol_name; + break; + case LTTNG_KERNEL_KRETPROBE: + addr = event->event->u.kretprobe.addr; + offset = event->event->u.kretprobe.offset; + symbol_name = event->event->u.kretprobe.symbol_name; + break; + default: + assert(1); + } + + ret = config_writer_open_element(writer, config_element_probe_attributes); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + if (symbol_name) { + ret = config_writer_write_element_string(writer, + config_element_symbol_name, symbol_name); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } + + if (addr) { + ret = config_writer_write_element_unsigned_int( writer, + config_element_address, addr); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } + + if (offset) { + ret = config_writer_write_element_unsigned_int(writer, + config_element_offset, offset); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } + + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} int save_kernel_event(struct config_writer *writer, - struct ltt_kernel_event *event) + struct ltt_kernel_event *event) { int ret; const char *instrumentation_type; @@ -449,94 +546,18 @@ int save_kernel_event(struct config_writer *writer, switch (event->event->instrumentation) { case LTTNG_KERNEL_SYSCALL: case LTTNG_KERNEL_FUNCTION: - ret = config_writer_open_element(writer, - config_element_function_attributes); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = config_writer_write_element_string(writer, - config_element_name, - event->event->u.ftrace.symbol_name); + ret = save_kernel_function_event(writer, event); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - /* /function attributes */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } break; case LTTNG_KERNEL_KPROBE: case LTTNG_KERNEL_KRETPROBE: - { - const char *symbol_name; - uint64_t addr; - uint64_t offset; - - if (event->event->instrumentation == - LTTNG_KERNEL_KPROBE) { - /* - * Comments in lttng-kernel.h mention that - * either addr or symbol_name are set, not both. - */ - addr = event->event->u.kprobe.addr; - offset = event->event->u.kprobe.offset; - symbol_name = addr ? NULL : - event->event->u.kprobe.symbol_name; - } else { - symbol_name = - event->event->u.kretprobe.symbol_name; - addr = event->event->u.kretprobe.addr; - offset = event->event->u.kretprobe.offset; - } - - ret = config_writer_open_element(writer, - config_element_probe_attributes); + ret = save_kernel_kprobe_event(writer, event); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - if (symbol_name) { - ret = config_writer_write_element_string(writer, - config_element_symbol_name, - symbol_name); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } - - if (addr) { - ret = config_writer_write_element_unsigned_int( - writer, config_element_address, addr); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } - - if (offset) { - ret = config_writer_write_element_unsigned_int( - writer, config_element_offset, offset); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } - - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } break; - } default: ERR("Unsupported kernel instrumentation type."); ret = LTTNG_ERR_INVALID;