Implement tracelog API
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 9 Jun 2015 11:56:47 +0000 (13:56 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 9 Jun 2015 14:22:41 +0000 (16:22 +0200)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/Makefile.am
include/lttng/lttng-ust-tracelog.h [new file with mode: 0644]
include/lttng/tracelog.h [new file with mode: 0644]
liblttng-ust/Makefile.am
liblttng-ust/lttng-ust-tracelog-provider.h [new file with mode: 0644]
liblttng-ust/tracelog.c [new file with mode: 0644]

index 2fc11b5afb6451cbf8fa6e91f994b2541e2c7763..44102ef8e781ccba26e12c2180eda6b901a8ed1b 100644 (file)
@@ -21,6 +21,8 @@ nobase_include_HEADERS = \
        lttng/ust-error.h \
        lttng/tracef.h \
        lttng/lttng-ust-tracef.h \
+       lttng/tracelog.h \
+       lttng/lttng-ust-tracelog.h \
        lttng/ust-clock.h \
        lttng/ust-getcpu.h
 
diff --git a/include/lttng/lttng-ust-tracelog.h b/include/lttng/lttng-ust-tracelog.h
new file mode 100644 (file)
index 0000000..5b1c940
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011-2015  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+#include <stdarg.h>
+
+#define TP_TRACELOG_TEMPLATE(_level_identifier, _level_enum) \
+       TRACEPOINT_EVENT(lttng_ust_tracelog, _level_identifier, \
+               TP_ARGS(const char *, file, int, line, const char *, func, \
+                       const char *, msg, unsigned int, len, void *, ip), \
+               TP_FIELDS( \
+                       ctf_integer(int, line, line) \
+                       ctf_string(file, file) \
+                       ctf_string(func, func) \
+                       ctf_sequence_text(char, msg, msg, unsigned int, len) \
+               ) \
+       ) \
+       TRACEPOINT_LOGLEVEL(lttng_ust_tracelog, _level_identifier, \
+               TRACE_##_level_enum)
+
+TP_TRACELOG_TEMPLATE(emerg, EMERG)
+TP_TRACELOG_TEMPLATE(alert, ALERT)
+TP_TRACELOG_TEMPLATE(crit, CRIT)
+TP_TRACELOG_TEMPLATE(err, ERR)
+TP_TRACELOG_TEMPLATE(warning, WARNING)
+TP_TRACELOG_TEMPLATE(notice, NOTICE)
+TP_TRACELOG_TEMPLATE(info, INFO)
+TP_TRACELOG_TEMPLATE(debug_system, DEBUG_SYSTEM)
+TP_TRACELOG_TEMPLATE(debug_program, DEBUG_PROGRAM)
+TP_TRACELOG_TEMPLATE(debug_process, DEBUG_PROCESS)
+TP_TRACELOG_TEMPLATE(debug_module, DEBUG_MODULE)
+TP_TRACELOG_TEMPLATE(debug_unit, DEBUG_UNIT)
+TP_TRACELOG_TEMPLATE(debug_function, DEBUG_FUNCTION)
+TP_TRACELOG_TEMPLATE(debug_line, DEBUG_LINE)
+TP_TRACELOG_TEMPLATE(debug, DEBUG)
diff --git a/include/lttng/tracelog.h b/include/lttng/tracelog.h
new file mode 100644 (file)
index 0000000..50ef4ff
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef _LTTNG_UST_TRACELOG_H
+#define _LTTNG_UST_TRACELOG_H
+
+/*
+ * Copyright (C) 2013-2015  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/lttng-ust-tracelog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TP_TRACELOG_CB_TEMPLATE(level) \
+       extern void _lttng_ust_tracelog_##level(const char *file, \
+               int line, const char *func, const char *fmt, ...)
+
+TP_TRACELOG_CB_TEMPLATE(emerg);
+TP_TRACELOG_CB_TEMPLATE(alert);
+TP_TRACELOG_CB_TEMPLATE(crit);
+TP_TRACELOG_CB_TEMPLATE(err);
+TP_TRACELOG_CB_TEMPLATE(warning);
+TP_TRACELOG_CB_TEMPLATE(notice);
+TP_TRACELOG_CB_TEMPLATE(info);
+TP_TRACELOG_CB_TEMPLATE(debug_system);
+TP_TRACELOG_CB_TEMPLATE(debug_program);
+TP_TRACELOG_CB_TEMPLATE(debug_process);
+TP_TRACELOG_CB_TEMPLATE(debug_module);
+TP_TRACELOG_CB_TEMPLATE(debug_unit);
+TP_TRACELOG_CB_TEMPLATE(debug_function);
+TP_TRACELOG_CB_TEMPLATE(debug_line);
+TP_TRACELOG_CB_TEMPLATE(debug);
+
+#undef TP_TRACELOG_CB_TEMPLATE
+
+#define tracelog(level, fmt, ...)                                      \
+       do {                                                            \
+               STAP_PROBEV(tracepoint_lttng_ust_tracelog, level, ## __VA_ARGS__); \
+               if (caa_unlikely(__tracepoint_lttng_ust_tracelog___## level.state)) \
+                       _lttng_ust_tracelog_##level(__FILE__, __LINE__, __func__, \
+                               fmt, ## __VA_ARGS__); \
+       } while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LTTNG_UST_TRACELOG_H */
index a716a34fcdf5fa69b8f1ec0c2dc64535c191b988..442b054012a57e461b135d4424757c886659c985 100644 (file)
@@ -47,6 +47,8 @@ liblttng_ust_runtime_la_SOURCES = \
        error.h \
        tracef.c \
        lttng-ust-tracef-provider.h \
+       tracelog.c \
+       lttng-ust-tracelog-provider.h \
        getenv.h
 
 if HAVE_PERF_EVENT
diff --git a/liblttng-ust/lttng-ust-tracelog-provider.h b/liblttng-ust/lttng-ust-tracelog-provider.h
new file mode 100644 (file)
index 0000000..a1c431d
--- /dev/null
@@ -0,0 +1,38 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER lttng_ust_tracelog
+
+#if !defined(_TRACEPOINT_LTTNG_UST_TRACELOG_PROVIDER_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_LTTNG_UST_TRACELOG_PROVIDER_H
+
+/*
+ * Copyright (C) 2011-2015  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/lttng-ust-tracelog.h>
+
+#endif /* _TRACEPOINT_LTTNG_UST_TRACEF_PROVIDER_H */
+
+#define TP_IP_PARAM    /* IP context received as parameter */
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./lttng-ust-tracelog.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
diff --git a/liblttng-ust/tracelog.c b/liblttng-ust/tracelog.c
new file mode 100644 (file)
index 0000000..0e42b4b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013-2014  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define _GNU_SOURCE
+#define _LGPL_SOURCE
+#include <stdio.h>
+
+#define TRACEPOINT_CREATE_PROBES
+#define TRACEPOINT_DEFINE
+#include "lttng-ust-tracelog-provider.h"
+
+#define TRACELOG_CB(level) \
+       void _lttng_ust_tracelog_##level(const char *file, \
+                       int line, const char *func, \
+                       const char *fmt, ...) \
+       { \
+               va_list ap; \
+               char *msg; \
+               int len; \
+               \
+               va_start(ap, fmt); \
+               len = vasprintf(&msg, fmt, ap); \
+               /* len does not include the final \0 */ \
+               if (len < 0) \
+                       goto end; \
+               __tracepoint_cb_lttng_ust_tracelog___##level(file, \
+                       line, func, msg, len, \
+                       __builtin_return_address(0)); \
+               free(msg); \
+       end: \
+               va_end(ap); \
+       }
+
+TRACELOG_CB(emerg)
+TRACELOG_CB(alert)
+TRACELOG_CB(crit)
+TRACELOG_CB(err)
+TRACELOG_CB(warning)
+TRACELOG_CB(notice)
+TRACELOG_CB(info)
+TRACELOG_CB(debug_system)
+TRACELOG_CB(debug_program)
+TRACELOG_CB(debug_process)
+TRACELOG_CB(debug_module)
+TRACELOG_CB(debug_unit)
+TRACELOG_CB(debug_function)
+TRACELOG_CB(debug_line)
+TRACELOG_CB(debug)
This page took 0.028463 seconds and 4 git commands to generate.