Fix: Initialize events discarded and packet lost counters to zero
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 331a9d67160d4fee424e4ddb892e1f7057f8983b..987bb0e1cf3209eba995e68a0670d3efae5c4b51 100644 (file)
@@ -392,12 +392,22 @@ void save_per_pid_lost_discarded_counters(struct ust_app_channel *ua_chan)
 
        rcu_read_lock();
        session = session_find_by_id(ua_chan->session->tracing_id);
-       if (!session) {
-               ERR("Missing LTT session to get discarded events");
-               goto end;
-       }
-       if (!session->ust_session) {
-               ERR("Missing UST session to get discarded events");
+       if (!session || !session->ust_session) {
+               /*
+                * Not finding the session is not an error because there are
+                * multiple ways the channels can be torn down.
+                *
+                * 1) The session daemon can initiate the destruction of the
+                *    ust app session after receiving a destroy command or
+                *    during its shutdown/teardown.
+                * 2) The application, since we are in per-pid tracing, is
+                *    unregistering and tearing down its ust app session.
+                *
+                * Both paths are protected by the session list lock which
+                * ensures that the accounting of lost packets and discarded
+                * events is done exactly once. The session is then unpublished
+                * from the session list, resulting in this condition.
+                */
                goto end;
        }
 
@@ -541,7 +551,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry,
        char *metadata_str = NULL;
        size_t len, offset, new_metadata_len_sent;
        ssize_t ret_val;
-       uint64_t metadata_key;
+       uint64_t metadata_key, metadata_version;
 
        assert(registry);
        assert(socket);
@@ -571,6 +581,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry,
        offset = registry->metadata_len_sent;
        len = registry->metadata_len - registry->metadata_len_sent;
        new_metadata_len_sent = registry->metadata_len;
+       metadata_version = registry->metadata_version;
        if (len == 0) {
                DBG3("No metadata to push for metadata key %" PRIu64,
                                registry->metadata_key);
@@ -607,7 +618,7 @@ push_data:
         * different bidirectionnal communication sockets.
         */
        ret = consumer_push_metadata(socket, metadata_key,
-                       metadata_str, len, offset);
+                       metadata_str, len, offset, metadata_version);
        pthread_mutex_lock(&registry->lock);
        if (ret < 0) {
                /*
@@ -5934,9 +5945,11 @@ int ust_app_uid_get_channel_runtime_stats(uint64_t ust_session_id,
        if (overwrite) {
                ret = consumer_get_lost_packets(ust_session_id,
                                consumer_chan_key, consumer, lost);
+               *discarded = 0;
        } else {
                ret = consumer_get_discarded_events(ust_session_id,
                                consumer_chan_key, consumer, discarded);
+               *lost = 0;
        }
 
 end:
@@ -5979,10 +5992,12 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
                if (overwrite) {
                        ret = consumer_get_lost_packets(usess->id, ua_chan->key,
                                        consumer, lost);
+                       *discarded = 0;
                        goto end;
                } else {
                        ret = consumer_get_discarded_events(usess->id,
                                        ua_chan->key, consumer, discarded);
+                       *lost = 0;
                        goto end;
                }
        }
This page took 0.024728 seconds and 4 git commands to generate.