LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getAvgCacheTable.m
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.
7% Columns:
8%
9% Node cache node name
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)
22%
23% The hit class throughput reported by getAvgNodeTable aggregates true hits
24% and delayed hits; this table separates them.
25%
26% Copyright (c) 2012-2026, Imperial College London
27% All rights reserved.
28
29if GlobalConstants.DummyMode
30 CacheAvgTable = IndexedTable(Table());
31 return
32end
33
34sn = self.model.getStruct;
35K = sn.nclasses;
36
37caches = find(sn.nodetype == NodeType.Cache)';
38if isempty(caches)
39 CacheAvgTable = IndexedTable(Table());
40 return
41end
42
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);
48
49Node = {};
50JobClass = {};
51[Listv, ListCapv, Itemsv, HitPv, DHitPv, MissPv, HitRv, DHitRv, MissRv, ArvRv, Latv] = deal([]);
52
53for ind = caches
54 np = sn.nodeparam{ind};
55 hitclass = np.hitclass;
56 nitems = 0;
57 if isfield(np,'nitems'), nitems = np.nitems; end
58 itemcap = [];
59 if isfield(np,'itemcap'), itemcap = np.itemcap(:).'; end
60 h = numel(itemcap);
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();
68 for r = 1:K
69 % read (input) classes are those with a defined hit class
70 if r > length(hitclass) || hitclass(r) <= 0
71 continue
72 end
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
78 end
79 if isnan(ph), ph = 0; end
80 if isnan(pm), pm = 0; end
81 if isnan(pd), pd = 0; end
82 arvr = 0;
83 if ~isempty(TNn) && ~isempty(srcNode) && srcNode <= size(TNn,1) && r <= size(TNn,2)
84 arvr = TNn(srcNode, r);
85 end
86 latr = nanGetAt(lat, r);
87
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);
95
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,:)))
98 for l = 1:h
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);
108 end
109 end
110 end
111end
112
113Node = label(Node);
114JobClass = label(JobClass);
115List = Listv;
116ListCap = ListCapv;
117Items = Itemsv;
118HitProb = HitPv;
119DelayedHitProb = DHitPv;
120MissProb = MissPv;
121HitRate = HitRv;
122DelayedHitRate = DHitRv;
123MissRate = MissRv;
124ArvR = ArvRv;
125ResidT = Latv;
126CacheAvgTable = Table(Node, JobClass, List, ListCap, Items, HitProb, ...
127 DelayedHitProb, MissProb, HitRate, DelayedHitRate, MissRate, ArvR, ResidT);
128CacheAvgTable = IndexedTable(CacheAvgTable);
129end
130
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;
142HitPv(end+1,1) = ph;
143DHitPv(end+1,1) = pd;
144MissPv(end+1,1) = pm;
145HitRv(end+1,1) = hr;
146DHitRv(end+1,1) = dhr;
147MissRv(end+1,1) = mr;
148ArvRv(end+1,1) = arvr;
149Latv(end+1,1) = lat;
150end
151
152function v = nanGetAt(vec, r)
153% Safe scalar read; returns NaN if out of range or empty.
154if isempty(vec) || r > numel(vec)
155 v = NaN;
156else
157 v = full(vec(r));
158end
159end