Skip to content

Commit

Permalink
chore: move isFileExists function to util for reuse
Browse files Browse the repository at this point in the history
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
  • Loading branch information
sunya-ch committed Aug 26, 2024
1 parent de1aad9 commit 31f106e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cmd/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 31f106e

Please sign in to comment.