summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/frr_pthread.c5
-rw-r--r--lib/hash.c14
-rw-r--r--lib/libfrr_trace.c4
-rw-r--r--lib/libfrr_trace.h240
-rw-r--r--lib/linklist.c9
-rw-r--r--lib/memory.c5
-rw-r--r--lib/subdir.am8
-rw-r--r--lib/table.c7
-rw-r--r--lib/thread.c33
-rw-r--r--lib/trace.h80
-rw-r--r--lib/zassert.h2
-rw-r--r--lib/zlog.c29
12 files changed, 431 insertions, 5 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index da9594ed80..3f0179fbc1 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -28,6 +28,7 @@
#include "memory.h"
#include "linklist.h"
#include "zlog.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, FRR_PTHREAD, "FRR POSIX Thread")
DEFINE_MTYPE_STATIC(LIB, PTHREAD_PRIM, "POSIX sync primitives")
@@ -167,6 +168,8 @@ int frr_pthread_run(struct frr_pthread *fpt, const pthread_attr_t *attr)
sigfillset(&blocksigs);
pthread_sigmask(SIG_BLOCK, &blocksigs, &oldsigs);
+ frrtrace(1, frr_libfrr, frr_pthread_run, fpt->name);
+
fpt->rcu_thread = rcu_thread_prepare();
ret = pthread_create(&fpt->thread, attr, frr_pthread_inner, fpt);
@@ -204,6 +207,8 @@ void frr_pthread_notify_running(struct frr_pthread *fpt)
int frr_pthread_stop(struct frr_pthread *fpt, void **result)
{
+ frrtrace(1, frr_libfrr, frr_pthread_stop, fpt->name);
+
int ret = (*fpt->attr.stop)(fpt, result);
memset(&fpt->thread, 0x00, sizeof(fpt->thread));
return ret;
diff --git a/lib/hash.c b/lib/hash.c
index 85982774ac..ed429b77d0 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -29,6 +29,7 @@
#include "command.h"
#include "libfrr.h"
#include "frr_pthread.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, HASH, "Hash")
DEFINE_MTYPE_STATIC(LIB, HASH_BACKET, "Hash Bucket")
@@ -138,6 +139,8 @@ static void hash_expand(struct hash *hash)
void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *))
{
+ frrtrace(2, frr_libfrr, hash_get, hash, data);
+
unsigned int key;
unsigned int index;
void *newdata;
@@ -172,6 +175,8 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *))
hash->index[index] = bucket;
hash->count++;
+ frrtrace(3, frr_libfrr, hash_insert, hash, data, key);
+
int oldlen = bucket->next ? bucket->next->len : 0;
int newlen = oldlen + 1;
@@ -206,7 +211,7 @@ unsigned int string_hash_make(const char *str)
void *hash_release(struct hash *hash, void *data)
{
- void *ret;
+ void *ret = NULL;
unsigned int key;
unsigned int index;
struct hash_bucket *bucket;
@@ -236,11 +241,14 @@ void *hash_release(struct hash *hash, void *data)
ret = bucket->data;
XFREE(MTYPE_HASH_BACKET, bucket);
hash->count--;
- return ret;
+ break;
}
pp = bucket;
}
- return NULL;
+
+ frrtrace(3, frr_libfrr, hash_release, hash, data, ret);
+
+ return ret;
}
void hash_iterate(struct hash *hash, void (*func)(struct hash_bucket *, void *),
diff --git a/lib/libfrr_trace.c b/lib/libfrr_trace.c
new file mode 100644
index 0000000000..2f300e6ee1
--- /dev/null
+++ b/lib/libfrr_trace.c
@@ -0,0 +1,4 @@
+#define TRACEPOINT_CREATE_PROBES
+#define TRACEPOINT_DEFINE
+
+#include "libfrr_trace.h"
diff --git a/lib/libfrr_trace.h b/lib/libfrr_trace.h
new file mode 100644
index 0000000000..7215007ffb
--- /dev/null
+++ b/lib/libfrr_trace.h
@@ -0,0 +1,240 @@
+/* Tracing
+ *
+ * Copyright (C) 2020 NVIDIA Corporation
+ * Quentin Young
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if !defined(_LIBFRR_TRACE_H_) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _LIBFRR_TRACE_H_
+
+#include "trace.h"
+
+#ifdef HAVE_LTTNG
+
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER frr_libfrr
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./libfrr_trace.h"
+
+#include <lttng/tracepoint.h>
+
+#include "hash.h"
+#include "thread.h"
+#include "memory.h"
+#include "linklist.h"
+#include "table.h"
+
+/* clang-format off */
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ hash_get,
+ TP_ARGS(struct hash *, hash, void *, data),
+ TP_FIELDS(
+ ctf_string(name, hash->name ? hash->name : "(unnamed)")
+ ctf_integer(unsigned int, index_size, hash->size)
+ ctf_integer(unsigned long, item_count, hash->count)
+ ctf_integer_hex(intptr_t, data_ptr, data)
+ )
+)
+
+TRACEPOINT_LOGLEVEL(frr_libfrr, hash_get, TRACE_INFO)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ hash_insert,
+ TP_ARGS(struct hash *, hash, void *, data, unsigned int, key),
+ TP_FIELDS(
+ ctf_string(name, hash->name ? hash->name : "(unnamed)")
+ ctf_integer(unsigned int, key, hash->size)
+ ctf_integer(unsigned int, index_size, hash->size)
+ ctf_integer(unsigned long, item_count, hash->count)
+ ctf_integer_hex(intptr_t, data_ptr, data)
+ )
+)
+
+TRACEPOINT_LOGLEVEL(frr_libfrr, hash_insert, TRACE_INFO)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ hash_release,
+ TP_ARGS(struct hash *, hash, void *, data, void *, released_item),
+ TP_FIELDS(
+ ctf_string(name, hash->name ? hash->name : "(unnamed)")
+ ctf_integer(unsigned int, index_size, hash->size)
+ ctf_integer(unsigned long, item_count, hash->count)
+ ctf_integer_hex(intptr_t, data_ptr, data)
+ ctf_integer_hex(intptr_t, released_item, data)
+ )
+)
+
+TRACEPOINT_LOGLEVEL(frr_libfrr, hash_release, TRACE_INFO)
+
+#define THREAD_SCHEDULE_ARGS \
+ TP_ARGS(struct thread_master *, master, const char *, funcname, \
+ const char *, schedfrom, int, fromln, struct thread **, \
+ thread_ptr, int, fd, int, val, void *, arg, long, time)
+
+TRACEPOINT_EVENT_CLASS(
+ frr_libfrr,
+ thread_operation,
+ THREAD_SCHEDULE_ARGS,
+ TP_FIELDS(
+ ctf_string(threadmaster_name, master->name)
+ ctf_string(function_name, funcname ? funcname : "(unknown function)")
+ ctf_string(scheduled_from, schedfrom ? schedfrom : "(unknown file)")
+ ctf_integer(int, scheduled_on_line, fromln)
+ ctf_integer_hex(intptr_t, thread_addr, thread_ptr ? *thread_ptr : NULL)
+ ctf_integer(int, file_descriptor, fd)
+ ctf_integer(int, event_value, val)
+ ctf_integer_hex(intptr_t, argument_ptr, arg)
+ ctf_integer(long, timer, time)
+ )
+)
+
+#define THREAD_OPERATION_TRACEPOINT_INSTANCE(name) \
+ TRACEPOINT_EVENT_INSTANCE(frr_libfrr, thread_operation, name, \
+ THREAD_SCHEDULE_ARGS) \
+ TRACEPOINT_LOGLEVEL(frr_libfrr, name, TRACE_INFO)
+
+THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_timer)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_event)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_read)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_write)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel_async)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ frr_pthread_run,
+ TP_ARGS(
+ char *, name
+ ),
+ TP_FIELDS(
+ ctf_string(frr_pthread_name, name)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ frr_pthread_stop,
+ TP_ARGS(
+ char *, name
+ ),
+ TP_FIELDS(
+ ctf_string(frr_pthread_name, name)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ memalloc,
+ TP_ARGS(
+ struct memtype *, mt, void *, ptr, size_t, size
+ ),
+ TP_FIELDS(
+ ctf_string(memtype, mt->name)
+ ctf_integer(size_t, size, size)
+ ctf_integer_hex(intptr_t, ptr, ptr)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ memfree,
+ TP_ARGS(
+ struct memtype *, mt, void *, ptr
+ ),
+ TP_FIELDS(
+ ctf_string(memtype, mt->name)
+ ctf_integer_hex(intptr_t, ptr, ptr)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ list_add,
+ TP_ARGS(
+ struct list *, list, const void *, ptr
+ ),
+ TP_FIELDS(
+ ctf_integer_hex(intptr_t, list, list)
+ ctf_integer(unsigned int, count, list->count)
+ ctf_integer_hex(intptr_t, ptr, ptr)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ list_remove,
+ TP_ARGS(
+ struct list *, list, const void *, ptr
+ ),
+ TP_FIELDS(
+ ctf_integer_hex(intptr_t, list, list)
+ ctf_integer(unsigned int, count, list->count)
+ ctf_integer_hex(intptr_t, ptr, ptr)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ list_delete_node,
+ TP_ARGS(
+ struct list *, list, const void *, node
+ ),
+ TP_FIELDS(
+ ctf_integer_hex(intptr_t, list, list)
+ ctf_integer(unsigned int, count, list->count)
+ ctf_integer_hex(intptr_t, node, node)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ list_sort,
+ TP_ARGS(
+ struct list *, list
+ ),
+ TP_FIELDS(
+ ctf_integer_hex(intptr_t, list, list)
+ ctf_integer(unsigned int, count, list->count)
+ )
+)
+
+TRACEPOINT_EVENT(
+ frr_libfrr,
+ route_node_get,
+ TP_ARGS(
+ struct route_table *, table, char *, prefix
+ ),
+ TP_FIELDS(
+ ctf_integer_hex(intptr_t, table, table)
+ ctf_string(prefix, prefix)
+ )
+)
+
+/* clang-format on */
+
+#include <lttng/tracepoint-event.h>
+#include <lttng/tracelog.h>
+
+#endif /* HAVE_LTTNG */
+
+#endif /* _LIBFRR_TRACE_H_ */
diff --git a/lib/linklist.c b/lib/linklist.c
index 84dc6e1419..43c2002231 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -23,6 +23,7 @@
#include "linklist.h"
#include "memory.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List")
DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node")
@@ -66,6 +67,8 @@ static void listnode_free(struct list *list, struct listnode *node)
struct listnode *listnode_add(struct list *list, void *val)
{
+ frrtrace(2, frr_libfrr, list_add, list, val);
+
struct listnode *node;
assert(val != NULL);
@@ -281,6 +284,8 @@ void listnode_move_to_tail(struct list *l, struct listnode *n)
void listnode_delete(struct list *list, const void *val)
{
+ frrtrace(2, frr_libfrr, list_remove, list, val);
+
struct listnode *node = listnode_lookup(list, val);
if (node)
@@ -360,6 +365,8 @@ struct listnode *listnode_lookup_nocheck(struct list *list, void *data)
void list_delete_node(struct list *list, struct listnode *node)
{
+ frrtrace(2, frr_libfrr, list_delete_node, list, node);
+
if (node->prev)
node->prev->next = node->next;
else
@@ -374,6 +381,8 @@ void list_delete_node(struct list *list, struct listnode *node)
void list_sort(struct list *list, int (*cmp)(const void **, const void **))
{
+ frrtrace(1, frr_libfrr, list_sort, list);
+
struct listnode *ln, *nn;
int i = -1;
void *data;
diff --git a/lib/memory.c b/lib/memory.c
index 2c902d123b..f715044ea3 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -29,6 +29,7 @@
#include "memory.h"
#include "log.h"
+#include "libfrr_trace.h"
static struct memgroup *mg_first = NULL;
struct memgroup **mg_insert = &mg_first;
@@ -77,6 +78,8 @@ static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
static inline void mt_count_free(struct memtype *mt, void *ptr)
{
+ frrtrace(2, frr_libfrr, memfree, mt, ptr);
+
assert(mt->n_alloc);
atomic_fetch_sub_explicit(&mt->n_alloc, 1, memory_order_relaxed);
@@ -89,6 +92,8 @@ static inline void mt_count_free(struct memtype *mt, void *ptr)
static inline void *mt_checkalloc(struct memtype *mt, void *ptr, size_t size)
{
+ frrtrace(3, frr_libfrr, memalloc, mt, ptr, size);
+
if (__builtin_expect(ptr == NULL, 0)) {
if (size) {
/* malloc(0) is allowed to return NULL */
diff --git a/lib/subdir.am b/lib/subdir.am
index 55f127b019..ed3c30799d 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -3,7 +3,7 @@
#
lib_LTLIBRARIES += lib/libfrr.la
lib_libfrr_la_LDFLAGS = -version-info 0:0:0 -Xlinker -e_libfrr_version
-lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(LIBM)
+lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST_LIBS) $(LIBM)
lib_libfrr_la_SOURCES = \
lib/agg_table.c \
@@ -46,6 +46,7 @@ lib_libfrr_la_SOURCES = \
lib/lib_errors.c \
lib/lib_vty.c \
lib/libfrr.c \
+ lib/libfrr_trace.c \
lib/linklist.c \
lib/log.c \
lib/log_filter.c \
@@ -204,6 +205,7 @@ pkginclude_HEADERS += \
lib/lib_errors.h \
lib/lib_vty.h \
lib/libfrr.h \
+ lib/libfrr_trace.h \
lib/libospf.h \
lib/linklist.h \
lib/log.h \
@@ -251,6 +253,7 @@ pkginclude_HEADERS += \
lib/table.h \
lib/termtable.h \
lib/thread.h \
+ lib/trace.h \
lib/typerb.h \
lib/typesafe.h \
lib/vector.h \
@@ -401,7 +404,7 @@ lib_grammar_sandbox_LDADD = \
lib_clippy_CPPFLAGS = $(AM_CPPFLAGS) -D_GNU_SOURCE -DBUILDING_CLIPPY
lib_clippy_CFLAGS = $(PYTHON_CFLAGS)
-lib_clippy_LDADD = $(PYTHON_LIBS)
+lib_clippy_LDADD = $(PYTHON_LIBS) $(UST_LIBS)
lib_clippy_LDFLAGS = -export-dynamic
lib_clippy_SOURCES = \
lib/clippy.c \
@@ -411,6 +414,7 @@ lib_clippy_SOURCES = \
lib/command_py.c \
lib/defun_lex.l \
lib/graph.c \
+ lib/libfrr_trace.c \
lib/memory.c \
lib/vector.c \
# end
diff --git a/lib/table.c b/lib/table.c
index b315637f19..89e32182b5 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -27,6 +27,7 @@
#include "table.h"
#include "memory.h"
#include "sockunion.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, ROUTE_TABLE, "Route table")
DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
@@ -276,6 +277,12 @@ struct route_node *route_node_lookup_maynull(struct route_table *table,
struct route_node *route_node_get(struct route_table *table,
union prefixconstptr pu)
{
+ if (frrtrace_enabled(frr_libfrr, route_node_get)) {
+ char buf[PREFIX2STR_BUFFER];
+ prefix2str(pu, buf, sizeof(buf));
+ frrtrace(2, frr_libfrr, route_node_get, table, buf);
+ }
+
struct route_node search;
struct prefix *p = &search.p;
diff --git a/lib/thread.c b/lib/thread.c
index 012194a47b..1765de9573 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -35,6 +35,7 @@
#include "frratomic.h"
#include "frr_pthread.h"
#include "lib_errors.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread")
DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master")
@@ -787,6 +788,13 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m,
struct thread *thread = NULL;
struct thread **thread_array;
+ if (dir == THREAD_READ)
+ frrtrace(9, frr_libfrr, schedule_read, m, funcname, schedfrom,
+ fromln, t_ptr, fd, 0, arg, 0);
+ else
+ frrtrace(9, frr_libfrr, schedule_write, m, funcname, schedfrom,
+ fromln, t_ptr, fd, 0, arg, 0);
+
assert(fd >= 0 && fd < m->fd_limit);
frr_with_mutex(&m->mtx) {
if (t_ptr && *t_ptr)
@@ -861,6 +869,9 @@ funcname_thread_add_timer_timeval(struct thread_master *m,
assert(type == THREAD_TIMER);
assert(time_relative);
+ frrtrace(9, frr_libfrr, schedule_timer, m, funcname, schedfrom, fromln,
+ t_ptr, 0, 0, arg, (long)time_relative->tv_sec);
+
frr_with_mutex(&m->mtx) {
if (t_ptr && *t_ptr)
/* thread is already scheduled; don't reschedule */
@@ -939,6 +950,9 @@ struct thread *funcname_thread_add_event(struct thread_master *m,
{
struct thread *thread = NULL;
+ frrtrace(9, frr_libfrr, schedule_event, m, funcname, schedfrom, fromln,
+ t_ptr, 0, val, arg, 0);
+
assert(m != NULL);
frr_with_mutex(&m->mtx) {
@@ -1172,6 +1186,10 @@ void thread_cancel(struct thread **thread)
master = (*thread)->master;
+ frrtrace(9, frr_libfrr, thread_cancel, master, thread->funcname,
+ thread->schedfrom, thread->schedfrom_line, NULL, thread->u.fd,
+ thread->u.val, thread->arg, thread->u.sands.tv_sec);
+
assert(master->owner == pthread_self());
frr_with_mutex(&master->mtx) {
@@ -1213,6 +1231,17 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
void *eventobj)
{
assert(!(thread && eventobj) && (thread || eventobj));
+
+ if (thread && *thread)
+ frrtrace(9, frr_libfrr, thread_cancel_async, master,
+ (*thread)->funcname, (*thread)->schedfrom,
+ (*thread)->schedfrom_line, NULL, (*thread)->u.fd,
+ (*thread)->u.val, (*thread)->arg,
+ (*thread)->u.sands.tv_sec);
+ else
+ frrtrace(9, frr_libfrr, thread_cancel_async, master, NULL, NULL,
+ 0, NULL, 0, 0, eventobj, 0);
+
assert(master->owner != pthread_self());
frr_with_mutex(&master->mtx) {
@@ -1591,6 +1620,10 @@ void thread_call(struct thread *thread)
GETRUSAGE(&before);
thread->real = before.real;
+ frrtrace(9, frr_libfrr, thread_call, thread->master, thread->funcname,
+ thread->schedfrom, thread->schedfrom_line, NULL, thread->u.fd,
+ thread->u.val, thread->arg, thread->u.sands.tv_sec);
+
pthread_setspecific(thread_current, thread);
(*thread->func)(thread);
pthread_setspecific(thread_current, NULL);
diff --git a/lib/trace.h b/lib/trace.h
new file mode 100644
index 0000000000..73fc10a556
--- /dev/null
+++ b/lib/trace.h
@@ -0,0 +1,80 @@
+/* Tracing macros
+ *
+ * Wraps tracepoint macros for different tracing systems to allow switching
+ * between them at compile time.
+ *
+ * This should not be included directly by source files wishing to provide
+ * tracepoints. Instead, write a header that defines LTTng tracepoints and
+ * which includes this header, and include your new header in your source. USDT
+ * probes do not need tracepoint definitions, but are less capable than LTTng
+ * tracepoints.
+ *
+ * Copyright (C) 2020 NVIDIA Corporation
+ * Quentin Young
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TRACE_H_
+#define _TRACE_H_
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+/*
+ * Provided here:
+ * - frrtrace(n, provider, name, ...args...)
+ * - frrtrace_enabled(provider, name)
+ * - frrtracelog(level, msg, ...)
+ *
+ * Use frrtrace() to define tracepoints. n is the number of arguments; this is
+ * needed because USDT probe definitions use DTRACE_PROBEn macros, so the
+ * number of args must be passed in order to expand the correct macro.
+ *
+ * frrtrace_enabled() maps to tracepoint_enabled() under LTTng and is always
+ * true when using USDT. In the future it could be mapped to USDT semaphores
+ * but this is not implemented at present.
+ *
+ * frrtracelog() maps to tracelog() under LTTng and should only be used in zlog
+ * core code, to propagate zlog messages to LTTng. It expands to nothing
+ * otherwise.
+ */
+
+#if defined(HAVE_LTTNG)
+
+#define frrtrace(nargs, provider, name, ...) \
+ tracepoint(provider, name, ## __VA_ARGS__)
+#define frrtrace_enabled(...) tracepoint_enabled(__VA_ARGS__)
+#define frrtracelog(...) tracelog(__VA_ARGS__)
+
+#elif defined(HAVE_USDT)
+
+#include "sys/sdt.h"
+
+#define frrtrace(nargs, provider, name, ...) \
+ DTRACE_PROBE##nargs(provider, name, ## __VA_ARGS__)
+#define frrtrace_enabled(...) true
+#define frrtracelog(...)
+
+#else
+
+#define frrtrace(nargs, provider, name, ...) (void)0
+#define frrtrace_enabled(...) false
+#define frrtracelog(...) (void)0
+
+#endif
+
+#endif /* _TRACE_H_ */
diff --git a/lib/zassert.h b/lib/zassert.h
index e50a88f407..e6b254ee8d 100644
--- a/lib/zassert.h
+++ b/lib/zassert.h
@@ -27,6 +27,8 @@ extern void _zlog_assert_failed(const char *assertion, const char *file,
unsigned int line, const char *function)
__attribute__((noreturn));
+#undef __ASSERT_FUNCTION
+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define __ASSERT_FUNCTION __func__
#elif defined(__GNUC__)
diff --git a/lib/zlog.c b/lib/zlog.c
index 8dfd20371b..e77feec5f2 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -52,6 +52,7 @@
#include "printfrr.h"
#include "frrcu.h"
#include "zlog.h"
+#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, LOG_MESSAGE, "log message")
DEFINE_MTYPE_STATIC(LIB, LOG_TLSBUF, "log thread-local buffer")
@@ -450,6 +451,34 @@ void vzlog(int prio, const char *fmt, va_list ap)
{
struct zlog_tls *zlog_tls = zlog_tls_get();
+#ifdef HAVE_LTTNG
+ va_list copy;
+ va_copy(copy, ap);
+ char *msg = vasprintfrr(MTYPE_LOG_MESSAGE, fmt, copy);
+
+ switch (prio) {
+ case LOG_ERR:
+ frrtracelog(TRACE_ERR, msg);
+ break;
+ case LOG_WARNING:
+ frrtracelog(TRACE_WARNING, msg);
+ break;
+ case LOG_DEBUG:
+ frrtracelog(TRACE_DEBUG, msg);
+ break;
+ case LOG_NOTICE:
+ frrtracelog(TRACE_DEBUG, msg);
+ break;
+ case LOG_INFO:
+ default:
+ frrtracelog(TRACE_INFO, msg);
+ break;
+ }
+
+ va_end(copy);
+ XFREE(MTYPE_LOG_MESSAGE, msg);
+#endif
+
if (zlog_tls)
vzlog_tls(zlog_tls, prio, fmt, ap);
else