From 30350e0801018bd2523123c19c98f2bcd4807566 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 18 May 2022 21:00:34 +0800 Subject: add hitrate for build cache --- xmake/modules/private/cache/build_cache.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'xmake/modules/private/cache/build_cache.lua') 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 -- cgit v1.3.1