doc/examples/gen-tp/sample
doc/examples/gen-tp/sample_tracepoint.h
doc/examples/demo-tracef/demo-tracef
+doc/examples/demo-tracef/demo-vtracef
doc/examples/demo-tracelog/demo-tracelog
doc/examples/cmake-multiple-shared-libraries/build/
LOCAL_CPPFLAGS += -I.
AM_V_P := :
-all: demo-tracef
+all: demo-tracef demo-vtracef
demo-tracef.o: demo-tracef.c
@if $(AM_V_P); then set -x; else echo " CC $@"; fi; \
$(CC) $(LDFLAGS) $(AM_CFLAGS) $(AM_LDFLAGS) $(CFLAGS) \
-o $@ $< $(LIBS)
+demo-vtracef.o: demo-vtracef.c
+ @if $(AM_V_P); then set -x; else echo " CC $@"; fi; \
+ $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(AM_CFLAGS) $(AM_CPPFLAGS) \
+ $(CFLAGS) -c -o $@ $<
+
+demo-vtracef: demo-vtracef.o
+ @if $(AM_V_P); then set -x; else echo " CCLD $@"; fi; \
+ $(CC) $(LDFLAGS) $(AM_CFLAGS) $(AM_LDFLAGS) $(CFLAGS) \
+ -o $@ $< $(LIBS)
+
.PHONY: clean
clean:
- rm -f *.o *.a demo-tracef
+ rm -f *.o *.a demo-tracef demo-vtracef
--- /dev/null
+/*
+ * Copyright (C) 2020 Maxime Roussin-Belanger <maxime.roussinbelanger@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1 of
+ * the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <lttng/tracef.h>
+
+void print_debug(const char* msg, ...)
+{
+ va_list ap;
+
+ va_start(ap, msg);
+ vtracef(msg, ap);
+ va_end(ap);
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+ int delay = 0;
+ const char *str = "mystring test";
+ long l = 0x42;
+
+ if (argc > 2)
+ delay = atoi(argv[1]);
+
+ fprintf(stderr, "Demo program starting.\n");
+
+ sleep(delay);
+
+ fprintf(stderr, "Tracing... ");
+
+ for (i = 0; i < 5; i++) {
+ print_debug("This is a \"%s\" formatted %d event %lx", str, i, l);
+ }
+
+ fprintf(stderr, " done.\n");
+ return 0;
+}
should not be considered for any permanent/serious application
instrumentation.
++v{macro-name}()+ does not have a `STAP_PROBEV()` call, because `STAP_PROBEV()`
+does not support `va_list`. If you need it, you should emit this call yourself.
+
See man:lttng-ust(3) to learn more about custom tracepoint providers.
NAME
----
-tracef - LTTng-UST printf(3)-like interface
+tracef, vtracef - LTTng-UST printf(3)-like interface
SYNOPSIS
[verse]
#define *tracef*('fmt', ...)
+#define *vtracef*('fmt', 'va_list' ap)
Link with `-llttng-ust`.
passed directly to the 'fmt' parameter of man:vasprintf(3), as well as
the optional parameters following 'fmt'.
-To use `tracef()`, include `<lttng/tracef.h>` where you need it, and
-link your application with `liblttng-ust`. See the <<example,EXAMPLE>>
+To use `tracef()` or `vtracef()`, include `<lttng/tracef.h>` where you need it,
+and link your application with `liblttng-ust`. See the <<example,EXAMPLE>>
section below for a complete usage example.
-Once your application is instrumented with `tracef()` calls and
+Once your application is instrumented with `tracef()` or `vtracef()` calls and
ready to run, use man:lttng-enable-event(1) to enable the
`lttng_ust_tracef:*` event.
man:tracelog(3) instead.
See also the <<limitations,LIMITATIONS>> section below for important
-limitations to consider when using `tracef()`.
+limitations to consider when using `tracef()` or `vtracef()`.
[[example]]
extern
void _lttng_ust_tracef(const char *fmt, ...);
+extern
+void _lttng_ust_vtracef(const char *fmt, va_list ap);
+
#define tracef(fmt, ...) \
do { \
LTTNG_STAP_PROBEV(tracepoint_lttng_ust_tracef, event, ## __VA_ARGS__); \
_lttng_ust_tracef(fmt, ## __VA_ARGS__); \
} while (0)
+#define vtracef(fmt, ap) \
+ do { \
+ if (caa_unlikely(__tracepoint_lttng_ust_tracef___event.state)) \
+ _lttng_ust_vtracef(fmt, ap); \
+ } while (0)
#ifdef __cplusplus
}
#endif
#define TRACEPOINT_DEFINE
#include "lttng-ust-tracef-provider.h"
-void _lttng_ust_tracef(const char *fmt, ...)
+static inline __attribute__((always_inline))
+void __lttng_ust_vtracef(const char *fmt, va_list ap)
{
- va_list ap;
char *msg;
- int len;
+ const int len = vasprintf(&msg, fmt, ap);
- va_start(ap, fmt);
- len = vasprintf(&msg, fmt, ap);
/* len does not include the final \0 */
if (len < 0)
goto end;
LTTNG_UST_CALLER_IP());
free(msg);
end:
+ return;
+}
+
+void _lttng_ust_vtracef(const char *fmt, va_list ap)
+{
+ __lttng_ust_vtracef(fmt, ap);
+}
+
+void _lttng_ust_tracef(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ __lttng_ust_vtracef(fmt, ap);
va_end(ap);
}