1function [CacheAvgTable] = getAvgCacheTable(self)
2% [CACHEAVGTABLE] = GETAVGCACHETABLE(SELF)
3% Return a table of detailed per-
class performance metrics for every Cache
4% node in the model. For each cache node and read (input)
class there
is a
5% total row (List=0) and, where the solver reports per-list (per-level) hit
6% probabilities and the cache has more than one list, one extra row per list.
10% JobClass read (input) class name
11% List 0 = total over all lists; l = cache list (level) l
12% ListCap capacity of the list (total capacity on the total row)
13% Items number of items managed by the cache
14% HitProb (true) hit probability; per list on list rows
15% DelayedHitProb delayed-hit probability (retrieval system; total row only)
16% MissProb miss probability (total row only)
17% HitRate hit throughput = ArvR * HitProb
18% DelayedHitRate delayed-hit throughput = ArvR * DelayedHitProb
19% MissRate miss throughput = ArvR * MissProb
20% ArvR read-class arrival rate into the cache
21% ResidT expected retrieval latency / residence time (NaN if not computed)
23% The hit class throughput reported by getAvgNodeTable aggregates true hits
24% and delayed hits; this table separates them.
26% Copyright (c) 2012-2026, Imperial College London
29if GlobalConstants.DummyMode
30 CacheAvgTable = IndexedTable(Table());
34sn = self.model.getStruct;
37caches = find(sn.nodetype == NodeType.Cache)';
39 CacheAvgTable = IndexedTable(Table());
43% Node throughputs. The cache read-class arrival equals that class's source
44% throughput (every read request enters the cache); robust across solvers,
45% including simulators where delayed hits are not folded into hit/miss tput.
46[~,~,~,TNn] = self.getAvgNode();
47srcNode = find(sn.nodetype == NodeType.Source, 1);
51[Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, HitRv, DHitRv, MissRv, ArvRv, Latv] = deal([]);
54 np = sn.nodeparam{ind};
55 hitclass = np.hitclass;
57 if isfield(np,
'nitems'), nitems = np.nitems; end
59 if isfield(np,
'itemcap'), itemcap = np.itemcap(:).
'; end
61 totcap = sum(itemcap);
62 node = self.model.nodes{ind};
63 hitp = node.getHitRatio();
64 missp = node.getMissRatio();
65 dhitp = node.getDelayedHitRatio();
66 hitplist = node.getHitRatioByList();
67 lat = node.getResidT();
69 % read (input) classes are those with a defined hit class
70 if r > length(hitclass) || hitclass(r) <= 0
73 ph = nanGetAt(hitp, r);
74 pm = nanGetAt(missp, r);
75 pd = nanGetAt(dhitp, r);
76 if isnan(ph) && isnan(pm) && isnan(pd)
77 continue % no solved cache metrics for this class
79 if isnan(ph), ph = 0; end
80 if isnan(pm), pm = 0; end
81 if isnan(pd), pd = 0; end
83 if ~isempty(TNn) && ~isempty(srcNode) && srcNode <= size(TNn,1) && r <= size(TNn,2)
84 arvr = TNn(srcNode, r);
86 latr = nanGetAt(lat, r);
88 % --- total row (List = 0) ---
89 [Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
90 HitRv, DHitRv, MissRv, ArvRv, Latv] = addrow( ...
91 Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
92 HitRv, DHitRv, MissRv, ArvRv, Latv, ...
93 sn.nodenames{ind}, sn.classnames{r}, 0, totcap, nitems, ...
94 ph, pd, pm, arvr*ph, arvr*pd, arvr*pm, arvr, latr);
96 % --- per-list rows (only if a multi-list breakdown is available) ---
97 if h > 1 && ~isempty(hitplist) && r <= size(hitplist,1) && ~all(isnan(hitplist(r,:)))
99 phl = full(hitplist(r,l));
100 if isnan(phl), phl = 0; end
101 capl = NaN; if l <= numel(itemcap), capl = itemcap(l); end
102 [Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
103 HitRv, DHitRv, MissRv, ArvRv, Latv] = addrow( ...
104 Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
105 HitRv, DHitRv, MissRv, ArvRv, Latv, ...
106 sn.nodenames{ind}, sn.classnames{r}, l, capl, nitems, ...
107 phl, NaN, NaN, arvr*phl, NaN, NaN, arvr, NaN);
114JobClass = label(JobClass);
119DelayedHitProb = DHitPv;
122DelayedHitRate = DHitRv;
126CacheAvgTable = Table(Node, JobClass, List, ListCap, Items, HitProb, ...
127 DelayedHitProb, MissProb, HitRate, DelayedHitRate, MissRate, ArvR, ResidT);
128CacheAvgTable = IndexedTable(CacheAvgTable);
131function [Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
132 HitRv, DHitRv, MissRv, ArvRv, Latv] = addrow( ...
133 Node, JobClass, Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, ...
134 HitRv, DHitRv, MissRv, ArvRv, Latv, ...
135 nodename, classname, listidx, listcap, nitems, ...
136 ph, pd, pm, hr, dhr, mr, arvr, lat)
137Node{end+1,1} = nodename;
138JobClass{end+1,1} = classname;
139Listv(end+1,1) = listidx;
140ListCapv(end+1,1) = listcap;
141Itemsv(end+1,1) = nitems;
146DHitRv(end+1,1) = dhr;
148ArvRv(end+1,1) = arvr;
152function v = nanGetAt(vec, r)
153% Safe scalar read; returns NaN if out of range or empty.
154if isempty(vec) || r > numel(vec)