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-matches-internal.h>
17 #include <lttng/condition/event-rule-matches.h>
18 #include <lttng/event-rule/event-rule-internal.h>
19 #include <lttng/condition/event-rule-matches-internal.h>
20 #include "condition-internal.h"
23 unsigned long lttng_condition_buffer_usage_hash(
24 const struct lttng_condition
*_condition
)
27 unsigned long condition_type
;
28 struct lttng_condition_buffer_usage
*condition
;
30 condition
= container_of(_condition
,
31 struct lttng_condition_buffer_usage
, parent
);
33 condition_type
= (unsigned long) condition
->parent
.type
;
34 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
35 if (condition
->session_name
) {
36 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
38 if (condition
->channel_name
) {
39 hash
^= hash_key_str(condition
->channel_name
, lttng_ht_seed
);
41 if (condition
->domain
.set
) {
42 hash
^= hash_key_ulong(
43 (void *) condition
->domain
.type
,
46 if (condition
->threshold_ratio
.set
) {
49 val
= condition
->threshold_ratio
.value
* (double) UINT32_MAX
;
50 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
51 } else if (condition
->threshold_bytes
.set
) {
54 val
= condition
->threshold_bytes
.value
;
55 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
61 unsigned long lttng_condition_session_consumed_size_hash(
62 const struct lttng_condition
*_condition
)
65 unsigned long condition_type
=
66 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
;
67 struct lttng_condition_session_consumed_size
*condition
;
70 condition
= container_of(_condition
,
71 struct lttng_condition_session_consumed_size
, parent
);
73 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
74 if (condition
->session_name
) {
75 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
77 val
= condition
->consumed_threshold_bytes
.value
;
78 hash
^= hash_key_u64(&val
, lttng_ht_seed
);
83 unsigned long lttng_condition_session_rotation_hash(
84 const struct lttng_condition
*_condition
)
86 unsigned long hash
, condition_type
;
87 struct lttng_condition_session_rotation
*condition
;
89 condition
= container_of(_condition
,
90 struct lttng_condition_session_rotation
, parent
);
91 condition_type
= (unsigned long) condition
->parent
.type
;
92 hash
= hash_key_ulong((void *) condition_type
, lttng_ht_seed
);
93 assert(condition
->session_name
);
94 hash
^= hash_key_str(condition
->session_name
, lttng_ht_seed
);
99 unsigned long lttng_condition_on_event_hash(
100 const struct lttng_condition
*condition
)
102 unsigned long hash
, condition_type
;
103 enum lttng_condition_status condition_status
;
104 const struct lttng_event_rule
*event_rule
;
106 condition_type
= (unsigned long) condition
->type
;
107 condition_status
= lttng_condition_on_event_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_ON_EVENT
:
132 return lttng_condition_on_event_hash(condition
);
134 //ERR("[notification-thread] Unexpected condition type caught");
140 struct lttng_condition
*lttng_condition_copy(const struct lttng_condition
*condition
)
143 struct lttng_payload copy_buffer
;
144 struct lttng_condition
*copy
= NULL
;
146 lttng_payload_init(©_buffer
);
148 ret
= lttng_condition_serialize(condition
, ©_buffer
);
154 struct lttng_payload_view view
=
155 lttng_payload_view_from_payload(
156 ©_buffer
, 0, -1);
158 ret
= lttng_condition_create_from_payload(
167 lttng_payload_reset(©_buffer
);