v.vcache: improve tracing of vcache usage

pull/8420/head
Delyan Angelov 2021-01-29 18:01:22 +02:00
parent 26c06a56b7
commit 49b01549da
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 22 additions and 0 deletions

View File

@ -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')
}
}
}