misc: add TimeFunc()

This allows it to be re-used easily when things are broken up into
more packages later.
This commit is contained in:
Clayton Craft
2023-02-11 14:37:14 -08:00
parent f714f110a1
commit 7e80107bbe
2 changed files with 14 additions and 7 deletions

View File

@@ -4,10 +4,12 @@
package misc
import (
"golang.org/x/sys/unix"
"log"
"os"
"path/filepath"
"time"
"golang.org/x/sys/unix"
)
// Converts a relative symlink target path (e.g. ../../lib/foo.so), that is
@@ -74,3 +76,13 @@ func RemoveDuplicates(in []string) (out []string) {
return
}
// Prints the execution time of a function, not meant to be very
// sensitive/accurate, but good enough to gauge rough run times.
// Meant to be called as:
//
// defer misc.TimeFunc(time.Now(), "foo")
func TimeFunc(start time.Time, name string) {
elapsed := time.Since(start)
log.Printf("%s completed in: %s", name, elapsed)
}