2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <common/error.h>
25 #include <common/utils.h>
31 static const char *str_kernel
= "Kernel";
32 static const char *str_ust
= "UST";
33 static const char *str_jul
= "JUL";
38 * Return allocated string with the session name found in the config
41 char *get_session_name(void)
43 char *path
, *session_name
= NULL
;
45 /* Get path to config file */
46 path
= utils_get_home_dir();
51 /* Get session name from config */
52 session_name
= config_read_session_name(path
);
53 if (session_name
== NULL
) {
57 DBG2("Config file path found: %s", path
);
58 DBG("Session name found: %s", session_name
);
68 * List commands line by line. This is mostly for bash auto completion and to
69 * avoid difficult parsing.
71 void list_commands(struct cmd_struct
*commands
, FILE *ofp
)
74 struct cmd_struct
*cmd
= NULL
;
77 while (cmd
->name
!= NULL
) {
78 fprintf(ofp
, "%s\n", cmd
->name
);
87 * Prints a simple list of the options available to a command. This is intended
88 * to be easily parsed for bash completion.
90 void list_cmd_options(FILE *ofp
, struct poptOption
*options
)
93 struct poptOption
*option
= NULL
;
95 for (i
= 0; options
[i
].longName
!= NULL
; i
++) {
98 fprintf(ofp
, "--%s\n", option
->longName
);
100 if (isprint(option
->shortName
)) {
101 fprintf(ofp
, "-%c\n", option
->shortName
);
107 * fls: returns the position of the most significant bit.
108 * Returns 0 if no bit is set, else returns the position of the most
109 * significant bit (from 1 to 32 on 32-bit, from 1 to 64 on 64-bit).
111 #if defined(__i386) || defined(__x86_64)
113 unsigned int fls_u32(uint32_t x
)
121 : "=r" (r
) : "rm" (x
));
127 #if defined(__x86_64)
129 unsigned int fls_u64(uint64_t x
)
137 : "=r" (r
) : "rm" (x
));
144 static __attribute__((unused
))
145 unsigned int fls_u64(uint64_t x
)
152 if (!(x
& 0xFFFFFFFF00000000ULL
)) {
156 if (!(x
& 0xFFFF000000000000ULL
)) {
160 if (!(x
& 0xFF00000000000000ULL
)) {
164 if (!(x
& 0xF000000000000000ULL
)) {
168 if (!(x
& 0xC000000000000000ULL
)) {
172 if (!(x
& 0x8000000000000000ULL
)) {
181 static __attribute__((unused
))
182 unsigned int fls_u32(uint32_t x
)
188 if (!(x
& 0xFFFF0000U
)) {
192 if (!(x
& 0xFF000000U
)) {
196 if (!(x
& 0xF0000000U
)) {
200 if (!(x
& 0xC0000000U
)) {
204 if (!(x
& 0x80000000U
)) {
213 unsigned int fls_ulong(unsigned long x
)
215 #if (CAA_BITS_PER_LONG == 32)
223 * Return the minimum order for which x <= (1UL << order).
224 * Return -1 if x is 0.
226 int get_count_order_u32(uint32_t x
)
231 return fls_u32(x
- 1);
235 * Return the minimum order for which x <= (1UL << order).
236 * Return -1 if x is 0.
238 int get_count_order_u64(uint64_t x
)
243 return fls_u64(x
- 1);
247 * Return the minimum order for which x <= (1UL << order).
248 * Return -1 if x is 0.
250 int get_count_order_ulong(unsigned long x
)
255 return fls_ulong(x
- 1);
258 const char *get_domain_str(enum lttng_domain_type domain
)
263 case LTTNG_DOMAIN_KERNEL
:
264 str_dom
= str_kernel
;
266 case LTTNG_DOMAIN_UST
:
269 case LTTNG_DOMAIN_JUL
:
273 /* Should not have an unknown domain or else define it. */
This page took 0.03861 seconds and 5 git commands to generate.