Cleanup: move session saving of K(ret)probe and function tracing to dedicated functions
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 27 Jun 2018 19:23:59 +0000 (15:23 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 19:45:39 +0000 (15:45 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/save.c

index 5a70fe609204a1ad1e1b3bffdf091aee40cd90b4..3e2627818deffffceb5f5deeb03c31111be25482 100644 (file)
@@ -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;
This page took 0.029212 seconds and 5 git commands to generate.