Implement libcounter
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index de03407b702aa5851f7fc69ae99633f5f08455f4..4b13571df3b0a3edf46e90162545e91cf9080e04 100644 (file)
@@ -350,6 +350,13 @@ static const char *cmd_name_mapping[] = {
 
        /* Event notifier group commands */
        [ LTTNG_UST_EVENT_NOTIFIER_CREATE ] = "Create event notifier",
+
+       /* Session and event notifier group commands */
+       [ LTTNG_UST_COUNTER ] = "Create Counter",
+
+       /* Counter commands */
+       [ LTTNG_UST_COUNTER_GLOBAL ] = "Create Counter Global",
+       [ LTTNG_UST_COUNTER_CPU ] = "Create Counter CPU",
 };
 
 static const char *str_timeout;
@@ -365,6 +372,10 @@ extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
 extern void lttng_ring_buffer_client_discard_exit(void);
 extern void lttng_ring_buffer_client_discard_rt_exit(void);
 extern void lttng_ring_buffer_metadata_client_exit(void);
+extern void lttng_counter_client_percpu_32_modular_init(void);
+extern void lttng_counter_client_percpu_32_modular_exit(void);
+extern void lttng_counter_client_percpu_64_modular_init(void);
+extern void lttng_counter_client_percpu_64_modular_exit(void);
 
 static char *get_map_shm(struct sock_info *sock_info);
 
@@ -1133,6 +1144,79 @@ int handle_message(struct sock_info *sock_info,
                        ret = -ENOSYS;
                }
                break;
+       case LTTNG_UST_COUNTER:
+       {
+               void *counter_data;
+
+               len = ustcomm_recv_counter_from_sessiond(sock,
+                               &counter_data, lum->u.counter.len);
+               switch (len) {
+               case 0: /* orderly shutdown */
+                       ret = 0;
+                       goto error;
+               default:
+                       if (len == lum->u.counter.len) {
+                               DBG("counter data received");
+                               break;
+                       } else if (len < 0) {
+                               DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
+                               if (len == -ECONNRESET) {
+                                       ERR("%s remote end closed connection", sock_info->name);
+                                       ret = len;
+                                       goto error;
+                               }
+                               ret = len;
+                               goto error;
+                       } else {
+                               DBG("incorrect counter data message size: %zd", len);
+                               ret = -EINVAL;
+                               goto error;
+                       }
+               }
+               args.counter.counter_data = counter_data;
+               if (ops->cmd)
+                       ret = ops->cmd(lum->handle, lum->cmd,
+                                       (unsigned long) &lum->u,
+                                       &args, sock_info);
+               else
+                       ret = -ENOSYS;
+               break;
+       }
+       case LTTNG_UST_COUNTER_GLOBAL:
+       {
+               /* Receive shm_fd */
+               ret = ustcomm_recv_counter_shm_from_sessiond(sock,
+                       &args.counter_shm.shm_fd);
+               if (ret) {
+                       goto error;
+               }
+
+               if (ops->cmd)
+                       ret = ops->cmd(lum->handle, lum->cmd,
+                                       (unsigned long) &lum->u,
+                                       &args, sock_info);
+               else
+                       ret = -ENOSYS;
+               break;
+       }
+       case LTTNG_UST_COUNTER_CPU:
+       {
+               /* Receive shm_fd */
+               ret = ustcomm_recv_counter_shm_from_sessiond(sock,
+                       &args.counter_shm.shm_fd);
+               if (ret) {
+                       goto error;
+               }
+
+               if (ops->cmd)
+                       ret = ops->cmd(lum->handle, lum->cmd,
+                                       (unsigned long) &lum->u,
+                                       &args, sock_info);
+               else
+                       ret = -ENOSYS;
+               break;
+       }
+
        default:
                if (ops->cmd)
                        ret = ops->cmd(lum->handle, lum->cmd,
@@ -1958,6 +2042,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
        lttng_ring_buffer_client_overwrite_rt_init();
        lttng_ring_buffer_client_discard_init();
        lttng_ring_buffer_client_discard_rt_init();
+       lttng_counter_client_percpu_32_modular_init();
+       lttng_counter_client_percpu_64_modular_init();
        lttng_perf_counter_init();
        /*
         * Invoke ust malloc wrapper init before starting other threads.
@@ -2103,6 +2189,8 @@ void lttng_ust_cleanup(int exiting)
        lttng_ring_buffer_client_overwrite_rt_exit();
        lttng_ring_buffer_client_overwrite_exit();
        lttng_ring_buffer_metadata_client_exit();
+       lttng_counter_client_percpu_32_modular_exit();
+       lttng_counter_client_percpu_64_modular_exit();
        lttng_ust_statedump_destroy();
        exit_tracepoint();
        if (!exiting) {
This page took 0.0245610000000001 seconds and 4 git commands to generate.