Skip to content

Commit

Permalink
Fixed CPU threadcount for xmr-stak
Browse files Browse the repository at this point in the history
  • Loading branch information
Donovan Solms committed May 28, 2018
1 parent 4e8562b commit 172752e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bundler.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"app_name": "Stellite GUI Miner v1.1.0",
"environments": [
{"arch": "amd64", "os": "darwin"},
{"arch": "amd64", "os": "linux"},
{"arch": "amd64", "os": "darwin"},
{
"arch": "amd64",
"os": "windows",
Expand Down
10 changes: 10 additions & 0 deletions src/bundler_dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app_name": "Stellite GUI Miner v1.1.0",
"environments": [
{"arch": "amd64", "os": "linux"}
],
"icon_path_darwin": "resources/icon.icns",
"icon_path_linux": "resources/icon.png",
"icon_path_windows": "resources/icon.ico",
"output_path": "../bin"
}
42 changes: 40 additions & 2 deletions src/gui/miner/xmr_stak.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
)

// XmrStak implements the miner interface for the xmr-stak miner
Expand Down Expand Up @@ -118,8 +120,10 @@ func (miner *XmrStak) WriteConfig(
// TODO: Currently only CPU threads, extend this to full CPU/GPU config
func (miner *XmrStak) GetProcessingConfig() ProcessingConfig {
return ProcessingConfig{
MaxUsage: 0,
Threads: uint16(len(miner.resultStatsCache.Hashrate.Threads)),
MaxUsage: 0,
// xmr-stak reports GPU + CPU threads in the same section, for that reason
// we need to check the actual cpu.txt file to get the real thread count
Threads: miner.getCPUThreadcount(),
MaxThreads: uint16(runtime.NumCPU()),
Type: miner.name,
}
Expand All @@ -135,6 +139,40 @@ func (miner *XmrStak) GetLastHashrate() float64 {
return miner.lastHashrate
}

// getCPUThreadcount returns the threads used for the CPU as read from the
// config
func (miner *XmrStak) getCPUThreadcount() uint16 {
configPath := filepath.Join(miner.Base.executablePath, "cpu.txt")
configFileBytes, err := ioutil.ReadFile(configPath)
// If config file doesn't exist, return 0 as the threadcount
if err != nil {
return 0
}
// xmr-stak uses a strange JSON-like format, I haven't found a Go library
// that can parse the file, so we're doing some basic string matches
lines := strings.Split(string(configFileBytes), "\n")
var validLines string
for _, line := range lines {
for _, char := range line {
// This is a very very very basic check if this line is actually a comment
if string(char) == "/" || string(char) == "*" {
// Skip this line
break
} else {
validLines += string(char)
}
}
}

var threadcount uint16
// Match anything enclosed in {} for JSON object
var re = regexp.MustCompile(`{*}`)
for _ = range re.FindAllString(validLines, -1) {
threadcount++
}
return threadcount
}

// GetStats returns the current miner stats
func (miner *XmrStak) GetStats() (Stats, error) {
var stats Stats
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func main() {
if err != nil {
log.Fatalf("Can't read current directory: %s", err)
}
// HACK For local development comment out filepath.Dir here

// HACK For local development comment out filepath.Dir here
workingDir = filepath.Dir(workingDir)
if err != nil {
log.Fatalf("Can't format current directory: %s", err)
Expand Down

0 comments on commit 172752e

Please sign in to comment.