Skip to content

Commit

Permalink
Parse numeric labels with a zero-value if units are specified. (googl…
Browse files Browse the repository at this point in the history
…e#619)

By default, a numeric label with a value of zero is interpreted as an
empty label which will be ignored during parsing. However, a zero value
can be a valid label value. Instead of ignoring it altogether, parse it
as a zero-valued numeric label if num_unit is set.
  • Loading branch information
xyzsam authored Apr 6, 2021
1 parent ec78c8a commit 17a10ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion profile/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (p *Profile) postDecode() error {
if l.strX != 0 {
value, err = getString(p.stringTable, &l.strX, err)
labels[key] = append(labels[key], value)
} else if l.numX != 0 {
} else if l.numX != 0 || l.unitX != 0 {
numValues := numLabels[key]
units := numUnits[key]
if l.unitX != 0 {
Expand Down
10 changes: 10 additions & 0 deletions profile/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ var all = &Profile{
"alignment": {"kilobytes", "kilobytes"},
},
},
{
Location: []*Location{testL[1], testL[2], testL[0], testL[1]},
Value: []int64{30, 40},
NumLabel: map[string][]int64{
"size": {0},
},
NumUnit: map[string][]string{
"size": {"bytes"},
},
},
},
Function: testF,
Mapping: testM,
Expand Down

0 comments on commit 17a10ee

Please sign in to comment.