From 86a551de2377af5132969b32d8f8f29ee90c47bc Mon Sep 17 00:00:00 2001 From: Who Soup Date: Wed, 31 Jul 2019 10:21:08 +0200 Subject: [PATCH] new lxrhash and some failure detection --- .gitignore | 1 + go.mod | 2 +- go.sum | 2 ++ main.go | 13 ++++++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f1c181e..93b9f53 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +*.txt # Test binary, build with `go test -c` *.test diff --git a/go.mod b/go.mod index dabdf48..7c1862c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.12 require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/go-ole/go-ole v1.2.4 // indirect - github.com/pegnet/LXRHash v0.0.0-20190726144200-a35b17bbf85c + github.com/pegnet/LXRHash v0.0.0-20190729193922-452b32b2d231 github.com/shirou/gopsutil v2.18.12+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e // indirect diff --git a/go.sum b/go.sum index ba617b6..5dd85a9 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNI github.com/pegnet/LXR256 v0.0.0-20190721001507-5e925f415fa2/go.mod h1:11Z6s/PoxMH3ON6Kh+2MxNFdaq9op2sgvIAqg52d/3I= github.com/pegnet/LXRHash v0.0.0-20190726144200-a35b17bbf85c h1:/3H7wWMIg/X/vvnkaVL48HrEm9WbTW/H/mFr8bKVeAI= github.com/pegnet/LXRHash v0.0.0-20190726144200-a35b17bbf85c/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA= +github.com/pegnet/LXRHash v0.0.0-20190729193922-452b32b2d231 h1:/kqjIK3ufejdrpUwWdk0hdALErfY/37uEffjFE5Pa0Q= +github.com/pegnet/LXRHash v0.0.0-20190729193922-452b32b2d231/go.mod h1:0zBp9GFy9F77zuQbPkAmdUBRiptMaJ1V96eVFdMnXZA= github.com/pegnet/OracleRecord v0.0.2/go.mod h1:VrY7Shn4oSCli47CsUYBFjH68IenGYtnLaXaaivepu4= github.com/pegnet/pegnet v0.0.2/go.mod h1:FUyEs8fyLOzPXZgyqXcqiOhQi58loNtujykIbxxoKbQ= github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM= diff --git a/main.go b/main.go index 0a9526d..b264627 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,9 @@ package main import ( + "context" "fmt" + "os" "runtime" "time" @@ -82,7 +84,16 @@ func main() { opr = lx.Hash([]byte("foo")) fmt.Printf("%10s = %x, %d, %d, %d\n", "Hash Init", lxr.Seed, lxr.MapSizeBits, lxr.HashSize, lxr.Passes) - c, _ := cpu.Info() + ctx := context.Background() + to, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + c, err := cpu.InfoWithContext(to) + if err != nil { + fmt.Println("There was an error querying the CPU info. Please try again.") + fmt.Println(err) + os.Exit(1) + } + fmt.Printf("%10s = %s\n", "CPU", c[0].ModelName) cores := runtime.NumCPU() fmt.Printf("%10s = %d\n", "Cores", cores)