Commit | Line | Data |
---|---|---|
6e0be6cc JD |
1 | /* |
2 | * Copyright (C) 2017 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
6 | * as published by the Free Software Foundation. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
11 | * for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public License | |
14 | * along with this library; if not, write to the Free Software Foundation, | |
15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
18 | #ifndef LTTNG_ROTATE_H | |
19 | #define LTTNG_ROTATE_H | |
20 | ||
8cf2762e JD |
21 | #include <stdint.h> |
22 | ||
6e0be6cc JD |
23 | #ifdef __cplusplus |
24 | extern "C" { | |
25 | #endif | |
26 | ||
27 | /* | |
28 | * Return codes for lttng_rotate_session_get_output_path. | |
29 | */ | |
30 | enum lttng_rotate_status { | |
31 | /* | |
32 | * After starting a rotation. | |
33 | */ | |
34 | LTTNG_ROTATE_STARTED = 0, | |
35 | /* | |
36 | * When the rotation is complete. | |
37 | */ | |
38 | LTTNG_ROTATE_COMPLETED = 1, | |
39 | /* | |
40 | * If the handle does not match the last rotate command, we cannot | |
41 | * retrieve the path for the chunk. | |
42 | */ | |
43 | LTTNG_ROTATE_EXPIRED = 2, | |
4a478f45 JD |
44 | /* |
45 | * Nothing to rotate, it happens on the first rotation when tracing | |
46 | * only in user-space and no app was started. | |
47 | */ | |
48 | LTTNG_ROTATE_EMPTY = 3, | |
6e0be6cc JD |
49 | /* |
50 | * On error. | |
51 | */ | |
4a478f45 | 52 | LTTNG_ROTATE_ERROR = 4, |
6e0be6cc JD |
53 | }; |
54 | ||
55 | /* | |
56 | * Input parameter to the lttng_rotate_session command. | |
57 | * The lttng_rotate_session_attr object is opaque to the user. Use the helper | |
58 | * functions below to use it. | |
59 | */ | |
60 | struct lttng_rotate_session_attr; | |
61 | ||
62 | /* | |
63 | * Handle used to check the progress of a rotation. | |
64 | * This object is opaque to the user. Use the helper functions below to use it. | |
65 | */ | |
66 | struct lttng_rotate_session_handle; | |
67 | ||
68 | /* | |
69 | * lttng rotate session command inputs. | |
70 | */ | |
71 | /* | |
72 | * Return a newly allocated rotate session attribute object or NULL on error. | |
73 | */ | |
74 | struct lttng_rotate_session_attr *lttng_rotate_session_attr_create(void); | |
75 | ||
76 | /* | |
77 | * Free a given rotate ssession attribute object. | |
78 | */ | |
79 | void lttng_rotate_session_attr_destroy(struct lttng_rotate_session_attr *attr); | |
80 | ||
81 | /* | |
82 | * Set the name of the session to rotate. | |
83 | */ | |
84 | int lttng_rotate_session_attr_set_session_name( | |
85 | struct lttng_rotate_session_attr *attr, const char *session_name); | |
86 | ||
8cf2762e JD |
87 | /* |
88 | * Set the timer to periodically rotate the session. | |
89 | */ | |
90 | void lttng_rotate_session_attr_set_timer( | |
91 | struct lttng_rotate_session_attr *attr, uint64_t timer); | |
92 | ||
93 | /* | |
94 | * Set the size to rotate the session. | |
95 | */ | |
96 | void lttng_rotate_session_attr_set_size( | |
97 | struct lttng_rotate_session_attr *attr, uint64_t size); | |
98 | ||
6e0be6cc JD |
99 | /* |
100 | * lttng rotate session handle functions. | |
101 | */ | |
102 | /* | |
103 | * Get the status from a handle. | |
104 | */ | |
105 | enum lttng_rotate_status lttng_rotate_session_get_status( | |
106 | struct lttng_rotate_session_handle *rotate_handle); | |
107 | ||
108 | /* | |
109 | * If the rotation is complete, returns 0, allocate path and set | |
110 | * it to the path of the readable chunk, the caller is responsible to free it. | |
111 | * Otherwise return a negative value. | |
112 | */ | |
113 | int lttng_rotate_session_get_output_path( | |
114 | struct lttng_rotate_session_handle *rotate_handle, | |
115 | char **path); | |
116 | ||
117 | /* | |
118 | * Destroy a lttng_rotate_session handle allocated by lttng_rotate_session() | |
119 | */ | |
120 | void lttng_rotate_session_handle_destroy( | |
121 | struct lttng_rotate_session_handle *rotate_handle); | |
122 | ||
123 | /* | |
124 | * Rotate the output folder of the session | |
125 | * | |
126 | * On success, handle is allocated and can be used to monitor the progress | |
127 | * of the rotation with lttng_rotate_session_pending(). The handle must be freed | |
128 | * by the caller with lttng_rotate_session_handle_destroy(). | |
129 | * | |
130 | * Return 0 if the rotate action was successfully launched or a negative | |
131 | * LTTng error code on error. | |
132 | */ | |
133 | extern int lttng_rotate_session(struct lttng_rotate_session_attr *attr, | |
134 | struct lttng_rotate_session_handle **rotate_handle); | |
135 | ||
136 | /* | |
137 | * For a given session name, this call checks if a session rotation is still in | |
138 | * progress or has completed. | |
139 | * | |
140 | * Return 0 if the rotation is complete, in this case, the output path can be | |
141 | * fetched with lttng_rotate_session_get_output_path(). | |
142 | * Return 1 if the rotate is still pending. | |
143 | * Return a negative LTTng error code on error (readable with lttng_strerror). | |
144 | */ | |
145 | extern int lttng_rotate_session_pending( | |
146 | struct lttng_rotate_session_handle *rotate_handle); | |
147 | ||
8cf2762e JD |
148 | /* |
149 | * Configure a session to rotate periodically or based on the size written. | |
150 | */ | |
151 | extern int lttng_rotate_setup(struct lttng_rotate_session_attr *attr); | |
152 | ||
6e0be6cc JD |
153 | #ifdef __cplusplus |
154 | } | |
155 | #endif | |
156 | ||
157 | #endif /* LTTNG_ROTATE_H */ |