Skip to content

Commit 5f44324

Browse files
committed
core: log offset pack data accesses happened
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 <[email protected]>
1 parent 033c2dc commit 5f44324

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime);
784784
/* global flag to enable extra checks when accessing packed objects */
785785
extern int do_check_packed_object_crc;
786786

787+
/* for development: log offset of pack access */
788+
extern const char *log_pack_access;
789+
787790
extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
788791

789792
extern int move_temp_to_file(const char *tmpfile, const char *filename);

config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,9 @@ static int git_default_core_config(const char *var, const char *value)
569569
return 0;
570570
}
571571

572+
if (!strcmp(var, "core.logpackaccess"))
573+
return git_config_string(&log_pack_access, var, value);
574+
572575
if (!strcmp(var, "core.autocrlf")) {
573576
if (value && !strcasecmp(value, "input")) {
574577
if (core_eol == EOL_CRLF)

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
3636
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
3737
size_t delta_base_cache_limit = 16 * 1024 * 1024;
3838
unsigned long big_file_threshold = 512 * 1024 * 1024;
39+
const char *log_pack_access;
3940
const char *pager_program;
4041
int pager_use_color = 1;
4142
const char *editor_program;

sha1_file.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,24 @@ static void *unpack_delta_entry(struct packed_git *p,
18391839
return result;
18401840
}
18411841

1842+
static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
1843+
{
1844+
static FILE *log_file;
1845+
1846+
if (!log_file) {
1847+
log_file = fopen(log_pack_access, "w");
1848+
if (!log_file) {
1849+
error("cannot open pack access log '%s' for writing: %s",
1850+
log_pack_access, strerror(errno));
1851+
log_pack_access = NULL;
1852+
return;
1853+
}
1854+
}
1855+
fprintf(log_file, "%s %"PRIuMAX"\n",
1856+
p->pack_name, (uintmax_t)obj_offset);
1857+
fflush(log_file);
1858+
}
1859+
18421860
int do_check_packed_object_crc;
18431861

18441862
void *unpack_entry(struct packed_git *p, off_t obj_offset,
@@ -1848,6 +1866,9 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
18481866
off_t curpos = obj_offset;
18491867
void *data;
18501868

1869+
if (log_pack_access)
1870+
write_pack_access_log(p, obj_offset);
1871+
18511872
if (do_check_packed_object_crc && p->index_version > 1) {
18521873
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
18531874
unsigned long len = revidx[1].offset - obj_offset;

0 commit comments

Comments
 (0)