diff options
| author | ruki <[email protected]> | 2022-05-18 21:00:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-18 21:00:34 +0800 |
| commit | 30350e0801018bd2523123c19c98f2bcd4807566 (patch) | |
| tree | 3390d83cbe8be9be2ba06714217d8286f59110d4 /xmake/modules | |
| parent | e73caa9e24f4c6ca5fa6d60e9c1623cf496bf1e8 (diff) | |
add hitrate for build cache
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/cache/build_cache.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index 8f3c98bd3..629c903a3 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -34,8 +34,9 @@ end -- get cache key function cachekey(program, cppfile, cppflags, envs) local items = {program} - table.insert(items, hash.sha256(cppfile)) table.join2(items, cppflags) + table.sort(items) + table.insert(items, hash.sha256(cppfile)) if envs then for k, v in pairs(table.orderpairs(envs)) do table.insert(items, k) @@ -55,10 +56,22 @@ function clean() os.rm(rootdir()) end +-- get hit rate +function hitrate() + local hit_count = (_g.hit_count or 0) + local total_count = (_g.total_count or 0) + if total_count > 0 then + return hit_count * 100 / total_count + end + return 0 +end + -- get object file function get(cachekey) + _g.total_count = (_g.total_count or 0) + 1 local objectfile_cached = path.join(rootdir(), cachekey:sub(1, 2):lower(), cachekey) if os.isfile(objectfile_cached) then + _g.hit_count = (_g.hit_count or 0) + 1 return objectfile_cached end end |
