File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -169,8 +169,14 @@ func (c *Counters) All() iter.Seq[int64] {
169169 // counters at a time.
170170 var vals [countersPerCacheLine ]int64
171171 for i := 0 ; i < c .numCounters ; i += countersPerCacheLine {
172- vals = [countersPerCacheLine ]int64 {}
172+ // We have a total of c.numCounters logical counters and we are processing
173+ // countersPerCacheLine logical counters at a time. So the last iteration
174+ // of this loop will have fewer than countersPerCacheLine logical counters
175+ // to read. n is the number of logical counters to read in this iteration.
173176 n := min (c .numCounters - i , countersPerCacheLine )
177+ // Iterate over all the shards and for this logical cache line, read the
178+ // physical cache line from each shard and aggregate into vals.
179+ vals = [countersPerCacheLine ]int64 {}
174180 for s := range c .numShards {
175181 start := int (s * c .shardSize ) + i
176182 counters := c .counters [start : start + n ]
@@ -180,6 +186,9 @@ func (c *Counters) All() iter.Seq[int64] {
180186 vals [j ] += counters [j ].Load ()
181187 }
182188 }
189+ // Yield the values for the next set of n logical counters. Across the
190+ // iterations of the outer loop we will in total yield c.numCounters
191+ // values.
183192 for j := range n {
184193 if ! yield (vals [j ]) {
185194 return
You can’t perform that action at this time.
0 commit comments