Send extended channel payload to client
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index c7665922f4f014f5b5dd07c6ffae69d6e6887e73..157d9a4335af5b5d52b3fcc7be942b4f2d77719a 100644 (file)
@@ -1694,10 +1694,15 @@ int lttng_list_channels(struct lttng_handle *handle,
                struct lttng_channel **channels)
 {
        int ret;
+       size_t channel_count, i;
+       const size_t channel_size = sizeof(struct lttng_channel) +
+                       sizeof(struct lttcomm_channel_extended);
        struct lttcomm_session_msg lsm;
+       void *extended_at;
 
        if (handle == NULL) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
@@ -1709,10 +1714,30 @@ int lttng_list_channels(struct lttng_handle *handle,
 
        ret = lttng_ctl_ask_sessiond(&lsm, (void**) channels);
        if (ret < 0) {
-               return ret;
+               goto end;
+       }
+
+       if (ret % channel_size) {
+               ret = -LTTNG_ERR_UNK;
+               free(*channels);
+               *channels = NULL;
+               goto end;
+       }
+       channel_count = (size_t) ret / channel_size;
+
+       /* Set extended info pointers */
+       extended_at = ((void *) *channels) +
+                       channel_count * sizeof(struct lttng_channel);
+       for (i = 0; i < channel_count; i++) {
+               struct lttng_channel *chan = &(*channels)[i];
+
+               chan->attr.extended.ptr = extended_at;
+               extended_at += sizeof(struct lttcomm_channel_extended);
        }
 
-       return ret / sizeof(struct lttng_channel);
+       ret = (int) channel_count;
+end:
+       return ret;
 }
 
 /*
@@ -1974,6 +1999,58 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain,
        }
 }
 
+int lttng_channel_get_discarded_event_count(struct lttng_channel *channel,
+               uint64_t *discarded_events)
+{
+       int ret = 0;
+       struct lttcomm_channel_extended *chan_ext;
+
+       if (!channel || !discarded_events) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       chan_ext = channel->attr.extended.ptr;
+       if (!chan_ext) {
+               /*
+                * This can happen since the lttng_channel structure is
+                * used for other tasks where this pointer is never set.
+                */
+               *discarded_events = 0;
+               goto end;
+       }
+
+       *discarded_events = chan_ext->discarded_events;
+end:
+       return ret;
+}
+
+int lttng_channel_get_lost_packet_count(struct lttng_channel *channel,
+               uint64_t *lost_packets)
+{
+       int ret = 0;
+       struct lttcomm_channel_extended *chan_ext;
+
+       if (!channel || !lost_packets) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       chan_ext = channel->attr.extended.ptr;
+       if (!chan_ext) {
+               /*
+                * This can happen since the lttng_channel structure is
+                * used for other tasks where this pointer is never set.
+                */
+               *lost_packets = 0;
+               goto end;
+       }
+
+       *lost_packets = chan_ext->lost_packets;
+end:
+       return ret;
+}
+
 /*
  * Check if session daemon is alive.
  *
This page took 0.024551 seconds and 5 git commands to generate.