sessiond: add loglevels_match()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 2 Sep 2015 15:31:35 +0000 (11:31 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 6 Sep 2015 20:42:22 +0000 (16:42 -0400)
UST and agent event loglevel matching algorithm is the same
so factor out this code into a common utility.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/agent.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/utils.c
src/bin/lttng-sessiond/utils.h

index 0b8bc0251ce2f8976de7a93a62b6ed8c194605e3..33559c89a9423ea13b322d90c5db9995269d9f21 100644 (file)
@@ -103,6 +103,7 @@ static int ht_match_event(struct cds_lfht_node *node,
 {
        struct agent_event *event;
        const struct agent_ht_key *key;
+       int ll_match;
 
        assert(node);
        assert(_key);
@@ -118,19 +119,11 @@ static int ht_match_event(struct cds_lfht_node *node,
        }
 
        /* Event loglevel value and type. */
-       if (event->loglevel_type == key->loglevel_type) {
-               /* Same loglevel type. */
-               if (key->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
-                       /*
-                        * Loglevel value must also match since the loglevel
-                        * type is not all.
-                        */
-                       if (event->loglevel_value != key->loglevel_value) {
-                               goto no_match;
-                       }
-               }
-       } else {
-               /* Loglevel type is different: no match. */
+       ll_match = loglevels_match(event->loglevel_type,
+               event->loglevel_value, key->loglevel_type,
+               key->loglevel_value, LTTNG_EVENT_LOGLEVEL_ALL);
+
+       if (!ll_match) {
                goto no_match;
        }
 
index b7ef806af1a5a218cdfa7ccc2f1b4c6e04691f98..1adda7e82b19b673f93352a921d843e1a5951e68 100644 (file)
@@ -72,6 +72,7 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
        struct ltt_ust_event *event;
        const struct ltt_ust_ht_key *key;
        int ev_loglevel_value;
+       int ll_match;
 
        assert(node);
        assert(_key);
@@ -88,19 +89,11 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
        }
 
        /* Event loglevel value and type. */
-       if (event->attr.loglevel_type == key->loglevel_type) {
-               /* Same loglevel type. */
-               if (key->loglevel_type != LTTNG_UST_LOGLEVEL_ALL) {
-                       /*
-                        * Loglevel value must also match since the loglevel
-                        * type is not all.
-                        */
-                       if (ev_loglevel_value != key->loglevel_value) {
-                               goto no_match;
-                       }
-               }
-       } else {
-               /* Loglevel type is different: no match. */
+       ll_match = loglevels_match(event->attr.loglevel_type,
+               ev_loglevel_value, key->loglevel_type,
+               key->loglevel_value, LTTNG_UST_LOGLEVEL_ALL);
+
+       if (!ll_match) {
                goto no_match;
        }
 
index fef31803f181b9c5aaebeec9b9e6dd025d30247f..f5f1cff638810207d17086f88a9af6b89fea768d 100644 (file)
@@ -72,3 +72,27 @@ void ht_cleanup_push(struct lttng_ht *ht)
 error:
        assert(!ret);
 }
+
+int loglevels_match(int a_loglevel_type, int a_loglevel_value,
+       int b_loglevel_type, int b_loglevel_value, int loglevel_all_type)
+{
+       int match = 1;
+
+       if (a_loglevel_type == b_loglevel_type) {
+               /* Same loglevel type. */
+               if (b_loglevel_type != loglevel_all_type) {
+                       /*
+                        * Loglevel value must also match since the loglevel
+                        * type is not all.
+                        */
+                       if (a_loglevel_value != b_loglevel_value) {
+                               match = 0;
+                       }
+               }
+       } else {
+               /* Loglevel type is different: no match. */
+               match = 0;
+       }
+
+       return match;
+}
index 7c06d5b03233e03320c6ab185fac0b495c44e579..2be72c20fc999e646a371b8c15fa3cc83ee51bb9 100644 (file)
@@ -23,5 +23,7 @@ struct lttng_ht;
 const char *get_home_dir(void);
 int notify_thread_pipe(int wpipe);
 void ht_cleanup_push(struct lttng_ht *ht);
+int loglevels_match(int a_loglevel_type, int a_loglevel_value,
+       int b_loglevel_type, int b_loglevel_value, int loglevel_all_type);
 
 #endif /* _LTT_UTILS_H */
This page took 0.027633 seconds and 4 git commands to generate.