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:
@@ -23,11 +23,6 @@ import (
|
|||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func timeFunc(start time.Time, name string) {
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
log.Printf("%s completed in: %s", name, elapsed)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
deviceinfoFile := "/etc/deviceinfo"
|
deviceinfoFile := "/etc/deviceinfo"
|
||||||
if !exists(deviceinfoFile) {
|
if !exists(deviceinfoFile) {
|
||||||
@@ -45,7 +40,7 @@ func main() {
|
|||||||
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
defer timeFunc(time.Now(), "mkinitfs")
|
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||||
|
|
||||||
kernVer, err := getKernelVersion()
|
kernVer, err := getKernelVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -4,10 +4,12 @@
|
|||||||
package misc
|
package misc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Converts a relative symlink target path (e.g. ../../lib/foo.so), that is
|
// Converts a relative symlink target path (e.g. ../../lib/foo.so), that is
|
||||||
@@ -74,3 +76,13 @@ func RemoveDuplicates(in []string) (out []string) {
|
|||||||
|
|
||||||
return
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user