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 <lttng/condition/event-rule.h>
18 #include <lttng/event-rule/event-rule-internal.h>
19 #include "condition-internal.h"
22 unsigned long lttng_condition_buffer_usage_hash(
23 const struct lttng_condition
*_condition
)
26 unsigned long condition_type
;
27 struct lttng_condition_buffer_usage
*condition
;
29 condition
= container_of(_condition
,
30 struct lttng_condition_buffer_usage
, parent
);
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
);
37 if (condition
->channel_name
) {
38 hash
^= hash_key_str(condition
->channel_name
, lttng_ht_seed
);
40 if (condition
->domain
.set
) {
41 hash
^= hash_key_ulong(
42 (void *) condition
->domain
.type
,
45 if (condition
->threshold_ratio
.set
) {
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
) {
53 val
= condition
->threshold_bytes
.value
;
54 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
60 unsigned long lttng_condition_session_consumed_size_hash(
61 const struct lttng_condition
*_condition
)
64 unsigned long condition_type
=
65 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
;
66 struct lttng_condition_session_consumed_size
*condition
;
69 condition
= container_of(_condition
,
70 struct lttng_condition_session_consumed_size
, parent
);
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
);
76 val
= condition
->consumed_threshold_bytes
.value
;
77 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
82 unsigned long lttng_condition_session_rotation_hash(
83 const struct lttng_condition
*_condition
)
85 unsigned long hash
, condition_type
;
86 struct lttng_condition_session_rotation
*condition
;
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
);
98 unsigned long lttng_condition_event_rule_hash(
99 const struct lttng_condition
*condition
)
101 unsigned long hash
, condition_type
;
102 enum lttng_condition_status condition_status
;
103 const struct lttng_event_rule
*event_rule
;
105 condition_type
= (unsigned long) condition
->type
;
107 condition_status
= lttng_condition_event_rule_get_rule(condition
,
109 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
111 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
112 return hash
^ lttng_event_rule_hash(event_rule
);
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.
120 unsigned long lttng_condition_hash(const struct lttng_condition
*condition
)
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
);
134 //ERR("[notification-thread] Unexpected condition type caught");