Skip to content

Commit

Permalink
core: log offset pack data accesses happened
Browse files Browse the repository at this point in the history
In a workload other than "git log" (without pathspec nor any option that
causes us to inspect trees and blobs), the recency pack order is said to
cause the access jump around quite a bit. Add a hook to allow us observe
how bad it is.

"git config core.logpackaccess /var/tmp/pal.txt" will give you the log
in the specified file.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jul 7, 2011
1 parent 033c2dc commit 5f44324
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime);
/* 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: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ 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: 1 addition & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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
21 changes: 21 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,24 @@ static void *unpack_delta_entry(struct packed_git *p,
return result;
}

static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
{
static FILE *log_file;

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;
return;
}
}
fprintf(log_file, "%s %"PRIuMAX"\n",
p->pack_name, (uintmax_t)obj_offset);
fflush(log_file);
}

int do_check_packed_object_crc;

void *unpack_entry(struct packed_git *p, off_t obj_offset,
Expand All @@ -1848,6 +1866,9 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
off_t curpos = obj_offset;
void *data;

if (log_pack_access)
write_pack_access_log(p, obj_offset);

if (do_check_packed_object_crc && p->index_version > 1) {
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
unsigned long len = revidx[1].offset - obj_offset;
Expand Down

0 comments on commit 5f44324

Please sign in to comment.