Skip to content

Commit 376319f

Browse files
EtiennePerotgvisor-bot
authored andcommitted
Change metric.fieldMapper methods to use pointer receivers.
This fixes some builds with debug flags that cause this function to grow beyond the stack size limit with nosplit. PiperOrigin-RevId: 801022224
1 parent 1b291cb commit 376319f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pkg/metric/metric.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func newFieldMapper(fields ...Field) (fieldMapper, error) {
384384
// +checkescape:all
385385
//
386386
//go:nosplit
387-
func (m fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, remainingCombinationBucket int) (int, int) {
387+
func (m *fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, remainingCombinationBucket int) (int, int) {
388388
field := m.fields[fieldIndex]
389389
numValues := len(field.values)
390390

@@ -422,7 +422,7 @@ func (m fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, r
422422
// +checkescape:all
423423
//
424424
//go:nosplit
425-
func (m fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
425+
func (m *fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
426426
if (len(fields1) + len(fields2)) != len(m.fields) {
427427
panic("invalid field lookup depth")
428428
}
@@ -447,15 +447,15 @@ func (m fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
447447
// +checkescape:all
448448
//
449449
//go:nosplit
450-
func (m fieldMapper) lookup(fields ...*FieldValue) int {
450+
func (m *fieldMapper) lookup(fields ...*FieldValue) int {
451451
return m.lookupConcat(fields, nil)
452452
}
453453

454454
// numKeys returns the total number of key-to-field-combinations mappings
455455
// defined by the fieldMapper.
456456
//
457457
//go:nosplit
458-
func (m fieldMapper) numKeys() int {
458+
func (m *fieldMapper) numKeys() int {
459459
return m.numFieldCombinations
460460
}
461461

@@ -464,7 +464,7 @@ func (m fieldMapper) numKeys() int {
464464
// accessed using index "keys" made by fieldMapper.
465465
// - The second level corresponds to buckets within a metric. The number of
466466
// buckets is specified by numBuckets.
467-
func (m fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.Uint64 {
467+
func (m *fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.Uint64 {
468468
samples := make([][]atomicbitops.Uint64, m.numKeys())
469469
for i := range samples {
470470
samples[i] = make([]atomicbitops.Uint64, numBuckets)
@@ -475,7 +475,7 @@ func (m fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.
475475
// keyToMultiField is the reverse of lookup/lookupConcat. The returned list of
476476
// field values corresponds to the same order of fields that were passed in to
477477
// newFieldMapper.
478-
func (m fieldMapper) keyToMultiField(key int) []string {
478+
func (m *fieldMapper) keyToMultiField(key int) []string {
479479
depth := len(m.fields)
480480
if depth == 0 && key == 0 {
481481
return nil
@@ -495,7 +495,7 @@ func (m fieldMapper) keyToMultiField(key int) []string {
495495
// `len(m.fields)`.
496496
//
497497
//go:nosplit
498-
func (m fieldMapper) keyToMultiFieldInPlace(key int, fieldValues []*FieldValue) {
498+
func (m *fieldMapper) keyToMultiFieldInPlace(key int, fieldValues []*FieldValue) {
499499
if len(m.fields) == 0 {
500500
return
501501
}
@@ -1386,10 +1386,10 @@ func EmitMetricUpdate() {
13861386
if (!ok && metricValue == 0) || (ok && prev.([]uint64)[fieldKey] == metricValue) {
13871387
continue
13881388
}
1389-
1389+
uint64M := allMetrics.uint64Metrics[k]
13901390
m.Metrics = append(m.Metrics, &pb.MetricValue{
13911391
Name: k,
1392-
FieldValues: allMetrics.uint64Metrics[k].fieldMapper.keyToMultiField(fieldKey),
1392+
FieldValues: uint64M.fieldMapper.keyToMultiField(fieldKey),
13931393
Value: &pb.MetricValue_Uint64Value{Uint64Value: metricValue},
13941394
})
13951395
}

0 commit comments

Comments
 (0)