Skip to content

Commit

Permalink
core: use env variable instead of config var to turn on logging pack …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pclouds authored and gitster committed Jun 9, 2013
1 parent edca415 commit b12ca96
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,13 @@ for further details.
as a file path and will try to write the trace messages
into it.

'GIT_TRACE_PACK_ACCESS'::
If this variable is set to a path, a file will be created at
the given path logging all accesses to any packs. For each
access, the pack file name and an offset in the pack is
recorded. This may be helpful for troubleshooting some
pack-related performance problems.

GIT_LITERAL_PATHSPECS::
Setting this variable to `1` will cause Git to treat all
pathspecs literally, rather than as glob patterns. For example,
Expand Down
3 changes: 0 additions & 3 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,6 @@ extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
/* global flag to enable extra checks when accessing packed objects */
extern int do_check_packed_object_crc;

/* for development: log offset of pack access */
extern const char *log_pack_access;

extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);

extern int move_temp_to_file(const char *tmpfile, const char *filename);
Expand Down
3 changes: 0 additions & 3 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,6 @@ static int git_default_core_config(const char *var, const char *value)
return 0;
}

if (!strcmp(var, "core.logpackaccess"))
return git_config_string(&log_pack_access, var, value);

if (!strcmp(var, "core.autocrlf")) {
if (value && !strcasecmp(value, "input")) {
if (core_eol == EOL_CRLF)
Expand Down
1 change: 0 additions & 1 deletion environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
size_t delta_base_cache_limit = 16 * 1024 * 1024;
unsigned long big_file_threshold = 512 * 1024 * 1024;
const char *log_pack_access;
const char *pager_program;
int pager_use_color = 1;
const char *editor_program;
Expand Down
14 changes: 12 additions & 2 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }

const unsigned char null_sha1[20];

static const char *no_log_pack_access = "no_log_pack_access";
static const char *log_pack_access;

/*
* This is meant to hold a *small* number of objects that you would
* want read_sha1_file() to be able to return, but yet you do not want
Expand Down Expand Up @@ -1956,12 +1959,19 @@ static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
{
static FILE *log_file;

if (!log_pack_access)
log_pack_access = getenv("GIT_TRACE_PACK_ACCESS");
if (!log_pack_access)
log_pack_access = no_log_pack_access;
if (log_pack_access == no_log_pack_access)
return;

if (!log_file) {
log_file = fopen(log_pack_access, "w");
if (!log_file) {
error("cannot open pack access log '%s' for writing: %s",
log_pack_access, strerror(errno));
log_pack_access = NULL;
log_pack_access = no_log_pack_access;
return;
}
}
Expand Down Expand Up @@ -1992,7 +2002,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
int base_from_cache = 0;

if (log_pack_access)
if (log_pack_access != no_log_pack_access)
write_pack_access_log(p, obj_offset);

/* PHASE 1: drill down to the innermost base object */
Expand Down

0 comments on commit b12ca96

Please sign in to comment.