6
#include "trace2/tr2_dst.h"
7
#include "trace2/tr2_tbuf.h"
8
#include "trace2/tr2_sid.h"
9
+#include "trace2/tr2_sysenv.h"
10
#include "trace2/tr2_tgt.h"
11
#include "trace2/tr2_tls.h"
12
12
-static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 };
13
+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };
14
15
/*
16
* The version number of the JSON data generated by the EVENT target
29
* are primarily intended for the performance target during debugging.
30
*
31
* Some of the outer-most messages, however, may be of interest to the
31
- * event target. Set this environment variable to a larger integer for
32
- * more detail in the event target.
32
+ * event target. Use the TR2_SYSENV_EVENT_NESTING setting to increase
33
+ * region details in the event target.
34
*/
34
-#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING"
35
-static int tr2env_event_nesting_wanted = 2;
35
+static int tr2env_event_max_nesting_levels = 2;
36
37
/*
38
- * Set this environment variable to true to omit the <time>, <file>, and
38
+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and
39
* <line> fields from most events.
40
*/
41
-#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF"
42
-static int tr2env_event_brief;
41
+static int tr2env_event_be_brief;
42
43
static int fn_init(void)
44
{
45
int want = tr2_dst_trace_want(&tr2dst_event);
47
- int want_nesting;
46
+ int max_nesting;
47
int want_brief;
49
- char *nesting;
50
- char *brief;
48
+ const char *nesting;
49
+ const char *brief;
50
51
if (!want)
52
return want;
53
55
- nesting = getenv(TR2_ENVVAR_EVENT_NESTING);
56
- if (nesting && ((want_nesting = atoi(nesting)) > 0))
57
- tr2env_event_nesting_wanted = want_nesting;
54
+ nesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);
55
+ if (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))
56
+ tr2env_event_max_nesting_levels = max_nesting;
57
59
- brief = getenv(TR2_ENVVAR_EVENT_BRIEF);
60
- if (brief && ((want_brief = atoi(brief)) > 0))
61
- tr2env_event_brief = want_brief;
58
+ brief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);
59
+ if (brief && *brief &&
60
+ ((want_brief = git_parse_maybe_bool(brief)) != -1))
61
+ tr2env_event_be_brief = want_brief;
62
63
return want;
64
}
92
/*
93
* In brief mode, only emit <time> on these 2 event types.
94
*/
95
- if (!tr2env_event_brief || !strcmp(event_name, "version") ||
95
+ if (!tr2env_event_be_brief || !strcmp(event_name, "version") ||
96
!strcmp(event_name, "atexit")) {
97
tr2_tbuf_utc_time(&tb_now);
98
jw_object_string(jw, "time", tb_now.buf);
99
}
100
101
- if (!tr2env_event_brief && file && *file) {
101
+ if (!tr2env_event_be_brief && file && *file) {
102
jw_object_string(jw, "file", file);
103
jw_object_intmax(jw, "line", line);
104
}
459
{
460
const char *event_name = "region_enter";
461
struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
462
- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
462
+ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
463
struct json_writer jw = JSON_WRITER_INIT;
464
465
jw_object_begin(&jw, 0);
484
{
485
const char *event_name = "region_leave";
486
struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
487
- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
487
+ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
488
struct json_writer jw = JSON_WRITER_INIT;
489
double t_rel = (double)us_elapsed_region / 1000000.0;
490
511
{
512
const char *event_name = "data";
513
struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
514
- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
514
+ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
515
struct json_writer jw = JSON_WRITER_INIT;
516
double t_abs = (double)us_elapsed_absolute / 1000000.0;
517
double t_rel = (double)us_elapsed_region / 1000000.0;
539
{
540
const char *event_name = "data_json";
541
struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
542
- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
542
+ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
543
struct json_writer jw = JSON_WRITER_INIT;
544
double t_abs = (double)us_elapsed_absolute / 1000000.0;
545
double t_rel = (double)us_elapsed_region / 1000000.0;