2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef LTTNG_SESSIOND_AGENT_H
20 #define LTTNG_SESSIOND_AGENT_H
24 #include <common/hashtable/hashtable.h>
25 #include <lttng/lttng.h>
27 /* Agent protocol version that is verified during the agent registration. */
28 #define AGENT_MAJOR_VERSION 2
29 #define AGENT_MINOR_VERSION 0
32 * Hash table that contains the agent app created upon registration indexed by
33 * socket. Global to the session daemon.
35 extern struct lttng_ht
*agent_apps_ht_by_sock
;
40 enum lttng_loglevel_type loglevel_type
;
41 char *filter_expression
;
45 * Registration message payload from an agent application. The PID is used to
46 * find back the corresponding UST app object so both socket can be linked.
48 struct agent_register_msg
{
49 /* This maps to a lttng_domain_type. */
52 uint32_t major_version
;
53 uint32_t minor_version
;
57 * Agent application object created after a successful registration. This
58 * object is linked to its associated UST app by their PID through hash table
63 * PID sent during registration of an agent application.
67 /* Domain of the application. */
68 enum lttng_domain_type domain
;
71 * AGENT TCP socket that was created upon registration.
73 struct lttcomm_sock
*sock
;
75 /* Initialized with the AGENT sock value. */
76 struct lttng_ht_node_ulong node
;
80 * Agent event representation.
83 /* Name of the event. */
84 char name
[LTTNG_SYMBOL_NAME_LEN
];
86 enum lttng_loglevel_type loglevel_type
;
89 * Tells if the event is enabled or not on the agent.
91 unsigned int enabled
:1;
93 /* Hash table node of the agent domain object. */
94 struct lttng_ht_node_str node
;
96 /* Filter associated with the event. NULL if none. */
97 struct lttng_filter_bytecode
*filter
;
98 char *filter_expression
;
99 struct lttng_event_exclusion
*exclusion
;
103 * Agent object containing events enabled/disabled for it.
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
112 unsigned int being_used
:1;
114 /* What domain this agent is. */
115 enum lttng_domain_type domain
;
117 /* Contains event indexed by name. */
118 struct lttng_ht
*events
;
120 /* Application context list (struct agent_app_ctx). */
121 struct cds_list_head app_ctx_list
;
123 /* Node used for the hash table indexed by domain type. */
124 struct lttng_ht_node_u64 node
;
127 /* Allocate agent apps hash table */
128 int agent_app_ht_alloc(void);
129 /* Clean-up agent apps hash table */
130 void agent_app_ht_clean(void);
132 /* Initialize an already allocated agent domain. */
133 int agent_init(struct agent
*agt
);
134 struct agent
*agent_create(enum lttng_domain_type domain
);
135 void agent_destroy(struct agent
*agt
);
136 void agent_add(struct agent
*agt
, struct lttng_ht
*ht
);
138 /* Agent event API. */
139 struct agent_event
*agent_create_event(const char *name
,
140 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
141 struct lttng_filter_bytecode
*filter
,
142 char *filter_expression
);
143 void agent_add_event(struct agent_event
*event
, struct agent
*agt
);
145 struct agent_event
*agent_find_event(const char *name
,
146 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
147 char *filter_expression
, struct agent
*agt
);
148 void agent_find_events_by_name(const char *name
, struct agent
*agt
,
149 struct lttng_ht_iter
* iter
);
150 void agent_event_next_duplicate(const char *name
,
151 struct agent
*agt
, struct lttng_ht_iter
* iter
);
152 void agent_delete_event(struct agent_event
*event
, struct agent
*agt
);
153 void agent_destroy_event(struct agent_event
*event
);
155 /* Agent context API.*/
156 int agent_enable_context(struct lttng_event_context
*ctx
,
157 enum lttng_domain_type domain
);
158 int agent_add_context(struct lttng_event_context
*ctx
, struct agent
*agt
);
161 struct agent_app
*agent_create_app(pid_t pid
, enum lttng_domain_type domain
,
162 struct lttcomm_sock
*sock
);
163 void agent_add_app(struct agent_app
*app
);
164 void agent_delete_app(struct agent_app
*app
);
165 struct agent_app
*agent_find_app_by_sock(int sock
);
166 void agent_destroy_app(struct agent_app
*app
);
167 void agent_destroy_app_by_sock(int sock
);
168 int agent_send_registration_done(struct agent_app
*app
);
170 /* Agent action API */
171 int agent_enable_event(struct agent_event
*event
,
172 enum lttng_domain_type domain
);
173 int agent_disable_event(struct agent_event
*event
,
174 enum lttng_domain_type domain
);
175 void agent_update(struct agent
*agt
, int sock
);
176 int agent_list_events(struct lttng_event
**events
,
177 enum lttng_domain_type domain
);
179 #endif /* LTTNG_SESSIOND_AGENT_H */