From 31f106e7d2003d997063b9ff4a7e9d9cf036fcd9 Mon Sep 17 00:00:00 2001 From: Sunyanan Choochotkaew Date: Wed, 21 Aug 2024 14:28:26 +0900 Subject: [PATCH] chore: move isFileExists function to util for reuse Signed-off-by: Sunyanan Choochotkaew --- cmd/validator/validator.go | 8 ++------ pkg/utils/utils.go | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 9832c8b70c..ab92124ae4 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -32,6 +32,7 @@ import ( "github.com/sustainable-computing-io/kepler/pkg/sensors/components" "github.com/sustainable-computing-io/kepler/pkg/sensors/components/source" "github.com/sustainable-computing-io/kepler/pkg/sensors/platform" + "github.com/sustainable-computing-io/kepler/pkg/utils" ) const ( @@ -171,11 +172,6 @@ func getX86Architecture() (string, error) { return uarch, err } -func isFileExists(path string) bool { - _, err := os.Stat(path) - return !os.IsNotExist(err) -} - func main() { // init stuffs flag.Parse() @@ -199,7 +195,7 @@ func main() { platform.InitPowerImpl() csvFilePath := filepath.Join(resultDirPath, "power.csv") - if !isFileExists(csvFilePath) { + if !utils.IsFileExists(csvFilePath) { columnHeaders := []string{"Pkg", "Core", "Uncore", "Dram"} csvFile, e := os.Create(csvFilePath) if e != nil { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index cc0d79fbba..751e22f758 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -94,3 +94,8 @@ func GetCgroupIDFromPath(byteOrder binary.ByteOrder, path string) (uint64, error } return byteOrder.Uint64(handle.Bytes()), nil } + +func IsFileExists(path string) bool { + _, err := os.Stat(path) + return !os.IsNotExist(err) +}