349adcd7c26d73b53ec1865a4fd14c60b74f9386 braney Wed May 13 09:18:36 2026 -0700 trackDbCache: CACHE_TRACK_DB_DIR env var override; add trackDbCacheBench, refs #37551 trackDbCacheOn() in src/hg/lib/trackDbCache.c now reads CACHE_TRACK_DB_DIR from the environment ahead of the cacheTrackDbDir hg.conf setting. When the env var is set its value wins, including the empty string (which disables the cache). This lets a benchmark harness switch caching on and off per hgTracks invocation without editing hg.conf. trackDbCacheBench (src/utils/qa/trackDbCacheBench/) drives hgTracks through cached and uncached runs, with warmups and per-iteration median/min/max timings, and an --evict-cache option that uses posix_fadvise(DONTNEED) to drop cache files from the OS page cache between iterations so disk-backed cache directories can be compared to /dev/shm. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> diff --git src/hg/lib/trackDbCache.c src/hg/lib/trackDbCache.c index de3aecad99f..6a08f6bfd2f 100644 --- src/hg/lib/trackDbCache.c +++ src/hg/lib/trackDbCache.c @@ -453,28 +453,37 @@ char newName[(SHA_DIGEST_LENGTH + 1) * 2]; hexBinaryString(hash, SHA_DIGEST_LENGTH, newName, (SHA_DIGEST_LENGTH + 1) * 2); cloneTdbListToSharedMem(newName, NULL, list, size, trackDbUrl, incFiles); } boolean trackDbCacheOn() /* Check to see if we're caching trackDb contents. */ { static boolean checkedCache = FALSE; static boolean doCache = FALSE; if (!checkedCache) { + /* The CACHE_TRACK_DB_DIR environment variable overrides the cacheTrackDbDir + * hg.conf setting so a benchmark harness can flip caching on/off per run. + * When set (even to the empty string) the env value wins: empty disables + * the cache. */ + char *envDir = getenv("CACHE_TRACK_DB_DIR"); + if (envDir != NULL) + trackDbCacheDir = envDir; + else trackDbCacheDir = cfgOptionDefault("cacheTrackDbDir", "/dev/shm/trackDbCache"); + if (isNotEmpty(trackDbCacheDir)) { makeDirsOnPath(trackDbCacheDir); chmod(trackDbCacheDir, 0777); doCache = TRUE; } checkedCache = TRUE; } return doCache; }