From e8b9309c5d822c9f6a3ce7188c17f0e23b41327b Mon Sep 17 00:00:00 2001
From: Olivier Dion <olivier.dion@savoirfairelinux.com>
Date: Fri, 10 Dec 2021 12:51:23 -0500
Subject: [PATCH] tracepoint: Add LTTng tracepoint generation

Change-Id: I6358f3ab5f464f1a553814c58b22245ef64f0b52
---
 src/Makefile.am           |  5 ++++
 src/jami/tracepoint-def.h | 26 +++++++++++++++++
 src/jami/tracepoint.c     |  3 ++
 src/jami/tracepoint.h     | 60 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+)
 create mode 100644 src/jami/tracepoint-def.h
 create mode 100644 src/jami/tracepoint.c
 create mode 100644 src/jami/tracepoint.h

diff --git a/src/Makefile.am b/src/Makefile.am
index b83726a94f..64195d1636 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -161,3 +161,8 @@ if ENABLE_VIDEO
 nobase_include_HEADERS += \
 		./jami/videomanager_interface.h
 endif
+
+if ENABLE_TRACEPOINTS
+libring_la_SOURCES += jami/tracepoint.h jami/tracepoint-def.h jami/tracepoint.c
+libring_la_LIBADD  += $(LTTNG_LIBS)
+endif
diff --git a/src/jami/tracepoint-def.h b/src/jami/tracepoint-def.h
new file mode 100644
index 0000000000..47ac84aa35
--- /dev/null
+++ b/src/jami/tracepoint-def.h
@@ -0,0 +1,26 @@
+#include "config.h"
+
+#ifdef ENABLE_TRACEPOINTS
+
+#undef LTTNG_UST_TRACEPOINT_PROVIDER
+#define LTTNG_UST_TRACEPOINT_PROVIDER jami
+
+#undef LTTNG_UST_TRACEPOINT_INCLUDE
+#define LTTNG_UST_TRACEPOINT_INCLUDE "src/jami/tracepoint-def.h"
+
+#if !defined(TRACEPOINT_DEF_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
+#define TRACEPOINT_DEF_H
+
+#include <lttng/tracepoint.h>
+
+/*
+ * Use LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(),
+ * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), and LTTNG_UST_TRACEPOINT_LOGLEVEL()
+ * here.
+ */
+
+#endif /* TRACEPOINT_H */
+
+#include <lttng/tracepoint-event.h>
+
+#endif
diff --git a/src/jami/tracepoint.c b/src/jami/tracepoint.c
new file mode 100644
index 0000000000..392fb0e92a
--- /dev/null
+++ b/src/jami/tracepoint.c
@@ -0,0 +1,3 @@
+#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
+#define LTTNG_UST_TRACEPOINT_DEFINE
+#include "./tracepoint.h"
diff --git a/src/jami/tracepoint.h b/src/jami/tracepoint.h
new file mode 100644
index 0000000000..266ecb55fd
--- /dev/null
+++ b/src/jami/tracepoint.h
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ *  Author: Olivier Dion <olivier.dion@savoirfairelinux.com>
+ *
+ *  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 3 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; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#pragma once
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#include "tracepoint-def.h"
+#pragma GCC diagnostic pop
+
+#ifdef ENABLE_TRACEPOINTS
+
+#  ifndef lttng_ust_tracepoint
+#    define lttng_ust_tracepoint(...) tracepoint(__VA_ARGS__)
+#  endif
+
+#  ifndef lttng_ust_do_tracepoint
+#    define lttng_ust_do_tracepoint(...) do_tracepoint(__VA_ARGS__)
+#  endif
+
+#  ifndef lttng_ust_tracepoint_enabled
+#    define lttng_ust_tracepoint_enabled(...) tracepoint_enabled(__VA_ARGS__)
+#  endif
+
+#  define jami_tracepoint(tp_name, ...)                                 \
+        lttng_ust_tracepoint(jami, tp_name __VA_OPT__(,) __VA_ARGS__)
+
+#  define jami_tracepoint_if_enabled(tp_name, ...)                      \
+        do {                                                            \
+                if (lttng_ust_tracepoint_enabled(jami, tp_name)) {      \
+                        lttng_ust_do_tracepoint(jami,                   \
+                                                tp_name                 \
+                                                __VA_OPT__(,)           \
+                                                __VA_ARGS__);           \
+                }                                                       \
+        }                                                               \
+        while (0)
+
+#else
+
+#  define jami_tracepoint(...)            static_assert(true)
+#  define jami_tracepoint_if_enabled(...) static_assert(true)
+
+#endif
-- 
GitLab