Skip to content

Commit 7166d2d

Browse files
committed
make deterministic expression parsing to replace fixed counter event names with corresponding perf event names
Signed-off-by: Harper, Jason M <[email protected]>
1 parent 53076df commit 7166d2d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cmd/metrics/loader_perfmon.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,17 @@ func getExpression(perfmonMetric PerfmonMetric) (string, error) {
330330
expression = strings.ReplaceAll(expression, commonEvent, alias)
331331
}
332332
// replace fixed counter perfmon event names with their corresponding perf event names
333-
for perfmonEventName, perfEventName := range fixedCounterEventNameTranslation {
334-
// Replace event name as whole words only (not substrings)
335-
expression = util.ReplaceWholeWord(expression, perfmonEventName, perfEventName)
333+
// example: "100 * ([ref-cycles:k] / [TSC])"
334+
// parse out the list of events/variables from the expression
335+
expressionVars := regexp.MustCompile(`\[[^\]]+\]`)
336+
// for each event/variable, check if it is in the fixedCounterEventNameTranslation map
337+
for _, match := range expressionVars.FindAllString(expression, -1) {
338+
for perfmonEventName, perfEventName := range fixedCounterEventNameTranslation {
339+
if match == "["+perfmonEventName+"]" {
340+
expression = util.ReplaceWholeWord(expression, perfmonEventName, perfEventName)
341+
break
342+
}
343+
}
336344
}
337345
return expression, nil
338346
}

0 commit comments

Comments
 (0)