sha1_file: change GIT_TRACE_PACK_ACCESS logging to use trace API

This changes GIT_TRACE_PACK_ACCESS functionality as follows: * supports the same options as GIT_TRACE (e.g. printing to stderr) * no longer supports relative paths * appends to the trace file rather than overwriting Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Jul 12, 2014 at 02:01 UTC 67dc598ec42ea25cda94ed8d283396c4ab385f50
2 files changed +6 -28
Documentation/git.txt
+2 -2
@@ -925,11 +925,11 @@ Unsetting the variable, or setting it to empty, "0" or
925 "false" (case insensitive) disables trace messages.
926
927 'GIT_TRACE_PACK_ACCESS'::
928 - If this variable is set to a path, a file will be created at
929 - the given path logging all accesses to any packs. For each
928 + Enables trace messages for all accesses to any packs. For each
929 access, the pack file name and an offset in the pack is
930 recorded. This may be helpful for troubleshooting some
931 pack-related performance problems.
932 + See 'GIT_TRACE' for available trace output options.
933
934 'GIT_TRACE_PACKET'::
935 Enables trace messages for all packets coming in or out of a
sha1_file.c
+4 -26
@@ -36,9 +36,6 @@ 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 -
39 /*
40 * This is meant to hold a *small* number of objects that you would
41 * want read_sha1_file() to be able to return, but yet you do not want
@@ -2085,27 +2082,9 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
2082
2083 static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
2084 {
2088 - static FILE *log_file;
2089 -
2090 - if (!log_pack_access)
2091 - log_pack_access = getenv("GIT_TRACE_PACK_ACCESS");
2092 - if (!log_pack_access)
2093 - log_pack_access = no_log_pack_access;
2094 - if (log_pack_access == no_log_pack_access)
2095 - return;
2096 -
2097 - if (!log_file) {
2098 - log_file = fopen(log_pack_access, "w");
2099 - if (!log_file) {
2100 - error("cannot open pack access log '%s' for writing: %s",
2101 - log_pack_access, strerror(errno));
2102 - log_pack_access = no_log_pack_access;
2103 - return;
2104 - }
2105 - }
2106 - fprintf(log_file, "%s %"PRIuMAX"\n",
2107 - p->pack_name, (uintmax_t)obj_offset);
2108 - fflush(log_file);
2085 + static struct trace_key pack_access = TRACE_KEY_INIT(PACK_ACCESS);
2086 + trace_printf_key(&pack_access, "%s %"PRIuMAX"\n",
2087 + p->pack_name, (uintmax_t)obj_offset);
2088 }
2089
2090 int do_check_packed_object_crc;
@@ -2130,8 +2109,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2109 int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
2110 int base_from_cache = 0;
2111
2133 - if (log_pack_access != no_log_pack_access)
2134 - write_pack_access_log(p, obj_offset);
2112 + write_pack_access_log(p, obj_offset);
2113
2114 /* PHASE 1: drill down to the innermost base object */
2115 for (;;) {