Add counter case in lttng_kernel_event_id_available
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 2 Feb 2022 20:37:03 +0000 (15:37 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 15 Jul 2024 20:58:48 +0000 (16:58 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I1967ddd37d677806558a41138f32566ce19bae21

src/lttng-events.c

index 506534306a3e56566fccba364dafee0b348f7a55..3f15965c3ba60e07cf20570ed81dbd50b2c45ce8 100644 (file)
@@ -44,6 +44,7 @@
 #include <lttng/endian.h>
 #include <lttng/string-utils.h>
 #include <lttng/utils.h>
+#include <counter/counter.h>
 #include <ringbuffer/backend.h>
 #include <ringbuffer/frontend.h>
 
@@ -895,7 +896,42 @@ bool lttng_kernel_event_id_available(struct lttng_event_enabler_common *event_en
                        return false;
                }
        }
-       //TODO: LTTNG_EVENT_ENABLER_TYPE_COUNTER
+       case LTTNG_EVENT_ENABLER_TYPE_COUNTER:
+       {
+               struct lttng_event_counter_enabler *event_counter_enabler =
+                       container_of(event_enabler, struct lttng_event_counter_enabler, parent.parent);
+               struct lttng_kernel_channel_counter *chan = event_counter_enabler->chan;
+               struct lib_counter *counter = chan->priv->counter;
+               size_t nr_dimensions, max_nr_elem;
+
+               if (lttng_counter_get_nr_dimensions(&counter->config, counter, &nr_dimensions))
+                       return false;
+               WARN_ON_ONCE(nr_dimensions != 1);
+               if (nr_dimensions != 1)
+                       return false;
+               if (lttng_counter_get_max_nr_elem(&counter->config, counter, &max_nr_elem))
+                       return false;
+               switch (itype) {
+               case LTTNG_KERNEL_ABI_TRACEPOINT:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_KPROBE:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_SYSCALL:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_UPROBE:
+                       if (chan->priv->free_index >= max_nr_elem)
+                               return false;
+                       return true;
+               case LTTNG_KERNEL_ABI_KRETPROBE:
+                       /* kretprobes require 2 event IDs. */
+                       if (chan->priv->free_index + 1 >= max_nr_elem)
+                               return false;
+                       return true;
+               default:
+                       WARN_ON_ONCE(1);
+                       return false;
+               }
+       }
        case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
                return true;
        default:
This page took 0.027618 seconds and 4 git commands to generate.