SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / src / bin / lttng-sessiond / condition-internal.c
... / ...
CommitLineData
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 "condition-internal.h"
18
19static
20unsigned long lttng_condition_buffer_usage_hash(
21 const struct lttng_condition *_condition)
22{
23 unsigned long hash;
24 unsigned long condition_type;
25 struct lttng_condition_buffer_usage *condition;
26
27 condition = container_of(_condition,
28 struct lttng_condition_buffer_usage, parent);
29
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);
34 }
35 if (condition->channel_name) {
36 hash ^= hash_key_str(condition->channel_name, lttng_ht_seed);
37 }
38 if (condition->domain.set) {
39 hash ^= hash_key_ulong(
40 (void *) condition->domain.type,
41 lttng_ht_seed);
42 }
43 if (condition->threshold_ratio.set) {
44 uint64_t val;
45
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) {
49 uint64_t val;
50
51 val = condition->threshold_bytes.value;
52 hash ^= hash_key_u64(&val, lttng_ht_seed);
53 }
54 return hash;
55}
56
57static
58unsigned long lttng_condition_session_consumed_size_hash(
59 const struct lttng_condition *_condition)
60{
61 unsigned long hash;
62 unsigned long condition_type =
63 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE;
64 struct lttng_condition_session_consumed_size *condition;
65 uint64_t val;
66
67 condition = container_of(_condition,
68 struct lttng_condition_session_consumed_size, parent);
69
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);
73 }
74 val = condition->consumed_threshold_bytes.value;
75 hash ^= hash_key_u64(&val, lttng_ht_seed);
76 return hash;
77}
78
79static
80unsigned long lttng_condition_session_rotation_hash(
81 const struct lttng_condition *_condition)
82{
83 unsigned long hash, condition_type;
84 struct lttng_condition_session_rotation *condition;
85
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);
92 return hash;
93}
94
95static
96unsigned long lttng_condition_event_rule_hash(
97 const struct lttng_condition *_condition)
98{
99 unsigned long hash, condition_type;
100 struct lttng_condition_event_rule *condition;
101
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);
106
107 /* TODO: further hasg using the event rule? on pattern maybe?*/
108 return hash;
109}
110
111/*
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.
115 */
116unsigned long lttng_condition_hash(const struct lttng_condition *condition)
117{
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);
129 default:
130 //ERR("[notification-thread] Unexpected condition type caught");
131 abort();
132 }
133}
This page took 0.02409 seconds and 5 git commands to generate.