git/trace2/tr2_sysenv.h
Josh Steadmon 83e57b04e6 trace2: discard new traces if target directory has too many files
trace2 can write files into a target directory. With heavy usage, this
directory can fill up with files, causing difficulty for
trace-processing systems.

This patch adds a config option (trace2.maxFiles) to set a maximum
number of files that trace2 will write to a target directory. The
following behavior is enabled when the maxFiles is set to a positive
integer:
  When trace2 would write a file to a target directory, first check
  whether or not the traces should be discarded. Traces should be
  discarded if:
    * there is a sentinel file declaring that there are too many files
    * OR, the number of files exceeds trace2.maxFiles.
  In the latter case, we create a sentinel file named git-trace2-discard
  to speed up future checks.

The assumption is that a separate trace-processing system is dealing
with the generated traces; once it processes and removes the sentinel
file, it should be safe to generate new trace files again.

The default value for trace2.maxFiles is zero, which disables the file
count check.

The config can also be overridden with a new environment variable:
GIT_TRACE2_MAX_FILES.

Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-10-05 17:53:51 +09:00

39 lines
834 B
C

#ifndef TR2_SYSENV_H
#define TR2_SYSENV_H
/*
* The Trace2 settings that can be loaded from /etc/gitconfig
* and/or user environment variables.
*
* Note that this set does not contain any of the transient
* environment variables used to pass information from parent
* to child git processes, such "GIT_TRACE2_PARENT_SID".
*/
enum tr2_sysenv_variable {
TR2_SYSENV_CFG_PARAM = 0,
TR2_SYSENV_DST_DEBUG,
TR2_SYSENV_NORMAL,
TR2_SYSENV_NORMAL_BRIEF,
TR2_SYSENV_EVENT,
TR2_SYSENV_EVENT_BRIEF,
TR2_SYSENV_EVENT_NESTING,
TR2_SYSENV_PERF,
TR2_SYSENV_PERF_BRIEF,
TR2_SYSENV_MAX_FILES,
TR2_SYSENV_MUST_BE_LAST
};
void tr2_sysenv_load(void);
const char *tr2_sysenv_get(enum tr2_sysenv_variable);
const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);
void tr2_sysenv_release(void);
#endif /* TR2_SYSENV_H */