2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include <common/hashtable/utils.h>
9 #include <common/hashtable/hashtable.h>
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 "condition-internal.h"
20 unsigned long lttng_condition_buffer_usage_hash(
21 const struct lttng_condition
*_condition
)
24 unsigned long condition_type
;
25 struct lttng_condition_buffer_usage
*condition
;
27 condition
= container_of(_condition
,
28 struct lttng_condition_buffer_usage
, parent
);
30 condition_type
= (unsigned long) condition
->parent
.type
;
31 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
32 if (condition
->session_name
) {
33 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
35 if (condition
->channel_name
) {
36 hash
^= hash_key_str(condition
->channel_name
, lttng_ht_seed
);
38 if (condition
->domain
.set
) {
39 hash
^= hash_key_ulong(
40 (void *) condition
->domain
.type
,
43 if (condition
->threshold_ratio
.set
) {
46 val
= condition
->threshold_ratio
.value
* (double) UINT32_MAX
;
47 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
48 } else if (condition
->threshold_bytes
.set
) {
51 val
= condition
->threshold_bytes
.value
;
52 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
58 unsigned long lttng_condition_session_consumed_size_hash(
59 const struct lttng_condition
*_condition
)
62 unsigned long condition_type
=
63 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
;
64 struct lttng_condition_session_consumed_size
*condition
;
67 condition
= container_of(_condition
,
68 struct lttng_condition_session_consumed_size
, parent
);
70 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
71 if (condition
->session_name
) {
72 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
74 val
= condition
->consumed_threshold_bytes
.value
;
75 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
80 unsigned long lttng_condition_session_rotation_hash(
81 const struct lttng_condition
*_condition
)
83 unsigned long hash
, condition_type
;
84 struct lttng_condition_session_rotation
*condition
;
86 condition
= container_of(_condition
,
87 struct lttng_condition_session_rotation
, parent
);
88 condition_type
= (unsigned long) condition
->parent
.type
;
89 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
90 assert(condition
->session_name
);
91 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
96 unsigned long lttng_condition_event_rule_hash(
97 const struct lttng_condition
*_condition
)
99 unsigned long hash
, condition_type
;
100 struct lttng_condition_event_rule
*condition
;
102 condition
= container_of(_condition
,
103 struct lttng_condition_event_rule
, parent
);
104 condition_type
= (unsigned long) condition
->parent
.type
;
105 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
107 /* TODO: further hasg using the event rule? on pattern maybe?*/
112 * The lttng_condition hashing code is kept in this file (rather than
113 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
114 * don't want to link in liblttng-ctl.
116 unsigned long lttng_condition_hash(const struct lttng_condition
*condition
)
118 switch (condition
->type
) {
119 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
120 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
121 return lttng_condition_buffer_usage_hash(condition
);
122 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
123 return lttng_condition_session_consumed_size_hash(condition
);
124 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
125 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
126 return lttng_condition_session_rotation_hash(condition
);
127 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT
:
128 return lttng_condition_event_rule_hash(condition
);
130 //ERR("[notification-thread] Unexpected condition type caught");