Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: JSON based telemetry #11

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,4 @@
*.pdb
/Debug/
/Release/
*.so
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ all::
#
# Define NEEDS_LIBGEN if your libgen needs -lgen when linking
#
# Define NEEDS_LIBDL if you need -ldl to get dlopen().
#
# Define NO_SYS_SELECT_H if you don't have sys/select.h.
#
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
Expand Down Expand Up @@ -662,6 +664,7 @@ TEST_PROGRAMS_NEED_X += test-fake-ssh
TEST_PROGRAMS_NEED_X += test-genrandom
TEST_PROGRAMS_NEED_X += test-hashmap
TEST_PROGRAMS_NEED_X += test-index-version
TEST_PROGRAMS_NEED_X += test-json-writer
TEST_PROGRAMS_NEED_X += test-lazy-init-name-hash
TEST_PROGRAMS_NEED_X += test-line-buffer
TEST_PROGRAMS_NEED_X += test-match-trees
Expand Down Expand Up @@ -815,6 +818,7 @@ LIB_OBJS += hashmap.o
LIB_OBJS += help.o
LIB_OBJS += hex.o
LIB_OBJS += ident.o
LIB_OBJS += json-writer.o
LIB_OBJS += kwset.o
LIB_OBJS += levenshtein.o
LIB_OBJS += line-log.o
Expand Down Expand Up @@ -899,6 +903,9 @@ LIB_OBJS += submodule-config.o
LIB_OBJS += sub-process.o
LIB_OBJS += symlinks.o
LIB_OBJS += tag.o
LIB_OBJS += telemetry.o
LIB_OBJS += telemetry-perf.o
LIB_OBJS += telemetry-plugin.o
LIB_OBJS += tempfile.o
LIB_OBJS += tmp-objdir.o
LIB_OBJS += trace.o
Expand Down Expand Up @@ -1303,6 +1310,9 @@ endif
ifdef NEEDS_LIBGEN
EXTLIBS += -lgen
endif
ifdef NEEDS_LIBDL
EXTLIBS += -ldl
endif
ifndef NO_GETTEXT
ifndef LIBC_CONTAINS_LIBINTL
EXTLIBS += -lintl
Expand Down
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "path.h"
#include "sha1-array.h"
#include "repository.h"
#include "json-writer.h"
#include "telemetry.h"
#include "telemetry-perf.h"

#ifndef platform_SHA_CTX
/*
Expand Down
2 changes: 1 addition & 1 deletion compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static inline int fcntl(int fd, int cmd, ...)
return -1;
}
/* bash cannot reliably detect negative return codes as failure */
#define exit(code) exit((code) & 0xff)
#define exit(code) exit(telemetry_exit((code) & 0xff))
#define sigemptyset(x) (void)0
static inline int sigaddset(sigset_t *set, int signum)
{ return 0; }
Expand Down
1 change: 1 addition & 0 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ifeq ($(uname_S),Linux)
HAVE_CLOCK_MONOTONIC = YesPlease
# -lrt is needed for clock_gettime on glibc <= 2.16
NEEDS_LIBRT = YesPlease
NEEDS_LIBDL = YesPlease
HAVE_GETDELIM = YesPlease
SANE_TEXT_GREP=-a
FREAD_READS_DIRECTORIES = UnfortunatelyYes
Expand Down
7 changes: 7 additions & 0 deletions contrib/telemetry-plugin-examples/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory contains some example telemetry plugins.
These are built as shared libraries and installed in a
known location.

Users can set "telemetry.plugin" to the absolute path
of the .so or .dll and have telemetry events routed to
the plugin.
3 changes: 3 additions & 0 deletions contrib/telemetry-plugin-examples/trivial-stderr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all: Makefile *.c
gcc -c -Wall -Werror -fpic trivial-stderr.c
gcc -shared -o trivial-stderr.so trivial-stderr.o
20 changes: 20 additions & 0 deletions contrib/telemetry-plugin-examples/trivial-stderr/trivial-stderr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>

/*
* Initialize any private data.
*
* Return 1 if we can emit events and have a consumer.
*/
int plugin_initialize(void)
{
return 1;
}

/*
* Emit the given json string as an event.
*/
void plugin_event(const char *json, int is_final_event)
{
fprintf(stderr, "%s\n", json);
fflush(stderr);
}
9 changes: 9 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1214,4 +1214,13 @@ extern void unleak_memory(const void *ptr, size_t len);
#define UNLEAK(var) do {} while (0)
#endif

/*
* Intercept exit() so that we can catch the exit-code and generate
* telememtry data.
*/
#ifndef exit
int telemetry_exit_event(int exit_code);
#define exit(code) exit(telemetry_exit_event(code))
#endif

#endif
5 changes: 4 additions & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static int handle_alias(int *argcp, const char ***argv)
child.use_shell = 1;
argv_array_push(&child.args, alias_string + 1);
argv_array_pushv(&child.args, (*argv) + 1);
child.is_alias_expansion = 1;

ret = run_command(&child);
if (ret >= 0) /* normal exit */
Expand Down Expand Up @@ -572,6 +573,7 @@ static void execv_dashed_external(const char **argv)
cmd.clean_on_exit = 1;
cmd.wait_after_clean = 1;
cmd.silent_exec_failure = 1;
cmd.is_alias_expansion = 1;

trace_argv_printf(cmd.args.argv, "trace: exec:");

Expand Down Expand Up @@ -636,6 +638,7 @@ int cmd_main(int argc, const char **argv)
cmd = slash + 1;
}

telemetry_start_event(argc, argv);
trace_command_performance(argv);

/*
Expand Down Expand Up @@ -699,5 +702,5 @@ int cmd_main(int argc, const char **argv)
fprintf(stderr, "Failed to run command '%s': %s\n",
cmd, strerror(errno));

return 1;
return telemetry_exit_event(1);
}
Loading