diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit c62231a33c4a18e54b2885a81b973ead9edba716
parent 192a00e467b195ff46a0e86491fbd8e0cfe82374
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sun, 26 Jun 2022 20:34:41 +0200

feat(lttng): add debug_date event

Diffstat:
MMakefile | 21+++++++++++++--------
Asrc/diary-tp.c | 5+++++
Asrc/diary-tp.h | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/diary.c | 2+-
Msrc/diary.h | 5+----
Dsrc/lttng/diary-tp.c | 4----
Dsrc/lttng/diary-tp.h | 58----------------------------------------------------------
Msrc/utils.c | 2+-
Msrc/utils.h | 2++
9 files changed, 97 insertions(+), 76 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ TARGET = diary SRCDIR = src/ -_SRC = export.c import.c utils.c caldav.c diary.c +_SRC = diary-tp.c export.c import.c utils.c caldav.c diary.c SRC = $(addprefix $(SRCDIR), $(_SRC)) PREFIX ?= /usr/local BINDIR ?= $(DESTDIR)$(PREFIX)/bin @@ -15,34 +15,39 @@ CFLAGS = -Wall \ UNAME = ${shell uname} ifeq ($(UNAME),FreeBSD) - LIBS = -lncurses -lcurl -ldl -pthread + LIBS = -lncurses -lcurl -ldl -llttng-ust -pthread endif ifeq ($(UNAME),Linux) - LIBS = -lncursesw -lcurl -ldl -pthread + LIBS = -lncursesw -lcurl -ldl -llttng-ust -pthread endif ifeq ($(UNAME),Darwin) - LIBS = -lncurses -lcurl -ldl -pthread -framework CoreFoundation + LIBS = -lncurses -lcurl -ldl -llttng-ust -pthread -framework CoreFoundation endif default: $(TARGET) $(TARGET): $(SRC) - $(CC) $(SRC) -o $(TARGET) $(CFLAGS) $(LIBS) + @# -I: Search this dir for header files (required for lttng) + $(CC) -I $(SRCDIR) $(SRC) -o $(TARGET) $(CFLAGS) $(LIBS) debug: $(SRC) lttng - $(CC) $(SRC) -o $(TARGET) $(CFLAGS) -g $(LIBS) + @# -g: Produce debugging information (for GDB) + $(CC) -I $(SRCDIR) $(SRC) -o $(TARGET) $(CFLAGS) -g $(LIBS) # The tracepoint provider package shared object can be # preloaded before the instrumented application starts. # https://lttng.org/docs/v2.13/#doc-building-tracepoint-providers-and-user-application -lttng: $(SRC) - $(CC) -I "$(SRCDIR)/lttng" -fpic -c $(SRCDIR)/lttng/diary-tp.c +lttng: + @# -fpic: Generate position-independent code (PIC) suitable for shared library + $(CC) -I $(SRCDIR) -fpic -c $(SRCDIR)/diary-tp.c + @# create shared object file (.so) $(CC) -shared -o libtpp.so diary-tp.o -llttng-ust -ldl clean: + @# cleanup target and lttng shared object file rm -f $(TARGET) libtpp.so diary-tp.o install: $(TARGET) diff --git a/src/diary-tp.c b/src/diary-tp.c @@ -0,0 +1,5 @@ +#define TRACEPOINT_CREATE_PROBES +#define TRACEPOINT_DEFINE +#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE + +#include "diary-tp.h" diff --git a/src/diary-tp.h b/src/diary-tp.h @@ -0,0 +1,74 @@ +// LTTng 2.13 prepends the lttng_ust_ and LTTNG_UST_ prefix to all names +// to offer a consistent API namespace. Prefer the pre 2.13 behavior (API v0). +#define LTTNG_UST_COMPAT_API_VERSION 0 + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER diary + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "diary-tp.h" + +#if !defined(_DIARY_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _DIARY_TP_H + +#include <time.h> +#include <lttng/tracepoint.h> + +// Instrument a C user application +// https://lttng.org/docs/v2.13/#doc-c-application +TRACEPOINT_EVENT( + /* Tracepoint provider name */ + diary, + + /* Tracepoint name */ + debug, + + /* Input arguments */ + TP_ARGS( + char*, msg_arg + ), + + /* Output event fields */ + TP_FIELDS( + ctf_string(msg, msg_arg) + ) +) + +TRACEPOINT_EVENT( + diary, + debug_date, + TP_ARGS( + char*, msg_arg, + const struct tm*, date_arg + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_string(date_arg, asctime(date_arg)) + ) +) + +TRACEPOINT_EVENT( + diary, + warning, + TP_ARGS( + char*, msg_arg, + char*, arg1 + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_string(arg1, arg1) + ) +) + +/* Log level assignment */ +// TRACE_ERR +// TRACE_WARNING +// TRACE_INFO +// TRACE_DEBUG_LINE (default) +TRACEPOINT_LOGLEVEL(diary, debug, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(diary, debug_date, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(diary, warning, TRACE_WARNING) + +#endif /* _DIARY_TP_H */ + +#include <lttng/tracepoint-event.h> diff --git a/src/diary.c b/src/diary.c @@ -760,7 +760,7 @@ int main(int argc, char** argv) { // get file path of entry and delete entry fpath(CONFIG.dir, diary_dir_size, &curs_date, &ppth, sizeof pth); if (ppth == NULL) { - fprintf(stderr, "Error retrieving file path for entry removal"); + tracepoint(diary, debug_date, "Error retrieving file path for entry", &curs_date); break; } diff --git a/src/diary.h b/src/diary.h @@ -25,10 +25,7 @@ #include "import.h" #include "export.h" #include "caldav.h" - -#define TRACEPOINT_DEFINE -#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE -#include "lttng/diary-tp.h" +#include "diary-tp.h" #define XDG_CONFIG_HOME_FALLBACK "~/.config" #define CONFIG_FILE_PATH "diary/diary.cfg" diff --git a/src/lttng/diary-tp.c b/src/lttng/diary-tp.c @@ -1,4 +0,0 @@ -#define TRACEPOINT_CREATE_PROBES -#define TRACEPOINT_DEFINE - -#include "diary-tp.h" diff --git a/src/lttng/diary-tp.h b/src/lttng/diary-tp.h @@ -1,58 +0,0 @@ -// LTTng 2.13 prepends the lttng_ust_ and LTTNG_UST_ prefix to all names -// to offer a consistent API namespace. Prefer the pre 2.13 behavior (API v0). -#define LTTNG_UST_COMPAT_API_VERSION 0 - -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER diary - -#undef TRACEPOINT_INCLUDE -#define TRACEPOINT_INCLUDE "diary-tp.h" - -#if !defined(_DIARY_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _DIARY_TP_H - -#include <lttng/tracepoint.h> - -// Instrument a C user application -// https://lttng.org/docs/v2.13/#doc-c-application -TRACEPOINT_EVENT( - /* Tracepoint provider name */ - diary, - - /* Tracepoint name */ - debug, - - /* Input arguments */ - TP_ARGS( - char *, msg_arg - ), - - /* Output event fields */ - TP_FIELDS( - ctf_string(msg, msg_arg) - ) -) - -TRACEPOINT_EVENT( - diary, - warning, - TP_ARGS( - char *, msg_arg, - char *, arg1 - ), - TP_FIELDS( - ctf_string(msg, msg_arg) - ctf_string(arg1, arg1) - ) -) - -/* Log level assignment */ -// TRACE_ERR -// TRACE_WARNING -// TRACE_INFO -// TRACE_DEBUG_LINE (default) -TRACEPOINT_LOGLEVEL(diary, warning, TRACE_WARNING) - -#endif /* _DIARY_TP_H */ - -#include <lttng/tracepoint-event.h> diff --git a/src/utils.c b/src/utils.c @@ -20,7 +20,7 @@ bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i) { fpath(dir, dir_size, i, &pepath, sizeof epath); if (pepath == NULL) { - fprintf(stderr, "Error retrieving file path for entry"); + tracepoint(diary, debug_date, "Error retrieving file path for entry", i); return false; } diff --git a/src/utils.h b/src/utils.h @@ -11,6 +11,8 @@ #include <stdbool.h> #include <ncurses.h> +#include "diary-tp.h" + #define GOOGLE_OAUTH_TOKEN_FILE "~/.diary-token" #ifndef GOOGLE_OAUTH_CLIENT_ID #define GOOGLE_OAUTH_CLIENT_ID ""