Rename struct lib_ring_buffer* to struct lttng_ust_lib_ring_buffer*
[lttng-ust.git] / tests / ust-basic-tracing / ust-basic-tracing.c
index d0ba4137d9899ed760194e749b94626fc8d022b1..49a0a3af1cc392e96b3d0e7f0fd5d296228bcb2d 100644 (file)
 #include <assert.h>
 #include <sys/socket.h>
 
-#include "lttng-ust-comm.h"
+#include <ust/lttng-ust-comm.h>
 #include "../../libringbuffer/backend.h"
 #include "../../libringbuffer/frontend.h"
 
 #define MAX_NR_STREAMS 64
 #define MAX_NR_EVENTS  128
 
-struct object_data {
-       int handle;
-       int shm_fd;
-       int wait_fd;
-       uint64_t memory_map_size;
-};
-
 static int session_handle;
-static struct object_data metadata_stream_data;
-static struct object_data metadata_data;
-static struct object_data channel_data;
-static struct object_data stream_data[MAX_NR_STREAMS];
+static struct lttng_ust_object_data metadata_stream_data;
+static struct lttng_ust_object_data metadata_data;
+static struct lttng_ust_object_data channel_data;
+static struct lttng_ust_object_data stream_data[MAX_NR_STREAMS];
 static int event_handle[MAX_NR_EVENTS];
 static int context_handle;
 
@@ -69,171 +62,36 @@ static void handle_signals(int signo)
        quit_program = 1;
 }
 
-static int send_app_msg(int sock, struct lttcomm_ust_msg *lum)
-{
-       ssize_t len;
-
-       len = lttcomm_send_unix_sock(sock, lum, sizeof(*lum));
-       switch (len) {
-       case sizeof(*lum):
-               printf("message successfully sent\n");
-               break;
-       case -1:
-               if (errno == ECONNRESET) {
-                       printf("remote end closed connection\n");
-                       return 0;
-               }
-               return -1;
-       default:
-               printf("incorrect message size: %zd\n", len);
-               return -1;
-       }
-       return 0;
-}
-
-static int recv_app_reply(int sock, struct lttcomm_ust_reply *lur,
-                         uint32_t expected_handle, uint32_t expected_cmd)
-{
-       ssize_t len;
-
-       memset(lur, 0, sizeof(*lur));
-       len = lttcomm_recv_unix_sock(sock, lur, sizeof(*lur));
-       switch (len) {
-       case 0: /* orderly shutdown */
-               printf("Application has performed an orderly shutdown\n");
-               return -EINVAL;
-       case sizeof(*lur):
-               printf("result message received\n");
-               if (lur->handle != expected_handle) {
-                       printf("Unexpected result message handle\n");
-                       return -EINVAL;
-               }
-
-               if (lur->cmd != expected_cmd) {
-                       printf("Unexpected result message command\n");
-                       return -EINVAL;
-               }
-               if (lur->ret_code != LTTCOMM_OK) {
-                       printf("remote operation failed with code %d.\n",
-                               lur->ret_code);
-                       return lur->ret_code;
-               }
-               return 0;
-       case -1:
-               if (errno == ECONNRESET) {
-                       printf("remote end closed connection\n");
-                       return -EINVAL;
-               }
-               return -1;
-       default:
-               printf("incorrect message size: %zd\n", len);
-               return len > 0 ? -1 : len;
-       }
-}
-
-static int send_app_cmd(int sock,
-                       struct lttcomm_ust_msg *lum,
-                       struct lttcomm_ust_reply *lur)
-{
-       int ret;
-
-       ret = send_app_msg(sock, lum);
-       if (ret)
-               return ret;
-       ret = recv_app_reply(sock, lur, lum->handle, lum->cmd);
-       if (ret)
-               return ret;
-       return 0;
-}
-
-
-/*
- * Receives a single fd from socket.
- *
- * Returns the size of received data
- */
-static int lttcomm_recv_fd(int sock)
-{
-       struct iovec iov[1];
-       int ret = 0;
-       int data_fd;
-       struct cmsghdr *cmsg;
-       char recv_fd[CMSG_SPACE(sizeof(int))];
-       struct msghdr msg = { 0 };
-       union {
-               unsigned char vc[4];
-               int vi;
-       } tmp;
-       int i;
-
-       /* Prepare to receive the structures */
-       iov[0].iov_base = &data_fd;
-       iov[0].iov_len = sizeof(data_fd);
-       msg.msg_iov = iov;
-       msg.msg_iovlen = 1;
-       msg.msg_control = recv_fd;
-       msg.msg_controllen = sizeof(recv_fd);
-
-       printf("Waiting to receive fd\n");
-       if ((ret = recvmsg(sock, &msg, 0)) < 0) {
-               perror("recvmsg");
-               goto end;
-       }
-       if (ret != sizeof(data_fd)) {
-               printf("Received %d bytes, expected %ld", ret, sizeof(data_fd));
-               goto end;
-       }
-       cmsg = CMSG_FIRSTHDR(&msg);
-       if (!cmsg) {
-               printf("Invalid control message header\n");
-               ret = -1;
-               goto end;
-       }
-       if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
-               printf("Didn't received any fd\n");
-               ret = -1;
-               goto end;
-       }
-       /* this is our fd */
-       for (i = 0; i < sizeof(int); i++)
-               tmp.vc[i] = CMSG_DATA(cmsg)[i];
-       ret = tmp.vi;
-       printf("received fd %d\n", ret);
-end:
-       return ret;
-}
-
-
 static
