2 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRACKER_H
9 #define LTTNG_TRACKER_H
11 #include <lttng/constant.h>
12 #include <lttng/session.h>
18 enum lttng_tracker_type
{
19 LTTNG_TRACKER_PID
= 0,
20 LTTNG_TRACKER_VPID
= 1,
21 LTTNG_TRACKER_UID
= 2,
22 LTTNG_TRACKER_GID
= 3,
23 LTTNG_TRACKER_VUID
= 4,
24 LTTNG_TRACKER_VGID
= 5,
27 enum lttng_tracker_id_type
{
28 LTTNG_ID_UNKNOWN
= -1,
34 enum lttng_tracker_id_status
{
35 /* Invalid tracker id parameter. */
36 LTTNG_TRACKER_ID_STATUS_INVALID
= -1,
37 LTTNG_TRACKER_ID_STATUS_OK
= 0,
38 /* Tracker id parameter is unset. */
39 LTTNG_TRACKER_ID_STATUS_UNSET
= 1,
45 struct lttng_tracker_id
;
48 * A collection of tracker id.
50 struct lttng_tracker_ids
;
53 * Create a tracker id for the passed tracker type.
54 * Users must set the tracker id using the matching API call.
56 * On success, the caller is responsible for calling lttng_tracker_id_destroy.
57 * On error, return NULL.
59 extern struct lttng_tracker_id
*lttng_tracker_id_create(void);
62 * Configure the tracker id using the numerical representation of the resource
63 * to be tracked/untracked.
65 * If the tracker id was already configured, calling this function will replace
66 * the previous configuration and free memory as necessary.
68 * Returns LTTNG_TRACKER_ID_STATUS_OK on success,
69 * LTTNG_TRACKER_ID_STATUS_INVALID is the passed parameter is invalid.
71 extern enum lttng_tracker_id_status
lttng_tracker_id_set_value(
72 struct lttng_tracker_id
*id
, int value
);
75 * Configure the tracker id using the string representation of the resource to
76 * be tracked/untracked.
78 * If the tracker id was already configured, calling this function will replace
79 * the previous configuration and free memory as necessary.
81 * Returns LTTNG_TRACKER_ID_STATUS_OK on success,
82 * LTTNG_TRACKER_ID_STATUS_INVALID if the passed parameter is invalid.
84 extern enum lttng_tracker_id_status
lttng_tracker_id_set_string(
85 struct lttng_tracker_id
*id
, const char *value
);
88 * Configure the tracker id to track/untrack all resources for the tracker type.
90 * If the tracker id was already configured, calling this function will replace
91 * the previous configuration and free memory as necessary.
93 * Returns LTTNG_TRACKER_ID_STATUS_OK on success,
94 * LTTNG_TRACKER_ID_STATUS_INVALID if the passed parameter is invalid.
96 extern enum lttng_tracker_id_status
lttng_tracker_id_set_all(
97 struct lttng_tracker_id
*id
);
100 * Destroy a tracker id.
102 extern void lttng_tracker_id_destroy(struct lttng_tracker_id
*id
);
105 * Get the type of a tracker id.
107 extern enum lttng_tracker_id_type
lttng_tracker_id_get_type(
108 const struct lttng_tracker_id
*id
);
111 * Get the value of a tracker id.
113 * Returns LTTNG_TRACKER_ID_OK on success,
114 * LTTNG_TRACKER_ID_STATUS_INVALID when the tracker is not of type
116 * LTTNG_TRACKER_ID_STATUS_UNSET when the tracker is not set.
118 extern enum lttng_tracker_id_status
lttng_tracker_id_get_value(
119 const struct lttng_tracker_id
*id
, int *value
);
122 * Get the string representation of the tracker id.
124 * Returns LTTNG_TRACKER_ID_OK on success,
125 * LTTNG_TRACKER_ID_STATUS_INVALID when the tracker is not of type
127 * LTTNG_TRACKER_ID_STATUS_UNSET when the tracker is not set.
129 extern enum lttng_tracker_id_status
lttng_tracker_id_get_string(
130 const struct lttng_tracker_id
*id
, const char **value
);
133 * Add ID to session tracker.
135 * tracker_type is the type of tracker.
136 * id is the lttng_tracker_type to track.
138 * Returns 0 on success else a negative LTTng error code.
140 extern int lttng_track_id(struct lttng_handle
*handle
,
141 enum lttng_tracker_type tracker_type
,
142 const struct lttng_tracker_id
*id
);
145 * Remove ID from session tracker.
147 * tracker_type is the type of tracker.
148 * id is the lttng_tracker_type to untrack.
149 * Returns 0 on success else a negative LTTng error code.
151 extern int lttng_untrack_id(struct lttng_handle
*handle
,
152 enum lttng_tracker_type tracker_type
,
153 const struct lttng_tracker_id
*id
);
156 * List IDs of a tracker.
158 * On success, ids is allocated.
159 * The ids collection must be freed by the caller with lttng_destroy_ids().
161 * Returns 0 on success, else a negative LTTng error code.
163 extern int lttng_list_tracker_ids(struct lttng_handle
*handle
,
164 enum lttng_tracker_type tracker_type
,
165 struct lttng_tracker_ids
**ids
);
168 * Backward compatibility.
169 * Add PID to session tracker.
171 * A pid argument >= 0 adds the PID to the session tracker.
172 * A pid argument of -1 means "track all PIDs".
174 * Returns 0 on success else a negative LTTng error code.
176 extern int lttng_track_pid(struct lttng_handle
*handle
, int pid
);
179 * Backward compatibility.
180 * Remove PID from session tracker.
182 * A pid argument >= 0 removes the PID from the session tracker.
183 * A pid argument of -1 means "untrack all PIDs".
185 * Returns 0 on success else a negative LTTng error code.
187 extern int lttng_untrack_pid(struct lttng_handle
*handle
, int pid
);
190 * Backward compatibility
191 * List PIDs in the tracker.
193 * enabled is set to whether the PID tracker is enabled.
194 * pids is set to an allocated array of PIDs currently tracked. On
195 * success, pids must be freed by the caller.
196 * nr_pids is set to the number of entries contained by the pids array.
198 * Returns 0 on success, else a negative LTTng error code.
200 extern int lttng_list_tracker_pids(struct lttng_handle
*handle
,
206 * Get a tracker id from the list at a given index.
208 * Note that the list maintains the ownership of the returned tracker id.
209 * It must not be destroyed by the user, nor should it be held beyond the
210 * lifetime of the tracker id list.
212 * Returns a tracker id, or NULL on error.
214 extern const struct lttng_tracker_id
*lttng_tracker_ids_get_at_index(
215 const struct lttng_tracker_ids
*ids
, unsigned int index
);
218 * Get the number of tracker id in a tracker id list.
220 * Return LTTNG_TRACKER_ID_STATUS on sucess,
221 * LTTNG_TRACKER_ID_STATUS_INVALID when passed invalid parameters.
223 extern enum lttng_tracker_id_status
lttng_tracker_ids_get_count(
224 const struct lttng_tracker_ids
*ids
, unsigned int *count
);
227 * Destroy a tracker id list.
229 extern void lttng_tracker_ids_destroy(struct lttng_tracker_ids
*ids
);
235 #endif /* LTTNG_TRACKER_H */