Rename lttng_condition_event_rule to lttng_condition_on_event
[lttng-tools.git] / src / bin / lttng-sessiond / condition-internal.c
CommitLineData
e98a976a
FD
1/*
2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#include <common/hashtable/utils.h>
9#include <common/hashtable/hashtable.h>
10
11#include <lttng/condition/condition.h>
12#include <lttng/condition/condition-internal.h>
13#include <lttng/condition/buffer-usage-internal.h>
14#include <lttng/condition/session-consumed-size-internal.h>
15#include <lttng/condition/session-rotation-internal.h>
16#include <lttng/condition/event-rule-internal.h>
17#include <lttng/condition/event-rule.h>
18#include <lttng/event-rule/event-rule-internal.h>
19#include "condition-internal.h"
20
21static
22unsigned long lttng_condition_buffer_usage_hash(
23 const struct lttng_condition *_condition)
24{
25 unsigned long hash;
26 unsigned long condition_type;
27 struct lttng_condition_buffer_usage *condition;
28
29 condition = container_of(_condition,
30 struct lttng_condition_buffer_usage, parent);
31
32 condition_type = (unsigned long) condition->parent.type;
33 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
34 if (condition->session_name) {
35 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
36 }
37 if (condition->channel_name) {
38 hash ^= hash_key_str(condition->channel_name, lttng_ht_seed);
39 }
40 if (condition->domain.set) {
41 hash ^= hash_key_ulong(
42 (void *) condition->domain.type,
43 lttng_ht_seed);
44 }
45 if (condition->threshold_ratio.set) {
46 uint64_t val;
47
48 val = condition->threshold_ratio.value * (double) UINT32_MAX;
49 hash ^= hash_key_u64(&val, lttng_ht_seed);
50 } else if (condition->threshold_bytes.set) {
51 uint64_t val;
52
53 val = condition->threshold_bytes.value;
54 hash ^= hash_key_u64(&val, lttng_ht_seed);
55 }
56 return hash;
57}
58
59static
60unsigned long lttng_condition_session_consumed_size_hash(
61 const struct lttng_condition *_condition)
62{
63 unsigned long hash;
64 unsigned long condition_type =
65 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE;
66 struct lttng_condition_session_consumed_size *condition;
67 uint64_t val;
68
69 condition = container_of(_condition,
70 struct lttng_condition_session_consumed_size, parent);
71
72 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
73 if (condition->session_name) {
74 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
75 }
76 val = condition->consumed_threshold_bytes.value;
77 hash ^= hash_key_u64(&val, lttng_ht_seed);
78 return hash;
79}
80
81static
82unsigned long lttng_condition_session_rotation_hash(
83 const struct lttng_condition *_condition)
84{
85 unsigned long hash, condition_type;
86 struct lttng_condition_session_rotation *condition;
87
88 condition = container_of(_condition,
89 struct lttng_condition_session_rotation, parent);
90 condition_type = (unsigned long) condition->parent.type;
91 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
92 assert(condition->session_name);
93 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
94 return hash;
95}
96
97static
d602bd6a 98unsigned long lttng_condition_on_event_hash(
e98a976a
FD
99 const struct lttng_condition *condition)
100{
101 unsigned long hash, condition_type;
102 enum lttng_condition_status condition_status;
103 const struct lttng_event_rule *event_rule;
104
105 condition_type = (unsigned long) condition->type;
d602bd6a 106 condition_status = lttng_condition_on_event_get_rule(condition,
e98a976a
FD
107 &event_rule);
108 assert(condition_status == LTTNG_CONDITION_STATUS_OK);
109
110 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
111 return hash ^ lttng_event_rule_hash(event_rule);
112}
113
114/*
115 * The lttng_condition hashing code is kept in this file (rather than
116 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
117 * don't want to link in liblttng-ctl.
118 */
119unsigned long lttng_condition_hash(const struct lttng_condition *condition)
120{
121 switch (condition->type) {
122 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
123 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
124 return lttng_condition_buffer_usage_hash(condition);
125 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
126 return lttng_condition_session_consumed_size_hash(condition);
127 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
128 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
129 return lttng_condition_session_rotation_hash(condition);
d602bd6a
JR
130 case LTTNG_CONDITION_TYPE_ON_EVENT:
131 return lttng_condition_on_event_hash(condition);
e98a976a
FD
132 default:
133 //ERR("[notification-thread] Unexpected condition type caught");
134 abort();
135 }
136}
This page took 0.027678 seconds and 4 git commands to generate.