SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / src / bin / lttng-sessiond / agent.h
CommitLineData
022d91ba 1/*
ab5be9fa
MJ
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
022d91ba 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
022d91ba 6 *
022d91ba
DG
7 */
8
9#ifndef LTTNG_SESSIOND_AGENT_H
10#define LTTNG_SESSIOND_AGENT_H
11
022d91ba
DG
12#include <inttypes.h>
13
14#include <common/hashtable/hashtable.h>
15#include <lttng/lttng.h>
16
9474416f 17/* Agent protocol version that is verified during the agent registration. */
a0ba721c 18#define AGENT_MAJOR_VERSION 2
9474416f
DG
19#define AGENT_MINOR_VERSION 0
20
022d91ba
DG
21/*
22 * Hash table that contains the agent app created upon registration indexed by
7c1d2758 23 * socket. Global to the session daemon.
022d91ba 24 */
7c1d2758 25extern struct lttng_ht *agent_apps_ht_by_sock;
022d91ba 26
2463b787
JR
27/*
28 * Hash table that contains the trigger agents by domain */
29extern struct lttng_ht *trigger_agents_ht_by_domain;
30
022d91ba
DG
31struct agent_ht_key {
32 const char *name;
2106efa0 33 int loglevel_value;
a9319624 34 enum lttng_loglevel_type loglevel_type;
2463b787 35 const char *filter_expression;
022d91ba
DG
36};
37
38/*
39 * Registration message payload from an agent application. The PID is used to
40 * find back the corresponding UST app object so both socket can be linked.
41 */
42struct agent_register_msg {
fefd409b
DG
43 /* This maps to a lttng_domain_type. */
44 uint32_t domain;
022d91ba 45 uint32_t pid;
9474416f
DG
46 uint32_t major_version;
47 uint32_t minor_version;
022d91ba
DG
48};
49
50/*
51 * Agent application object created after a successful registration. This
52 * object is linked to its associated UST app by their PID through hash table
53 * lookups.
54 */
55struct agent_app {
56 /*
d53e2992 57 * PID sent during registration of an agent application.
022d91ba
DG
58 */
59 pid_t pid;
60
fefd409b
DG
61 /* Domain of the application. */
62 enum lttng_domain_type domain;
63
022d91ba
DG
64 /*
65 * AGENT TCP socket that was created upon registration.
66 */
67 struct lttcomm_sock *sock;
68
69 /* Initialized with the AGENT sock value. */
70 struct lttng_ht_node_ulong node;
71};
72
73/*
74 * Agent event representation.
75 */
76struct agent_event {
77 /* Name of the event. */
78 char name[LTTNG_SYMBOL_NAME_LEN];
2106efa0 79 int loglevel_value;
022d91ba
DG
80 enum lttng_loglevel_type loglevel_type;
81
82 /*
83 * Tells if the event is enabled or not on the agent.
84 */
85 unsigned int enabled:1;
86
87 /* Hash table node of the agent domain object. */
88 struct lttng_ht_node_str node;
89
51755dc8 90 /* Filter associated with the event. NULL if none. */
2463b787 91 struct lttng_bytecode *filter;
51755dc8
JG
92 char *filter_expression;
93 struct lttng_event_exclusion *exclusion;
2463b787
JR
94
95 /*
96 * Multiple triggers and events can use this agent event.
97 * The event can only be disabled when the count is zero.
98 */
99 unsigned int user_refcount;
022d91ba
DG
100};
101
102/*
103 * Agent object containing events enabled/disabled for it.
104 */
105struct agent {
106 /*
107 * This indicates if that domain is being used meaning if at least one
108 * event has been at some point in time added to it. This is used so when
109 * listing domains for a session, we can tell or not if the agent is
110 * actually enabled.
111 */
112 unsigned int being_used:1;
fefd409b
DG
113
114 /* What domain this agent is. */
115 enum lttng_domain_type domain;
116
022d91ba
DG
117 /* Contains event indexed by name. */
118 struct lttng_ht *events;
fefd409b 119
bdf64013
JG
120 /* Application context list (struct agent_app_ctx). */
121 struct cds_list_head app_ctx_list;
122
fefd409b
DG
123 /* Node used for the hash table indexed by domain type. */
124 struct lttng_ht_node_u64 node;
022d91ba
DG
125};
126
6a4e4039
JG
127/* Allocate agent apps hash table */
128int agent_app_ht_alloc(void);
129/* Clean-up agent apps hash table */
130void agent_app_ht_clean(void);
022d91ba
DG
131
132/* Initialize an already allocated agent domain. */
133int agent_init(struct agent *agt);
fefd409b 134struct agent *agent_create(enum lttng_domain_type domain);
022d91ba 135void agent_destroy(struct agent *agt);
fefd409b 136void agent_add(struct agent *agt, struct lttng_ht *ht);
022d91ba
DG
137
138/* Agent event API. */
a9319624
PP
139struct agent_event *agent_create_event(const char *name,
140 enum lttng_loglevel_type loglevel_type, int loglevel_value,
2463b787 141 struct lttng_bytecode *filter,
51755dc8 142 char *filter_expression);
022d91ba
DG
143void agent_add_event(struct agent_event *event, struct agent *agt);
144
a9319624 145struct agent_event *agent_find_event(const char *name,
2463b787
JR
146 enum lttng_loglevel_type loglevel_type,
147 int loglevel_value,
148 const char *filter_expression,
149 struct agent *agt);
e261a6cc
PP
150void agent_find_events_by_name(const char *name, struct agent *agt,
151 struct lttng_ht_iter* iter);
152void agent_event_next_duplicate(const char *name,
153 struct agent *agt, struct lttng_ht_iter* iter);
022d91ba
DG
154void agent_delete_event(struct agent_event *event, struct agent *agt);
155void agent_destroy_event(struct agent_event *event);
156
bdf64013 157/* Agent context API.*/
df4f5a87 158int agent_enable_context(const struct lttng_event_context *ctx,
bdf64013 159 enum lttng_domain_type domain);
df4f5a87
JG
160int agent_add_context(const struct lttng_event_context *ctx,
161 struct agent *agt);
bdf64013 162
022d91ba 163/* Agent app API. */
fefd409b
DG
164struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
165 struct lttcomm_sock *sock);
022d91ba
DG
166void agent_add_app(struct agent_app *app);
167void agent_delete_app(struct agent_app *app);
168struct agent_app *agent_find_app_by_sock(int sock);
169void agent_destroy_app(struct agent_app *app);
6a4e4039 170void agent_destroy_app_by_sock(int sock);
022d91ba
DG
171int agent_send_registration_done(struct agent_app *app);
172
173/* Agent action API */
fefd409b
DG
174int agent_enable_event(struct agent_event *event,
175 enum lttng_domain_type domain);
176int agent_disable_event(struct agent_event *event,
177 enum lttng_domain_type domain);
733c9165 178void agent_update(const struct agent *agt, const struct agent_app *app);
f60140a1
DG
179int agent_list_events(struct lttng_event **events,
180 enum lttng_domain_type domain);
022d91ba 181
2463b787
JR
182struct agent_event *agent_find_event_by_trigger(
183 const struct lttng_trigger *trigger, struct agent *agt);
184
185/* todo: find a better place for this */
186struct agent *trigger_find_agent(enum lttng_domain_type domain_type);
187void trigger_agent_ht_clean(void);
188int trigger_agent_ht_alloc(void);
189
022d91ba 190#endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.096343 seconds and 5 git commands to generate.