From ff9cc1349f1178528a4595391a023f0d8da54d2b Mon Sep 17 00:00:00 2001 From: The_Spider Date: Mon, 21 Mar 2022 16:58:05 -0500 Subject: [PATCH] adds abilit to report timing for execution --- cmd/bind/build-bind.go | 3 +++ cmd/bind/cleanup.go | 3 +++ cmd/bind/get-remote-data.go | 4 ++++ cmd/bind/init.go | 8 ++++++++ cmd/bind/parsing-complex.go | 3 +++ cmd/bind/parsing-simple.go | 3 +++ cmd/bind/supporting-functions.go | 11 +++++++++++ 7 files changed, 35 insertions(+) create mode 100644 cmd/bind/supporting-functions.go diff --git a/cmd/bind/build-bind.go b/cmd/bind/build-bind.go index 783ad1f..47d82e6 100644 --- a/cmd/bind/build-bind.go +++ b/cmd/bind/build-bind.go @@ -4,11 +4,14 @@ import ( "bytes" "log" "os" + "time" "text/template" ) func buildBindResponsePolicyFile() { + defer timeTrack(time.Now(), "buildBindResponsePolicyFile") + var ( output bytes.Buffer ) diff --git a/cmd/bind/cleanup.go b/cmd/bind/cleanup.go index db80e0e..e3645d4 100644 --- a/cmd/bind/cleanup.go +++ b/cmd/bind/cleanup.go @@ -4,9 +4,12 @@ import ( "log" "regexp" "sort" + "time" ) func cleanBadDomains(domains []string) []string { + defer timeTrack(time.Now(), "cleanBadDomains") + // remove duplicates total := len(domains) all := make(map[string]bool) diff --git a/cmd/bind/get-remote-data.go b/cmd/bind/get-remote-data.go index 266d9c1..c76d9a0 100644 --- a/cmd/bind/get-remote-data.go +++ b/cmd/bind/get-remote-data.go @@ -7,6 +7,8 @@ import ( ) func getListData() []string { + defer timeTrack(time.Now(), "getListData") + var badDomains []string listSimple := make(chan []string) listComplex := make(chan []string) @@ -59,6 +61,8 @@ func getListData() []string { } func getData(urls []string) []byte { + defer timeTrack(time.Now(), "getData") + var listData []byte for _, u := range urls { diff --git a/cmd/bind/init.go b/cmd/bind/init.go index dccbf5d..c71ee96 100644 --- a/cmd/bind/init.go +++ b/cmd/bind/init.go @@ -15,6 +15,8 @@ import ( // getEnvString returns string from environment variable func getEnvString(env, def string) (val string) { //nolint:deadcode + defer timeTrack(time.Now(), "getEnvString") + val = os.Getenv(env) if val == "" { @@ -26,6 +28,8 @@ func getEnvString(env, def string) (val string) { //nolint:deadcode // getEnvInt returns int from environment variable func getEnvInt(env string, def int) (ret int) { + defer timeTrack(time.Now(), "getEnvInt") + val := os.Getenv(env) if val == "" { @@ -41,6 +45,8 @@ func getEnvInt(env string, def int) (ret int) { } func initialize() { + defer timeTrack(time.Now(), "initialize") + config.TimeZone, _ = time.LoadLocation("America/Chicago") config.TimeZoneUTC, _ = time.LoadLocation("UTC") @@ -189,6 +195,8 @@ func initialize() { } func readConfigFile(configFileLocation string) (configFileStruct, error) { + defer timeTrack(time.Now(), "readConfigFile") + var output configFileStruct rd, err := ioutil.ReadFile(configFileLocation) diff --git a/cmd/bind/parsing-complex.go b/cmd/bind/parsing-complex.go index 7e74b41..513b218 100644 --- a/cmd/bind/parsing-complex.go +++ b/cmd/bind/parsing-complex.go @@ -6,11 +6,14 @@ import ( "log" "regexp" "strings" + "time" "github.com/asaskevich/govalidator" ) func parseComplex(data []byte) []string { + defer timeTrack(time.Now(), "parseComplex") + var domains []string // convert data to reader for line-by-line reading diff --git a/cmd/bind/parsing-simple.go b/cmd/bind/parsing-simple.go index 2d20dbd..b161112 100644 --- a/cmd/bind/parsing-simple.go +++ b/cmd/bind/parsing-simple.go @@ -6,11 +6,14 @@ import ( "log" "regexp" "strings" + "time" "github.com/asaskevich/govalidator" ) func parseSimple(data []byte) []string { + defer timeTrack(time.Now(), "parseSimple") + var domains []string // convert data to reader for line-by-line reading diff --git a/cmd/bind/supporting-functions.go b/cmd/bind/supporting-functions.go new file mode 100644 index 0000000..632e4a2 --- /dev/null +++ b/cmd/bind/supporting-functions.go @@ -0,0 +1,11 @@ +package main + +import ( + "log" + "time" +) + +func timeTrack(start time.Time, name string) { + elapsed := time.Since(start) + log.Printf("[TRACE] Function %s took %s\n", name, elapsed) +}