-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some time measurement for istioctl bug-report command #46406
Conversation
The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.
🤔 🐛 You appear to be fixing a bug in Go code, yet your PR doesn't include updates to any test files. Did you forget to add a test? Courtesy of your friendly test nag. |
Hi @Abirdcfly. Thanks for your PR. I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense but there other places in this file with similar capture of the time for the logRuntime
and you didn't update those too?
Any reason not to?
There are 2 ways to use package main
import (
"fmt"
"time"
)
func main() {
Use1()
Use2()
}
func Use1() {
defer logRuntime(time.Now(), "use1")
time.Sleep(time.Second)
}
func Use2() {
defer func() {
fmt.Println("do something")
logRuntime(time.Now(), "use2")
}()
time.Sleep(time.Second)
}
func logRuntime(start time.Time, format string, args ...any) {
fmt.Printf("runtime %s %s\n", time.Since(start), format)
} |
And maybe this issue is helpful: golang/go#60048 |
Please provide a description of this PR:
The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.
There's a quick way to tell if the runtime is correct: manually add a 1s delay using
time.Sleep(time.Second)
in each function that needs to log time, and if the time is still less than 1s in the log, then it must be wrong.The diff is as follows: