Skip to content

Commit fec5e0c

Browse files
committedOct 17, 2024·
mod: update time track utils
1 parent 1039fa5 commit fec5e0c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎internal/middleware/plugins/http_proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error {
8383
span := tracer.StartSpan("web.request", tracer.ResourceName("/"+session.Chain))
8484
defer func() {
8585
span.Finish()
86-
utils.TimeTrack(startTime, session.NodeName)
86+
log.Info(utils.TimeTrack(startTime, session.NodeName))
8787
}()
8888

89-
log.Debug("relay rpc -> "+session.RpcMethod(), "sid", session.SId(), "node", session.NodeName, "isTx", session.IsWriteRpcMethod, "tries", session.Tries)
89+
//log.Debug("relay rpc -> "+session.RpcMethod(), "sid", session.SId(), "node", session.NodeName, "isTx", session.IsWriteRpcMethod, "tries", session.Tries)
9090

9191
if _, ok := m.disableEndpoints.Get(session.NodeName); ok {
9292
log.Debug("disabled endpoint", "node", session.NodeName)

‎pkg/utils/misc.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@ import (
55
"time"
66
)
77

8-
func TimeTrack(start time.Time, name string) {
8+
func TimeTrack(start time.Time, name string) string {
99
elapsed := time.Since(start)
1010

11-
// calculate hours, minutes, and seconds
11+
// calculate hours, minutes, seconds, and milliseconds
1212
hours := int(elapsed.Hours())
1313
minutes := int(elapsed.Minutes()) % 60
1414
seconds := int(elapsed.Seconds()) % 60
15+
milliseconds := int(elapsed.Milliseconds()) % 1000
1516

16-
// build the formatted time string
1717
var formattedTime string
1818
if hours > 0 {
1919
formattedTime += fmt.Sprintf("%d hours, ", hours)
2020
}
2121
if minutes > 0 {
2222
formattedTime += fmt.Sprintf("%d minutes, ", minutes)
2323
}
24-
formattedTime += fmt.Sprintf("%d seconds", seconds)
24+
if seconds > 0 {
25+
formattedTime += fmt.Sprintf("%d seconds, ", seconds)
26+
}
27+
formattedTime += fmt.Sprintf("%d ms", milliseconds)
2528

26-
fmt.Printf("%s took: %s\n", name, formattedTime)
29+
return fmt.Sprintf("%s took: %s", name, formattedTime)
2730
}

0 commit comments

Comments
 (0)
Please sign in to comment.