]> git.ipfire.org Git - thirdparty/git.git/blobdiff - trace2/tr2_tgt_event.c
Merge branch 'cm/send-email-document-req-modules' into maint
[thirdparty/git.git] / trace2 / tr2_tgt_event.c
index 1cf4f62441c9307d610ebb0274ddb272ec2b8f01..c2852d1bd2bd856d518b5ce499d38e7b13bb452c 100644 (file)
@@ -6,10 +6,11 @@
 #include "trace2/tr2_dst.h"
 #include "trace2/tr2_tbuf.h"
 #include "trace2/tr2_sid.h"
+#include "trace2/tr2_sysenv.h"
 #include "trace2/tr2_tgt.h"
 #include "trace2/tr2_tls.h"
 
-static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 };
+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };
 
 /*
  * The version number of the JSON data generated by the EVENT target
@@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 };
  * are primarily intended for the performance target during debugging.
  *
  * Some of the outer-most messages, however, may be of interest to the
- * event target.  Set this environment variable to a larger integer for
- * more detail in the event target.
+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase
+ * region details in the event target.
  */
-#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING"
-static int tr2env_event_nesting_wanted = 2;
+static int tr2env_event_max_nesting_levels = 2;
 
 /*
- * Set this environment variable to true to omit the <time>, <file>, and
+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and
  * <line> fields from most events.
  */
-#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF"
-static int tr2env_event_brief;
+static int tr2env_event_be_brief;
 
 static int fn_init(void)
 {
        int want = tr2_dst_trace_want(&tr2dst_event);
-       int want_nesting;
+       int max_nesting;
        int want_brief;
-       char *nesting;
-       char *brief;
+       const char *nesting;
+       const char *brief;
 
        if (!want)
                return want;
 
-       nesting = getenv(TR2_ENVVAR_EVENT_NESTING);
-       if (nesting && ((want_nesting = atoi(nesting)) > 0))
-               tr2env_event_nesting_wanted = want_nesting;
+       nesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);
+       if (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))
+               tr2env_event_max_nesting_levels = max_nesting;
 
-       brief = getenv(TR2_ENVVAR_EVENT_BRIEF);
-       if (brief && ((want_brief = atoi(brief)) > 0))
-               tr2env_event_brief = want_brief;
+       brief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);
+       if (brief && *brief &&
+           ((want_brief = git_parse_maybe_bool(brief)) != -1))
+               tr2env_event_be_brief = want_brief;
 
        return want;
 }
@@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file,
        /*
         * In brief mode, only emit <time> on these 2 event types.
         */
-       if (!tr2env_event_brief || !strcmp(event_name, "version") ||
+       if (!tr2env_event_be_brief || !strcmp(event_name, "version") ||
            !strcmp(event_name, "atexit")) {
-               tr2_tbuf_utc_time(&tb_now);
+               tr2_tbuf_utc_datetime_extended(&tb_now);
                jw_object_string(jw, "time", tb_now.buf);
        }
 
-       if (!tr2env_event_brief && file && *file) {
+       if (!tr2env_event_be_brief && file && *file) {
                jw_object_string(jw, "file", file);
                jw_object_intmax(jw, "line", line);
        }
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)
        jw_release(&jw);
 }
 
-static void fn_start_fl(const char *file, int line, const char **argv)
+static void fn_start_fl(const char *file, int line,
+                       uint64_t us_elapsed_absolute, const char **argv)
 {
        const char *event_name = "start";
        struct json_writer jw = JSON_WRITER_INIT;
+       double t_abs = (double)us_elapsed_absolute / 1000000.0;
 
        jw_object_begin(&jw, 0);
        event_fmt_prepare(event_name, file, line, NULL, &jw);
+       jw_object_double(&jw, "t_abs", 6, t_abs);
        jw_object_inline_begin_array(&jw, "argv");
        jw_array_argv(&jw, argv);
        jw_end(&jw);
@@ -456,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line,
 {
        const char *event_name = "region_enter";
        struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
-       if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
+       if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
                struct json_writer jw = JSON_WRITER_INIT;
 
                jw_object_begin(&jw, 0);
@@ -481,7 +484,7 @@ static void fn_region_leave_printf_va_fl(
 {
        const char *event_name = "region_leave";
        struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
-       if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
+       if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
                struct json_writer jw = JSON_WRITER_INIT;
                double t_rel = (double)us_elapsed_region / 1000000.0;
 
@@ -508,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute,
 {
        const char *event_name = "data";
        struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
-       if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
+       if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
                struct json_writer jw = JSON_WRITER_INIT;
                double t_abs = (double)us_elapsed_absolute / 1000000.0;
                double t_rel = (double)us_elapsed_region / 1000000.0;
@@ -536,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line,
 {
        const char *event_name = "data_json";
        struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
-       if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
+       if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
                struct json_writer jw = JSON_WRITER_INIT;
                double t_abs = (double)us_elapsed_absolute / 1000000.0;
                double t_rel = (double)us_elapsed_region / 1000000.0;