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