From 49b01549dad2dd4d8b51f2507bcd8a15b28e79eb Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 29 Jan 2021 18:01:22 +0200 Subject: [PATCH] v.vcache: improve tracing of vcache usage --- vlib/v/vcache/vcache.v | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vlib/v/vcache/vcache.v b/vlib/v/vcache/vcache.v index 75038fd192..aa958460a0 100644 --- a/vlib/v/vcache/vcache.v +++ b/vlib/v/vcache/vcache.v @@ -39,6 +39,7 @@ pub fn new_cache_manager(opts []string) CacheManager { if vcache_basepath == '' { vcache_basepath = os.join_path(os.vmodules_dir(), 'cache') } + dlog(@FN, 'vcache_basepath: $vcache_basepath | opts:\n $opts') if !os.is_dir(vcache_basepath) { os.mkdir_all(vcache_basepath) or { panic(err) } readme_content := 'This folder contains cached build artifacts from the V build system. @@ -61,6 +62,7 @@ pub fn new_cache_manager(opts []string) CacheManager { // without affecting the .original_vopts pub fn (mut cm CacheManager) set_temporary_options(new_opts []string) { cm.vopts = cm.original_vopts + '#' + new_opts.join('|') + dlog(@FN, 'cm.vopts:\n $cm.vopts') } pub fn (mut cm CacheManager) key2cpath(key string) string { @@ -77,8 +79,13 @@ pub fn (mut cm CacheManager) key2cpath(key string) string { os.mkdir_all(cprefix_folder) or { panic(err) } os.chmod(cprefix_folder, 0o777) } + dlog(@FN, 'new hk') + dlog(@FN, ' key: $key') + dlog(@FN, ' cpath: $cpath') + dlog(@FN, ' cm.vopts:\n $cm.vopts') cm.k2cpath[key] = cpath } + dlog(@FN, 'key: ${key:-30} => cpath: $cpath') return cpath } @@ -88,6 +95,7 @@ pub fn (mut cm CacheManager) postfix_with_key2cpath(postfix string, key string) pub fn (mut cm CacheManager) exists(postfix string, key string) ?string { fpath := cm.postfix_with_key2cpath(postfix, key) + dlog(@FN, 'postfix: $postfix | key: $key | fpath: $fpath') if !os.exists(fpath) { return error('does not exist yet') } @@ -97,11 +105,25 @@ pub fn (mut cm CacheManager) exists(postfix string, key string) ?string { pub fn (mut cm CacheManager) save(postfix string, key string, content string) ?string { fpath := cm.postfix_with_key2cpath(postfix, key) os.write_file(fpath, content) ? + dlog(@FN, 'postfix: $postfix | key: $key | fpath: $fpath') return fpath } pub fn (mut cm CacheManager) load(postfix string, key string) ?string { fpath := cm.exists(postfix, key) ? content := os.read_file(fpath) ? + dlog(@FN, 'postfix: $postfix | key: $key | fpath: $fpath') return content } + +const process_pid = os.getpid() + +pub fn dlog(fname string, s string) { + $if trace_use_cache ? { + if fname[0] != `|` { + eprintln('> VCache | pid: $vcache.process_pid | CacheManager.$fname $s') + } else { + eprintln('> VCache | pid: $vcache.process_pid $fname $s') + } + } +}