Commit | Line | Data |
---|---|---|
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 | ||
21 | static | |
22 | unsigned 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 | ||
59 | static | |
60 | unsigned 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 | ||
81 | static | |
82 | unsigned 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 | ||
97 | static | |
98 | unsigned long lttng_condition_event_rule_hash( | |
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; | |
106 | ||
107 | condition_status = lttng_condition_event_rule_get_rule(condition, | |
108 | &event_rule); | |
109 | assert(condition_status == LTTNG_CONDITION_STATUS_OK); | |
110 | ||
111 | hash = hash_key_ulong((void *) condition_type, lttng_ht_seed); | |
112 | return hash ^ lttng_event_rule_hash(event_rule); | |
113 | } | |
114 | ||
115 | /* | |
116 | * The lttng_condition hashing code is kept in this file (rather than | |
117 | * condition.c) since it makes use of GPLv2 code (hashtable utils), which we | |
118 | * don't want to link in liblttng-ctl. | |
119 | */ | |
120 | unsigned long lttng_condition_hash(const struct lttng_condition *condition) | |
121 | { | |
122 | switch (condition->type) { | |
123 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: | |
124 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: | |
125 | return lttng_condition_buffer_usage_hash(condition); | |
126 | case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: | |
127 | return lttng_condition_session_consumed_size_hash(condition); | |
128 | case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: | |
129 | case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: | |
130 | return lttng_condition_session_rotation_hash(condition); | |
131 | case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT: | |
132 | return lttng_condition_event_rule_hash(condition); | |
133 | default: | |
134 | //ERR("[notification-thread] Unexpected condition type caught"); | |
135 | abort(); | |
136 | } | |
137 | } |