From 0cbcadccf741fe679ce16ad051f1970c46323580 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 14 Sep 2020 18:02:56 -0400 Subject: lib, configure.ac: initial LTTng support This commit adds initial support for LTTng. When --enable-lttng=no or is not specified, no tracing code is included. When --enable-lttng=yes, LTTng tracing events are (will be) generated. configure.ac: - add --enable-lttng - define HAVE_LTTNG when enabled - minimum LTTng version: 2.12.0 lib: - add trace.[ch] - update subdir.am Signed-off-by: Quentin Young --- lib/trace.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/trace.h (limited to 'lib/trace.h') diff --git a/lib/trace.h b/lib/trace.h new file mode 100644 index 0000000000..b30bdd5110 --- /dev/null +++ b/lib/trace.h @@ -0,0 +1,50 @@ +/* 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(_TRACE_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACE_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_LTTNG + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER frr_libfrr + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./trace.h" + +/* tracepoint definitions go here */ + +#include +#include + +#else /* HAVE_LTTNG */ + +#define tracepoint(...) +#define tracef(...) +#define tracelog(...) +#define tracepoint_enabled(...) true + +#endif /* HAVE_LTTNG */ + +#endif /* _TRACE_H */ -- cgit v1.2.3 From abf96a87f3f2f9527885ee78930787ecb4068530 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 14 Sep 2020 18:04:33 -0400 Subject: lib: add tracepoints for hash ops, thread events Define some initial tracepoints for hash table operations, thread schedules, and thread cancels Signed-off-by: Quentin Young --- lib/hash.c | 12 +++++++--- lib/thread.c | 35 ++++++++++++++++++++++++++++ lib/trace.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 5 deletions(-) (limited to 'lib/trace.h') diff --git a/lib/hash.c b/lib/hash.c index 85982774ac..99a9e2e3ab 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -29,6 +29,7 @@ #include "command.h" #include "libfrr.h" #include "frr_pthread.h" +#include "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 *)) { + tracepoint(frr_libfrr, hash_get, hash, data); + unsigned int key; unsigned int index; void *newdata; @@ -206,7 +209,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 +239,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; + + tracepoint(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/thread.c b/lib/thread.c index db35a3f031..8679454367 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 "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) + tracepoint(frr_libfrr, schedule_read, m, funcname, schedfrom, + fromln, t_ptr, fd, 0, arg, 0); + else + tracepoint(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); + tracepoint(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; + tracepoint(frr_libfrr, schedule_event, m, funcname, schedfrom, fromln, + t_ptr, 0, val, arg, 0); + assert(m != NULL); frr_with_mutex(&m->mtx) { @@ -1167,6 +1181,11 @@ void thread_cancel(struct thread *thread) { struct thread_master *master = thread->master; + tracepoint(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) { @@ -1206,6 +1225,17 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread, void *eventobj) { assert(!(thread && eventobj) && (thread || eventobj)); + + if (thread && *thread) + tracepoint(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 + tracepoint(frr_libfrr, thread_cancel_async, master, NULL, NULL, + 0, NULL, 0, 0, eventobj, 0); + assert(master->owner != pthread_self()); frr_with_mutex(&master->mtx) { @@ -1581,6 +1611,11 @@ void thread_call(struct thread *thread) GETRUSAGE(&before); thread->real = before.real; + tracepoint(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 index b30bdd5110..dd6fb73ae4 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -33,9 +33,79 @@ #undef TRACEPOINT_INCLUDE #define TRACEPOINT_INCLUDE "./trace.h" -/* tracepoint definitions go here */ - #include + +#include "hash.h" +#include "thread.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_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) + +/* clang-format on */ + #include #else /* HAVE_LTTNG */ -- cgit v1.2.3 From 1bd1ebaa08e9ca2e120f31fb9db3bd6be8111989 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 14 Sep 2020 18:05:47 -0400 Subject: lib: generate trace events for log messages LTTng supports tracef() and tracelog() macros, which work like printf, and are used to ease transition between logging and tracing. Messages printed using these macros end up as trace events. For our uses we are not interested in dropping logging, but it is nice to get log messages in trace output, so I've added a call to tracelog() in zlog that dumps our zlog messages as trace events. Signed-off-by: Quentin Young --- lib/trace.h | 1 + lib/zlog.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'lib/trace.h') diff --git a/lib/trace.h b/lib/trace.h index dd6fb73ae4..d605cad0c4 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -107,6 +107,7 @@ THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call) /* clang-format on */ #include +#include #else /* HAVE_LTTNG */ diff --git a/lib/zlog.c b/lib/zlog.c index 8dfd20371b..f28ff08617 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -52,6 +52,7 @@ #include "printfrr.h" #include "frrcu.h" #include "zlog.h" +#include "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: + tracelog(TRACE_ERR, msg); + break; + case LOG_WARNING: + tracelog(TRACE_WARNING, msg); + break; + case LOG_DEBUG: + tracelog(TRACE_DEBUG, msg); + break; + case LOG_NOTICE: + tracelog(TRACE_DEBUG, msg); + break; + case LOG_INFO: + default: + tracelog(TRACE_INFO, msg); + break; + } + + va_end(copy); + XFREE(MTYPE_LOG_MESSAGE, msg); +#endif + if (zlog_tls) vzlog_tls(zlog_tls, prio, fmt, ap); else -- cgit v1.2.3 From 87879a5ecb0d31e490ce078adaf4408476bd4df8 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 15 Sep 2020 00:28:55 -0400 Subject: lib: add tracepoints for pthread run, stop Signed-off-by: Quentin Young --- lib/frr_pthread.c | 5 +++++ lib/trace.h | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'lib/trace.h') diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index da9594ed80..82d0c8c49f 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 "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); + tracepoint(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) { + tracepoint(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/trace.h b/lib/trace.h index d605cad0c4..e6d0f115e4 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -104,6 +104,28 @@ 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) + ) +) + /* clang-format on */ #include -- cgit v1.2.3 From 67a485d18f4074dbdd8378279b400137283c3aa5 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 16 Sep 2020 19:29:32 -0400 Subject: lib: add tracepoint for hash insertion hash_get is used for both lookup and insert; add a tracepoint for when we insert something into the hash Signed-off-by: Quentin Young --- lib/hash.c | 2 ++ lib/trace.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'lib/trace.h') diff --git a/lib/hash.c b/lib/hash.c index 99a9e2e3ab..d0dc639229 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -175,6 +175,8 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *)) hash->index[index] = bucket; hash->count++; + tracepoint(frr_libfrr, hash_insert, hash, data, key); + int oldlen = bucket->next ? bucket->next->len : 0; int newlen = oldlen + 1; diff --git a/lib/trace.h b/lib/trace.h index e6d0f115e4..753a25f4a5 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -54,6 +54,21 @@ TRACEPOINT_EVENT( 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, -- cgit v1.2.3 From d92658f4f7511c1b2c47a063df51ad3190db7af3 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 17 Sep 2020 14:57:36 -0400 Subject: lib: add tracepoints for *malloc, list ops - Add tracepoints for FRR malloc and free - Add tracepoints for basic list operations Signed-off-by: Quentin Young --- lib/linklist.c | 9 +++++++ lib/memory.c | 5 ++++ lib/subdir.am | 3 ++- lib/trace.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) (limited to 'lib/trace.h') diff --git a/lib/linklist.c b/lib/linklist.c index 84dc6e1419..19a8514cd6 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -23,6 +23,7 @@ #include "linklist.h" #include "memory.h" +#include "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) { + tracepoint(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) { + tracepoint(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) { + tracepoint(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 **)) { + tracepoint(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..219ddcb638 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -29,6 +29,7 @@ #include "memory.h" #include "log.h" +#include "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) { + tracepoint(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) { + tracepoint(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 5f764f8a55..54fdf429fc 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -403,7 +403,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 \ @@ -415,6 +415,7 @@ lib_clippy_SOURCES = \ lib/graph.c \ lib/memory.c \ lib/vector.c \ + lib/trace.c \ # end # (global) clippy rules for all directories diff --git a/lib/trace.h b/lib/trace.h index 753a25f4a5..989361e66c 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -37,6 +37,8 @@ #include "hash.h" #include "thread.h" +#include "memory.h" +#include "linklist.h" /* clang-format off */ @@ -141,6 +143,82 @@ TRACEPOINT_EVENT( ) ) +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) + ) +) + /* clang-format on */ #include -- cgit v1.2.3 From a72255a336c68dcc62d7bd9fcc1d409ee766cf77 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 18 Sep 2020 15:14:09 -0400 Subject: lib: add tracepoint for route table get Signed-off-by: Quentin Young --- lib/table.c | 7 +++++++ lib/trace.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) (limited to 'lib/trace.h') diff --git a/lib/table.c b/lib/table.c index b315637f19..0d1be2beff 100644 --- a/lib/table.c +++ b/lib/table.c @@ -27,6 +27,7 @@ #include "table.h" #include "memory.h" #include "sockunion.h" +#include "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 (tracepoint_enabled(frr_libfrr, route_node_get)) { + char buf[PREFIX2STR_BUFFER]; + prefix2str(pu, buf, sizeof(buf)); + tracepoint(frr_libfrr, route_node_get, table, buf); + } + struct route_node search; struct prefix *p = &search.p; diff --git a/lib/trace.h b/lib/trace.h index 989361e66c..5e0b13a655 100644 --- a/lib/trace.h +++ b/lib/trace.h @@ -39,6 +39,7 @@ #include "thread.h" #include "memory.h" #include "linklist.h" +#include "table.h" /* clang-format off */ @@ -219,6 +220,18 @@ TRACEPOINT_EVENT( ) ) +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 -- cgit v1.2.3 From 912d45a1610dc7ec14017a2d8618ad357e89370e Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 28 Sep 2020 15:49:22 -0400 Subject: lib: move trace.h -> libfrr_trace.h Signed-off-by: Quentin Young --- lib/frr_pthread.c | 2 +- lib/hash.c | 2 +- lib/libfrr_trace.c | 4 + lib/libfrr_trace.h | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/linklist.c | 2 +- lib/memory.c | 2 +- lib/subdir.am | 6 +- lib/table.c | 2 +- lib/thread.c | 2 +- lib/trace.c | 4 - lib/trace.h | 249 ----------------------------------------------------- lib/zlog.c | 2 +- 12 files changed, 263 insertions(+), 263 deletions(-) create mode 100644 lib/libfrr_trace.c create mode 100644 lib/libfrr_trace.h delete mode 100644 lib/trace.c delete mode 100644 lib/trace.h (limited to 'lib/trace.h') diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 82d0c8c49f..689284eb69 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -28,7 +28,7 @@ #include "memory.h" #include "linklist.h" #include "zlog.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, FRR_PTHREAD, "FRR POSIX Thread") DEFINE_MTYPE_STATIC(LIB, PTHREAD_PRIM, "POSIX sync primitives") diff --git a/lib/hash.c b/lib/hash.c index d0dc639229..f34a2aae0b 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -29,7 +29,7 @@ #include "command.h" #include "libfrr.h" #include "frr_pthread.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, HASH, "Hash") DEFINE_MTYPE_STATIC(LIB, HASH_BACKET, "Hash Bucket") 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..337360852c --- /dev/null +++ b/lib/libfrr_trace.h @@ -0,0 +1,249 @@ +/* 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_ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_LTTNG + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER frr_libfrr + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./libfrr_trace.h" + +#include + +#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 +#include + +#else /* HAVE_LTTNG */ + +#define tracepoint(...) +#define tracef(...) +#define tracelog(...) +#define tracepoint_enabled(...) true + +#endif /* HAVE_LTTNG */ + +#endif /* _TRACE_H */ diff --git a/lib/linklist.c b/lib/linklist.c index 19a8514cd6..ea206d89e7 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -23,7 +23,7 @@ #include "linklist.h" #include "memory.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List") DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node") diff --git a/lib/memory.c b/lib/memory.c index 219ddcb638..6bc46b2f30 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -29,7 +29,7 @@ #include "memory.h" #include "log.h" -#include "trace.h" +#include "libfrr_trace.h" static struct memgroup *mg_first = NULL; struct memgroup **mg_insert = &mg_first; diff --git a/lib/subdir.am b/lib/subdir.am index 54fdf429fc..5c371f2cc9 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -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 \ @@ -93,7 +94,6 @@ lib_libfrr_la_SOURCES = \ lib/table.c \ lib/termtable.c \ lib/thread.c \ - lib/trace.c \ lib/typerb.c \ lib/typesafe.c \ lib/vector.c \ @@ -205,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 \ @@ -252,7 +253,6 @@ pkginclude_HEADERS += \ lib/table.h \ lib/termtable.h \ lib/thread.h \ - lib/trace.h \ lib/typerb.h \ lib/typesafe.h \ lib/vector.h \ @@ -413,9 +413,9 @@ lib_clippy_SOURCES = \ lib/command_py.c \ lib/defun_lex.l \ lib/graph.c \ + lib/libfrr_trace.c \ lib/memory.c \ lib/vector.c \ - lib/trace.c \ # end # (global) clippy rules for all directories diff --git a/lib/table.c b/lib/table.c index 0d1be2beff..26bcca4b2b 100644 --- a/lib/table.c +++ b/lib/table.c @@ -27,7 +27,7 @@ #include "table.h" #include "memory.h" #include "sockunion.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_TABLE, "Route table") DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node") diff --git a/lib/thread.c b/lib/thread.c index 8679454367..a15bd541dd 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -35,7 +35,7 @@ #include "frratomic.h" #include "frr_pthread.h" #include "lib_errors.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread") DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master") diff --git a/lib/trace.c b/lib/trace.c deleted file mode 100644 index 7b6c09b387..0000000000 --- a/lib/trace.c +++ /dev/null @@ -1,4 +0,0 @@ -#define TRACEPOINT_CREATE_PROBES -#define TRACEPOINT_DEFINE - -#include "trace.h" diff --git a/lib/trace.h b/lib/trace.h deleted file mode 100644 index 5e0b13a655..0000000000 --- a/lib/trace.h +++ /dev/null @@ -1,249 +0,0 @@ -/* 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(_TRACE_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _TRACE_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#ifdef HAVE_LTTNG - -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER frr_libfrr - -#undef TRACEPOINT_INCLUDE -#define TRACEPOINT_INCLUDE "./trace.h" - -#include - -#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 -#include - -#else /* HAVE_LTTNG */ - -#define tracepoint(...) -#define tracef(...) -#define tracelog(...) -#define tracepoint_enabled(...) true - -#endif /* HAVE_LTTNG */ - -#endif /* _TRACE_H */ diff --git a/lib/zlog.c b/lib/zlog.c index f28ff08617..aec8744b9c 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -52,7 +52,7 @@ #include "printfrr.h" #include "frrcu.h" #include "zlog.h" -#include "trace.h" +#include "libfrr_trace.h" DEFINE_MTYPE_STATIC(LIB, LOG_MESSAGE, "log message") DEFINE_MTYPE_STATIC(LIB, LOG_TLSBUF, "log thread-local buffer") -- cgit v1.2.3 From 552e2a306a3b3335ee60965bbcd61c27eecc576d Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 28 Sep 2020 17:22:53 -0400 Subject: lib: add trace.h, frrtrace(), support for USDT Previous commits added LTTng tracepoints. This was primarily for testing / trial purposes; in practice we'd like to support arbitrary tracing methods, and especially USDT probes, which SystemTap and dtrace expect, and which are supported on at least one flavor of BSD (FreeBSD). To that end this patch adds an frr-specific tracing macro, frrtrace(), which proxies into either DTRACE_PROBEn() or tracepoint() macros depending on whether --enable-usdt or --enable-lttng is passed at compile time. At some point this could be tweaked to allow compiling in both types of probes. Ideally there should be some logic there to use LTTng's optional support for generating USDT probes when both are requested. No additional libraries are required to use USDT, since these probes are a kernel feature and only need the header. - add --enable-usdt to toggle use of LTTng tracepoints or USDT probes - add new trace.h library header for use with tracepoint definition headers - add frrtrace() wrapper macro; this should be used to define tracepoints instead of using tracepoint() or DTRACE_PROBEn() Compilation with USDT does nothing as of this commit; the existing LTTng tracepoints need to be converted to use the frrtrace*() macros in a subsequent commit. Signed-off-by: Quentin Young --- configure.ac | 14 +++++++++++ lib/subdir.am | 1 + lib/trace.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 lib/trace.h (limited to 'lib/trace.h') diff --git a/configure.ac b/configure.ac index 3ed7eabc72..bda9a34504 100755 --- a/configure.ac +++ b/configure.ac @@ -568,6 +568,8 @@ AC_ARG_ENABLE([zeromq], AS_HELP_STRING([--enable-zeromq], [enable ZeroMQ handler (libfrrzmq)])) AC_ARG_ENABLE([lttng], AS_HELP_STRING([--enable-lttng], [enable LTTng tracing])) +AC_ARG_ENABLE([usdt], + AS_HELP_STRING([--enable-usdt], [enable USDT probes])) AC_ARG_WITH([libpam], AS_HELP_STRING([--with-libpam], [use libpam for PAM support in vtysh])) AC_ARG_ENABLE([ospfapi], @@ -1865,6 +1867,18 @@ if test "$enable_lttng" = "yes"; then ]) fi +dnl ---- +dnl USDT +dnl ---- +if test "$enable_usdt" = "yes"; then + AC_CHECK_HEADERS([sys/sdt.h], [ + AC_DEFINE([HAVE_USDT], [1], [Enable USDT probes]) + USDT=true + ], [ + AC_MSG_ERROR([configuration specifies --enable-usdt but no USDT kernel headers (sys/sdt.h) found]) + ]) +fi + dnl ------ dnl ZeroMQ dnl ------ diff --git a/lib/subdir.am b/lib/subdir.am index 5c371f2cc9..ed3c30799d 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -253,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 \ 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_ */ -- cgit v1.2.3