core: use env variable instead of config var to turn on logging pack access

5f44324 (core: log offset pack data accesses happened - 2011-07-06) provides a way to observe pack access patterns via a config switch. Setting an environment variable looks more obvious than a config var, especially when you just need to _observe_, and more inline with other tracing knobs we have. Document it as it may be useful for remote troubleshooting. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 9, 2013 at 12:22 UTC b12ca9631f86adc35b0c03fb5b792cd82c288288
5 files changed +19 -9
Documentation/git.txt
+7
@@ -832,6 +832,13 @@ for further details.
832 as a file path and will try to write the trace messages
833 into it.
834
835 +'GIT_TRACE_PACK_ACCESS'::
836 + If this variable is set to a path, a file will be created at
837 + the given path logging all accesses to any packs. For each
838 + access, the pack file name and an offset in the pack is
839 + recorded. This may be helpful for troubleshooting some
840 + pack-related performance problems.
841 +
842 GIT_LITERAL_PATHSPECS::
843 Setting this variable to `1` will cause Git to treat all
844 pathspecs literally, rather than as glob patterns. For example,
cache.h
-3
@@ -772,9 +772,6 @@ extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
772 /* global flag to enable extra checks when accessing packed objects */
773 extern int do_check_packed_object_crc;
774
775 -/* for development: log offset of pack access */
776 -extern const char *log_pack_access;
777 -
775 extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
776
777 extern int move_temp_to_file(const char *tmpfile, const char *filename);
config.c
-3
@@ -675,9 +675,6 @@ static int git_default_core_config(const char *var, const char *value)
675 return 0;
676 }
677
678 - if (!strcmp(var, "core.logpackaccess"))
679 - return git_config_string(&log_pack_access, var, value);
680 -
678 if (!strcmp(var, "core.autocrlf")) {
679 if (value && !strcasecmp(value, "input")) {
680 if (core_eol == EOL_CRLF)
environment.c
-1
@@ -37,7 +37,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
37 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
38 size_t delta_base_cache_limit = 16 * 1024 * 1024;
39 unsigned long big_file_threshold = 512 * 1024 * 1024;
40 -const char *log_pack_access;
40 const char *pager_program;
41 int pager_use_color = 1;
42 const char *editor_program;
sha1_file.c
+12 -2
@@ -36,6 +36,9 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
36
37 const unsigned char null_sha1[20];
38
39 +static const char *no_log_pack_access = "no_log_pack_access";
40 +static const char *log_pack_access;
41 +
42 /*
43 * This is meant to hold a *small* number of objects that you would
44 * want read_sha1_file() to be able to return, but yet you do not want
@@ -1956,12 +1959,19 @@ static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
1959 {
1960 static FILE *log_file;
1961
1962 + if (!log_pack_access)
1963 + log_pack_access = getenv("GIT_TRACE_PACK_ACCESS");
1964 + if (!log_pack_access)
1965 + log_pack_access = no_log_pack_access;
1966 + if (log_pack_access == no_log_pack_access)
1967 + return;
1968 +
1969 if (!log_file) {
1970 log_file = fopen(log_pack_access, "w");
1971 if (!log_file) {
1972 error("cannot open pack access log '%s' for writing: %s",
1973 log_pack_access, strerror(errno));
1964 - log_pack_access = NULL;
1974 + log_pack_access = no_log_pack_access;
1975 return;
1976 }
1977 }
@@ -1992,7 +2002,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2002 int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
2003 int base_from_cache = 0;
2004
1995 - if (log_pack_access)
2005 + if (log_pack_access != no_log_pack_access)
2006 write_pack_access_log(p, obj_offset);
2007
2008 /* PHASE 1: drill down to the innermost base object */