Class: XCCache::Cache::Cachemap
Instance Attribute Summary
#path, #raw
Instance Method Summary
collapse
#load, #save
#[], #[]=, #initialize, #load, #merge!, #reload, #save
Instance Method Details
#cache_data ⇒ Object
10
11
12
|
# File 'lib/xccache/cache/cachemap.rb', line 10
def cache_data
raw["cache"] ||= {}
end
|
#depgraph_data ⇒ Object
6
7
8
|
# File 'lib/xccache/cache/cachemap.rb', line 6
def depgraph_data
raw["depgraph"] ||= {}
end
|
#get_cache_data(type) ⇒ Object
59
60
61
|
# File 'lib/xccache/cache/cachemap.rb', line 59
def get_cache_data(type)
cache_data.select { |_, v| v == type }.keys
end
|
#missed ⇒ Object
18
19
20
|
# File 'lib/xccache/cache/cachemap.rb', line 18
def missed
get_cache_data(:missed)
end
|
#missed?(name) ⇒ Boolean
14
15
16
|
# File 'lib/xccache/cache/cachemap.rb', line 14
def missed?(name)
missed.include?(name)
end
|
#print_stats ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/xccache/cache/cachemap.rb', line 30
def print_stats
verbose = Config.instance.verbose?
colors = { :hit => "green", :missed => "yellow" }
descs = i[hit missed ignored].to_h do |type|
colorize = proc { |s| colors.key?(type) ? s.send(colors[type]).dark : s.dark }
items = get_cache_data(type)
percent = cache_data.count.positive? ? items.count.to_f / cache_data.count * 100 : 0
desc = "#{type} #{percent.round}% (#{items.count}/#{cache_data.count})"
desc = desc.capitalize if verbose
desc = "#{desc} #{colorize.call(items.to_s)}" if verbose && !items.empty?
[type, desc]
end
if verbose
UI.info " -------------------------------------------------------------------\n Cache stats\n \#{descs.values.map { |s| \"\u2022 \#{s}\" }.join(\"\\n\")}\n -------------------------------------------------------------------\n DESC\n else\n UI.info <<~DESC\n -------------------------------------------------------------------\n Cache stats: \#{descs.values.join(', ')}\n To see the full stats, use --verbose in the xccache command\n -------------------------------------------------------------------\n DESC\n end\nend\n"
|
#stats ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/xccache/cache/cachemap.rb', line 22
def stats
i[hit missed ignored].to_h do |type|
count, total_count = get_cache_data(type).count, cache_data.count
percent = total_count.positive? ? (count.to_f * 100 / total_count).round : 0
[type, "#{percent}% (#{count}/#{total_count})"]
end
end
|
#update_from_graph(graph) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/xccache/cache/cachemap.rb', line 63
def update_from_graph(graph)
cache_data =
graph["cache"]
.reject { |k, _| k.end_with?(".xccache") }
.to_h do |k, v|
next [k, :hit] if v
next [k, :ignored] if Config.instance.ignore?(k)
[k, :missed]
end
deps = graph["deps"]
edges = deps.flat_map { |k, xs| xs.map { |v| { :source => k, :target => v } } }
nodes = deps.keys.map do |k|
{
:id => k,
:cache => cache_data[k],
:type => ("agg" if k.end_with?(".xccache")),
:binary => graph["cache"][k],
}
end
self.raw = {
"cache" => cache_data,
"depgraph" => { "nodes" => nodes, "edges" => edges },
}
save
print_stats
end
|