Skip to content

Commit 44de6f3

Browse files
committed
refactor(go): change profiling info times from float to time.Duration.
1 parent 5a99f1e commit 44de6f3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

go/scanner.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ func (s *Scanner) Scan(buf []byte) (*ScanResults, error) {
250250
type ProfilingInfo struct {
251251
Namespace string
252252
Rule string
253-
PatternMatchingTime float64
254-
ConditionExecTime float64
253+
PatternMatchingTime time.Duration
254+
ConditionExecTime time.Duration
255255
}
256256

257257
// This is the callback called by yrx_rule_iter_patterns.
@@ -261,7 +261,7 @@ func mostExpensiveRulesCallback(
261261
namespace *C.char,
262262
rule *C.char,
263263
patternMatchingTime C.double,
264-
condExecTime C.double,
264+
conditionExecTime C.double,
265265
handle C.uintptr_t) {
266266
h := cgo.Handle(handle)
267267
profilingInfo, ok := h.Value().(*[]ProfilingInfo)
@@ -271,8 +271,8 @@ func mostExpensiveRulesCallback(
271271
*profilingInfo = append(*profilingInfo, ProfilingInfo{
272272
Namespace: C.GoString(namespace),
273273
Rule: C.GoString(rule),
274-
PatternMatchingTime: float64(patternMatchingTime),
275-
ConditionExecTime: float64(condExecTime),
274+
PatternMatchingTime: time.Duration(float64(patternMatchingTime) * float64(time.Second)),
275+
ConditionExecTime: time.Duration(float64(conditionExecTime) * float64(time.Second)),
276276
})
277277
}
278278

go/scanner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func TestScannerMostExpensiveRules(t *testing.T) {
9999
profilingInfo := s.MostExpensiveRules(1)
100100
assert.Equal(t, "t", profilingInfo[0].Rule)
101101
assert.Equal(t, "default", profilingInfo[0].Namespace)
102-
assert.Greater(t, profilingInfo[0].PatternMatchingTime, float64(0))
103-
assert.Greater(t, profilingInfo[0].ConditionExecTime, float64(0))
102+
assert.Greater(t, profilingInfo[0].PatternMatchingTime, time.Duration(0))
103+
assert.Greater(t, profilingInfo[0].ConditionExecTime, time.Duration(0))
104104
}
105105

106106
func TestScannerMetadata(t *testing.T) {

0 commit comments

Comments
 (0)