From 0cb03c850dedb8f1e7f11e2e47764aa4d3ba313b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 9 Jun 2015 13:56:47 +0200 Subject: [PATCH] Implement tracelog API Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 2 + include/lttng/lttng-ust-tracelog.h | 54 +++++++++++++++++ include/lttng/tracelog.h | 66 +++++++++++++++++++++ liblttng-ust/Makefile.am | 2 + liblttng-ust/lttng-ust-tracelog-provider.h | 38 ++++++++++++ liblttng-ust/tracelog.c | 67 ++++++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 include/lttng/lttng-ust-tracelog.h create mode 100644 include/lttng/tracelog.h create mode 100644 liblttng-ust/lttng-ust-tracelog-provider.h create mode 100644 liblttng-ust/tracelog.c diff --git a/include/Makefile.am b/include/Makefile.am index 2fc11b5a..44102ef8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 00000000..5b1c940a --- /dev/null +++ b/include/lttng/lttng-ust-tracelog.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011-2015 Mathieu Desnoyers + * + * 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 +#include + +#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 index 00000000..50ef4ff0 --- /dev/null +++ b/include/lttng/tracelog.h @@ -0,0 +1,66 @@ +#ifndef _LTTNG_UST_TRACELOG_H +#define _LTTNG_UST_TRACELOG_H + +/* + * Copyright (C) 2013-2015 Mathieu Desnoyers + * + * 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 + +#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 */ diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index a716a34f..442b0540 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -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 index 00000000..a1c431dc --- /dev/null +++ b/liblttng-ust/lttng-ust-tracelog-provider.h @@ -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 + * + * 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 + +#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 diff --git a/liblttng-ust/tracelog.c b/liblttng-ust/tracelog.c new file mode 100644 index 00000000..0e42b4b1 --- /dev/null +++ b/liblttng-ust/tracelog.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013-2014 Mathieu Desnoyers + * + * 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 + +#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) -- 2.34.1