From e80239a6618108058572beb4cb5799b335c3ab53 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 23 Mar 2021 22:32:44 -0700 Subject: [PATCH] simplify OS instrumentation remove functions for global variables --- cmd/os-instrumented.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/cmd/os-instrumented.go b/cmd/os-instrumented.go index 6114317a5..043119c5f 100644 --- a/cmd/os-instrumented.go +++ b/cmd/os-instrumented.go @@ -41,17 +41,9 @@ func init() { threshold = time.Duration(t) * time.Millisecond } -func getThreshold() time.Duration { - return threshold -} - -func collectLogTime() bool { - return logTime -} - func reportTime(name *strings.Builder, startTime time.Time) { delta := time.Since(startTime) - if delta > getThreshold() { + if delta > threshold { name.WriteString(" ") name.WriteString(delta.String()) fmt.Println(name.String()) @@ -60,7 +52,7 @@ func reportTime(name *strings.Builder, startTime time.Time) { // RemoveAll captures time taken to call the underlying os.RemoveAll func RemoveAll(dirPath string) error { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.RemoveAll: ") @@ -72,7 +64,7 @@ func RemoveAll(dirPath string) error { // MkdirAll captures time taken to call os.MkdirAll func MkdirAll(dirPath string, mode os.FileMode) error { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.MkdirAll: ") @@ -84,7 +76,7 @@ func MkdirAll(dirPath string, mode os.FileMode) error { // Rename captures time taken to call os.Rename func Rename(src, dst string) error { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.Rename: ") @@ -98,7 +90,7 @@ func Rename(src, dst string) error { // OpenFile captures time taken to call os.OpenFile func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.OpenFile: ") @@ -110,7 +102,7 @@ func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { // Open captures time taken to call os.Open func Open(name string) (*os.File, error) { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.Open: ") @@ -122,7 +114,7 @@ func Open(name string) (*os.File, error) { // OpenFileDirectIO captures time taken to call disk.OpenFileDirectIO func OpenFileDirectIO(name string, flag int, perm os.FileMode) (*os.File, error) { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("disk.OpenFileDirectIO: ") @@ -134,7 +126,7 @@ func OpenFileDirectIO(name string, flag int, perm os.FileMode) (*os.File, error) // Lstat captures time taken to call os.Lstat func Lstat(name string) (os.FileInfo, error) { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.Lstat: ") @@ -146,7 +138,7 @@ func Lstat(name string) (os.FileInfo, error) { // Remove captures time taken to call os.Remove func Remove(deletePath string) error { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.Remove: ") @@ -158,7 +150,7 @@ func Remove(deletePath string) error { // Stat captures time taken to call os.Stat func Stat(name string) (os.FileInfo, error) { - if collectLogTime() { + if logTime { startTime := time.Now() var s strings.Builder s.WriteString("os.Stat: ")