-int open_streams(int sock, int channel_handle, struct object_data *stream_datas,
+int open_streams(int sock, int channel_handle, struct lttng_ust_object_data *stream_datas,
                int nr_check)
 {
        int ret, k = 0;
 
        for (;;) {
-               struct lttcomm_ust_msg lum;
-               struct lttcomm_ust_reply lur;
+               struct ustcomm_ust_msg lum;
+               struct ustcomm_ust_reply lur;
 
                memset(&lum, 0, sizeof(lum));
                lum.handle = channel_handle;
                lum.cmd = LTTNG_UST_STREAM;
-               ret = send_app_cmd(sock, &lum, &lur);
+               ret = ustcomm_send_app_cmd(sock, &lum, &lur);
                if (!ret) {
                        assert(k < nr_check);
                        stream_datas[k].handle = lur.ret_val;
                        printf("received stream handle %u\n",
                                stream_datas[k].handle);
-                       if (lur.ret_code == LTTCOMM_OK) {
+                       if (lur.ret_code == USTCOMM_OK) {
                                ssize_t len;
 
                                stream_datas[k].memory_map_size = lur.u.stream.memory_map_size;
                                /* get shm fd */
-                               len = lttcomm_recv_fd(sock);
+                               len = ustcomm_recv_fd(sock);
                                if (len < 0)
                                        return -EINVAL;
                                stream_datas[k].shm_fd = len;
                                /* get wait fd */
-                               len = lttcomm_recv_fd(sock);
+                               len = ustcomm_recv_fd(sock);
                                if (len < 0)
                                        return -EINVAL;
                                stream_datas[k].wait_fd = len;
@@ -249,20 +107,20 @@ int open_streams(int sock, int channel_handle, struct object_data *stream_datas,
 }
 
 static
-int close_streams(int sock, struct object_data *stream_datas, int nr_check)
+int close_streams(int sock, struct lttng_ust_object_data *stream_datas, int nr_check)
 {
        int ret, k;
 
        for (k = 0; k < nr_check; k++) {
-               struct lttcomm_ust_msg lum;
-               struct lttcomm_ust_reply lur;
+               struct ustcomm_ust_msg lum;
+               struct ustcomm_ust_reply lur;
 
                if (!stream_datas[k].handle)
                        continue;
                memset(&lum, 0, sizeof(lum));
                lum.handle = stream_datas[k].handle;
                lum.cmd = LTTNG_UST_RELEASE;
-               ret = send_app_cmd(sock, &lum, &lur);
+               ret = ustcomm_send_app_cmd(sock, &lum, &lur);
                if (ret) {
                        printf("Error closing stream\n");
                        return ret;
@@ -286,10 +144,10 @@ int close_streams(int sock, struct object_data *stream_datas, int nr_check)
 }
 
 static
-struct shm_handle *map_channel(struct object_data *chan_data,
-               struct object_data *stream_datas, int nr_check)
+struct lttng_ust_shm_handle *map_channel(struct lttng_ust_object_data *chan_data,
+               struct lttng_ust_object_data *stream_datas, int nr_check)
 {
-       struct shm_handle *handle;
+       struct lttng_ust_shm_handle *handle;
        struct channel *chan;
        int k, ret;
 
@@ -306,7 +164,7 @@ struct shm_handle *map_channel(struct object_data *chan_data,
        chan = shmp(handle, handle->chan);
 
        for (k = 0; k < nr_check; k++) {
-               struct object_data *stream_data = &stream_datas[k];
+               struct lttng_ust_object_data *stream_data = &stream_datas[k];
 
                if (!stream_data->handle)
                        break;
@@ -330,7 +188,7 @@ error_destroy:
 }
 
 static
-void unmap_channel(struct shm_handle *handle)
+void unmap_channel(struct lttng_ust_shm_handle *handle)
 {
        struct channel *chan;
 
@@ -340,10 +198,10 @@ void unmap_channel(struct shm_handle *handle)
 }
 
 static
-int consume_stream(struct shm_handle *handle, int cpu, char *outfile)
+int consume_stream(struct lttng_ust_shm_handle *handle, int cpu, char *outfile)
 {
        struct channel *chan;
-       struct lib_ring_buffer *buf;
+       struct lttng_ust_lib_ring_buffer *buf;
        int outfd, ret;
        int shm_fd, wait_fd;
        uint64_t memory_map_size;
@@ -416,7 +274,7 @@ int consume_buffers(const char *outputpath)
        int k, ret;
        mode_t old_umask;
        char pathname[PATH_MAX];
-       struct shm_handle *handle;
+       struct lttng_ust_shm_handle *handle;
 
        snprintf(pathname, PATH_MAX - 1, "%s", outputpath);
        old_umask = umask(0);
@@ -461,18 +319,19 @@ int consume_buffers(const char *outputpath)
        return 0;
 }
 
+static
 int send_app_msgs(int sock, const char *outputpath,
                unsigned int nr_events, const char **event_names)
 {
-       struct lttcomm_ust_msg lum;
-       struct lttcomm_ust_reply lur;
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
        int ret, k;
 
        /* Create session */
        memset(&lum, 0, sizeof(lum));
        lum.handle = LTTNG_UST_ROOT_HANDLE;
        lum.cmd = LTTNG_UST_SESSION;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        session_handle = lur.ret_val;
@@ -488,22 +347,22 @@ int send_app_msgs(int sock, const char *outputpath,
        lum.u.channel.switch_timer_interval = 0;
        lum.u.channel.read_timer_interval = 0;
        lum.u.channel.output = LTTNG_UST_MMAP;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        metadata_data.handle = lur.ret_val;
        printf("received metadata handle %u\n", metadata_data.handle);
-       if (lur.ret_code == LTTCOMM_OK) {
+       if (lur.ret_code == USTCOMM_OK) {
                ssize_t len;
 
                metadata_data.memory_map_size = lur.u.channel.memory_map_size;
                /* get shm fd */
-               len = lttcomm_recv_fd(sock);
+               len = ustcomm_recv_fd(sock);
                if (len < 0)
                        return -EINVAL;
                metadata_data.shm_fd = len;
                /* get wait fd */
-               len = lttcomm_recv_fd(sock);
+               len = ustcomm_recv_fd(sock);
                if (len < 0)
                        return -EINVAL;
                metadata_data.wait_fd = len;
@@ -529,22 +388,22 @@ int send_app_msgs(int sock, const char *outputpath,
        lum.u.channel.switch_timer_interval = 0;
        lum.u.channel.read_timer_interval = 0;
        lum.u.channel.output = LTTNG_UST_MMAP;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        channel_data.handle = lur.ret_val;
        printf("received channel handle %u\n", channel_data.handle);
-       if (lur.ret_code == LTTCOMM_OK) {
+       if (lur.ret_code == USTCOMM_OK) {
                ssize_t len;
 
                channel_data.memory_map_size = lur.u.channel.memory_map_size;
                /* get shm fd */
-               len = lttcomm_recv_fd(sock);
+               len = ustcomm_recv_fd(sock);
                if (len < 0)
                        return -EINVAL;
                channel_data.shm_fd = len;
                /* get wait fd */
-               len = lttcomm_recv_fd(sock);
+               len = ustcomm_recv_fd(sock);
                if (len < 0)
                        return -EINVAL;
                channel_data.wait_fd = len;
@@ -558,19 +417,22 @@ int send_app_msgs(int sock, const char *outputpath,
                strncpy(lum.u.event.name, event_names[k],
                        LTTNG_UST_SYM_NAME_LEN);
                lum.u.event.instrumentation = LTTNG_UST_TRACEPOINT;
-               ret = send_app_cmd(sock, &lum, &lur);
+               ret = ustcomm_send_app_cmd(sock, &lum, &lur);
                if (ret)
                        return ret;
                event_handle[k] = lur.ret_val;
                printf("received event handle %u\n", event_handle[k]);
        }
 
-       /* Attach pthread_id context */
+       /* Attach vtid context */
        memset(&lum, 0, sizeof(lum));
        lum.handle = channel_data.handle;
        lum.cmd = LTTNG_UST_CONTEXT;
-       lum.u.context.ctx = LTTNG_UST_CONTEXT_PTHREAD_ID;
-       ret = send_app_cmd(sock, &lum, &lur);
+       lum.u.context.ctx = LTTNG_UST_CONTEXT_VTID;
+       //lum.u.context.ctx = LTTNG_UST_CONTEXT_PTHREAD_ID;
+       //lum.u.context.ctx = LTTNG_UST_CONTEXT_VPID;
+       //lum.u.context.ctx = LTTNG_UST_CONTEXT_PROCNAME;
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        context_handle = lur.ret_val;
@@ -587,7 +449,7 @@ int send_app_msgs(int sock, const char *outputpath,
        memset(&lum, 0, sizeof(lum));
        lum.handle = session_handle;
        lum.cmd = LTTNG_UST_SESSION_START;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        printf("Session handle %u started.\n", session_handle);
@@ -596,7 +458,7 @@ int send_app_msgs(int sock, const char *outputpath,
        memset(&lum, 0, sizeof(lum));
        lum.handle = LTTNG_UST_ROOT_HANDLE;
        lum.cmd = LTTNG_UST_REGISTER_DONE;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        printf("Registration done acknowledged.\n");
@@ -620,7 +482,7 @@ int send_app_msgs(int sock, const char *outputpath,
        memset(&lum, 0, sizeof(lum));
        lum.handle = context_handle;
        lum.cmd = LTTNG_UST_RELEASE;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
 
@@ -629,14 +491,14 @@ int send_app_msgs(int sock, const char *outputpath,
                memset(&lum, 0, sizeof(lum));
                lum.handle = event_handle[k];
                lum.cmd = LTTNG_UST_RELEASE;
-               ret = send_app_cmd(sock, &lum, &lur);
+               ret = ustcomm_send_app_cmd(sock, &lum, &lur);
                if (ret)
                        return ret;
        }
        memset(&lum, 0, sizeof(lum));
        lum.handle = channel_data.handle;
        lum.cmd = LTTNG_UST_RELEASE;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        if (channel_data.shm_fd >= 0) {
@@ -658,7 +520,7 @@ int send_app_msgs(int sock, const char *outputpath,
        memset(&lum, 0, sizeof(lum));
        lum.handle = metadata_data.handle;
        lum.cmd = LTTNG_UST_RELEASE;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
        if (metadata_data.shm_fd >= 0) {
@@ -676,7 +538,7 @@ int send_app_msgs(int sock, const char *outputpath,
        memset(&lum, 0, sizeof(lum));
        lum.handle = session_handle;
        lum.cmd = LTTNG_UST_RELEASE;
-       ret = send_app_cmd(sock, &lum, &lur);
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
 
@@ -915,7 +777,7 @@ int main(int argc, const char **argv)
                         DEFAULT_HOME_APPS_UNIX_SOCK, home_dir);
        }
 
-       ret = lttcomm_create_unix_sock(apps_sock_path);
+       ret = ustcomm_create_unix_sock(apps_sock_path);
        if (ret < 0) {
                perror("create error");
                return ret;
@@ -933,7 +795,7 @@ int main(int argc, const char **argv)
                }
                umask(old_umask);
        }
-       ret = lttcomm_listen_unix_sock(apps_socket);
+       ret = ustcomm_listen_unix_sock(apps_socket);
        if (ret < 0) {
                perror("listen error");
                return ret;
@@ -964,7 +826,7 @@ int main(int argc, const char **argv)
                        break;
 
                printf("Accepting application registration\n");
-               sock = lttcomm_accept_unix_sock(apps_socket);
+               sock = ustcomm_accept_unix_sock(apps_socket);
                if (sock < 0) {
                        perror("accept error");
                        goto end;
@@ -974,9 +836,9 @@ int main(int argc, const char **argv)
                 * Basic recv here to handle the very simple data
                 * that the libust send to register (reg_msg).
                 */
-               len = lttcomm_recv_unix_sock(sock, &reg_msg, sizeof(reg_msg));
+               len = ustcomm_recv_unix_sock(sock, &reg_msg, sizeof(reg_msg));
                if (len < 0 || len != sizeof(reg_msg)) {
-                       perror("lttcomm_recv_unix_sock");
+                       perror("ustcomm_recv_unix_sock");
                        continue;
                }
                memcpy(bufname, reg_msg.name, 16);
This page took 0.031276 seconds and 4 git commands to generate.