Clean-up: apply suggested clang-tidy fixes
[lttng-tools.git] / src / bin / lttng-sessiond / agent.hpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9#ifndef LTTNG_SESSIOND_AGENT_H
10#define LTTNG_SESSIOND_AGENT_H
11
12#include <common/hashtable/hashtable.hpp>
13
14#include <lttng/lttng.h>
15
16#include <inttypes.h>
17
18/* Agent protocol version that is verified during the agent registration. */
19#define AGENT_MAJOR_VERSION 2
20#define AGENT_MINOR_VERSION 0
21
22/*
23 * Hash table that contains the agent app created upon registration indexed by
24 * socket. Global to the session daemon.
25 */
26extern struct lttng_ht *the_agent_apps_ht_by_sock;
27
28/*
29 * Hash table that contains the trigger agents by domain */
30extern struct lttng_ht *the_trigger_agents_ht_by_domain;
31
32struct agent_ht_key {
33 const char *name;
34 int loglevel_value;
35 enum lttng_loglevel_type loglevel_type;
36 const char *filter_expression;
37};
38
39/*
40 * Registration message payload from an agent application. The PID is used to
41 * find back the corresponding UST app object so both socket can be linked.
42 */
43struct agent_register_msg {
44 /* This maps to a lttng_domain_type. */
45 uint32_t domain;
46 uint32_t pid;
47 uint32_t major_version;
48 uint32_t minor_version;
49};
50
51/*
52 * Agent application object created after a successful registration. This
53 * object is linked to its associated UST app by their PID through hash table
54 * lookups.
55 */
56struct agent_app {
57 /*
58 * PID sent during registration of an agent application.
59 */
60 pid_t pid;
61
62 /* Domain of the application. */
63 enum lttng_domain_type domain;
64
65 /*
66 * AGENT TCP socket that was created upon registration.
67 */
68 struct lttcomm_sock *sock;
69
70 /* Initialized with the AGENT sock value. */
71 struct lttng_ht_node_ulong node;
72};
73
74/*
75 * Agent event representation.
76 * Accesses to this structure are protected by the session list lock.
77 */
78struct agent_event {
79 /* Name of the event. */
80 char name[LTTNG_SYMBOL_NAME_LEN];
81 int loglevel_value;
82 enum lttng_loglevel_type loglevel_type;
83
84 /*
85 * Tells if the event is enabled or not on the agent. While this can be
86 * implicitly tested as a boolean, it is in fact a reference count and
87 * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental
88 * comparisons to non-zero literals (e.g. '1').
89 *
90 * Multiple triggers and events can map to the same agent event as it
91 * is merely a "filter" in front of a user space tracer enabler.
92 *
93 * This count is updated to ensure an event is only disabled when all
94 * matching enablers are disabled.
95 */
96 unsigned int enabled_count;
97
98 /* Hash table node of the agent domain object. */
99 struct lttng_ht_node_str node;
100
101 /* Filter associated with the event. NULL if none. */
102 struct lttng_bytecode *filter;
103 char *filter_expression;
104 struct lttng_event_exclusion *exclusion;
105};
106
107#define AGENT_EVENT_IS_ENABLED(agent_event) (!!(agent_event)->enabled_count)
108
109/*
110 * Agent object containing events enabled/disabled for a given domain in a
111 * scope. The scope is typically a session, but can also be "global" in the
112 * context of event notifiers: see event_notifiers_find_agent().
113 */
114struct agent {
115 /*
116 * This indicates if that domain is being used meaning if at least one
117 * event has been at some point in time added to it. This is used so when
118 * listing domains for a session, we can tell or not if the agent is
119 * actually enabled.
120 */
121 unsigned int being_used:1;
122
123 /* What domain this agent is. */
124 enum lttng_domain_type domain;
125
126 /* Contains event indexed by name. */
127 struct lttng_ht *events;
128
129 /* Application context list (struct agent_app_ctx). */
130 struct cds_list_head app_ctx_list;
131
132 /* Node used for the hash table indexed by domain type. */
133 struct lttng_ht_node_u64 node;
134};
135
136/* Allocate agent apps hash table */
137int agent_app_ht_alloc();
138/* Clean-up agent apps hash table */
139void agent_app_ht_clean();
140
141/* Initialize an already allocated agent domain. */
142int agent_init(struct agent *agt);
143struct agent *agent_create(enum lttng_domain_type domain);
144void agent_destroy(struct agent *agt);
145void agent_add(struct agent *agt, struct lttng_ht *ht);
146
147/* Agent event API. */
148struct agent_event *agent_create_event(const char *name,
149 enum lttng_loglevel_type loglevel_type,
150 int loglevel_value,
151 struct lttng_bytecode *filter,
152 char *filter_expression);
153void agent_add_event(struct agent_event *event, struct agent *agt);
154
155struct agent_event *agent_find_event(const char *name,
156 enum lttng_loglevel_type loglevel_type,
157 int loglevel_value,
158 const char *filter_expression,
159 struct agent *agt);
160void agent_find_events_by_name(const char *name, struct agent *agt, struct lttng_ht_iter *iter);
161void agent_event_next_duplicate(const char *name, struct agent *agt, struct lttng_ht_iter *iter);
162void agent_delete_event(struct agent_event *event, struct agent *agt);
163void agent_destroy_event(struct agent_event *event);
164
165/* Agent context API.*/
166int agent_enable_context(const struct lttng_event_context *ctx, enum lttng_domain_type domain);
167int agent_add_context(const struct lttng_event_context *ctx, struct agent *agt);
168
169/* Agent app API. */
170struct agent_app *
171agent_create_app(pid_t pid, enum lttng_domain_type domain, struct lttcomm_sock *sock);
172void agent_add_app(struct agent_app *app);
173void agent_delete_app(struct agent_app *app);
174struct agent_app *agent_find_app_by_sock(int sock);
175void agent_destroy_app(struct agent_app *app);
176void agent_destroy_app_by_sock(int sock);
177int agent_send_registration_done(struct agent_app *app);
178
179/* Agent action API */
180int agent_enable_event(struct agent_event *event, enum lttng_domain_type domain);
181int agent_disable_event(struct agent_event *event, enum lttng_domain_type domain);
182void agent_update(const struct agent *agt, const struct agent_app *app);
183int agent_list_events(struct lttng_event **events, enum lttng_domain_type domain);
184
185struct agent_event *agent_find_event_by_trigger(const struct lttng_trigger *trigger,
186 struct agent *agt);
187
188/* Global event notifier per-domain agents. */
189struct agent *agent_find_by_event_notifier_domain(enum lttng_domain_type domain_type);
190void agent_by_event_notifier_domain_ht_destroy();
191int agent_by_event_notifier_domain_ht_create();
192
193#endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.022492 seconds and 4 git commands to generate.