Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SavePlotLogs setting #49

Merged
merged 5 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ eg. plotng -ui -host plotter1:8484,plotter2,plotter3:8485
"DelaysBetweenPlot": 0,
"MaxActivePlotPerTemp": 0,
"UseTargetForTmp2": false,
"BucketSize": 0
"BucketSize": 0,
"SavePlotLogDir": ""
}

Please note for Windows, please use capital drive letter and '/' eg. "D:/temp"
Expand All @@ -85,5 +86,6 @@ Please note for Windows, please use capital drive letter and '/' eg. "D:/temp"
- MaxActivePlotPerPhase1 : Maximum active plots per Phase 1 (default: 0 - no limit)
- UseTargetForTmp2 : use target directory for tmp2
- BucketSize : specify custom busket size (default: 0 - use chia default)
- SavePlotLogDir : saves plotting logs to this directory. logs are not saved if no directory is provided (default: "")

Please note PlotNG now skips any destination directory which have less than 105GB of disk space, if you set DiskSpaceCheck to true.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"MaxActivePlotPerTemp": 0,
"MaxActivePlotPerPhase1": 0,
"UseTargetForTmp2": false,
"BucketSize": 0
"BucketSize": 0,
"SavePlotLogDir": ""
}
16 changes: 16 additions & 0 deletions internal/activePlot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -51,6 +52,7 @@ type ActivePlot struct {
Pid int
UseTargetForTmp2 bool
BucketSize int
SavePlotLogDir string
process *os.Process
}

Expand Down Expand Up @@ -202,6 +204,7 @@ func (ap *ActivePlot) RunPlot() {

func (ap *ActivePlot) processLogs(in io.ReadCloser) {
reader := bufio.NewReader(in)
var logFile *os.File
for {
if s, err := reader.ReadString('\n'); err != nil {
break
Expand All @@ -219,6 +222,16 @@ func (ap *ActivePlot) processLogs(in io.ReadCloser) {
}
if strings.HasPrefix(s, "ID: ") {
ap.Id = strings.TrimSuffix(s[4:], "\n")
if len(ap.SavePlotLogDir) > 0 {
logFilePath := filepath.Join(ap.SavePlotLogDir, fmt.Sprintf("plotng_log_%s.txt", ap.Id))
logFile, err = os.Create(logFilePath)
if err != nil {
break
}
for _, l := range ap.Tail {
logFile.Write([]byte(l))
}
}
}
for phaseStr, progress := range progressTable {
if strings.Index(s, phaseStr) >= 0 {
Expand All @@ -227,6 +240,9 @@ func (ap *ActivePlot) processLogs(in io.ReadCloser) {
}
}
ap.lock.Lock()
if logFile != nil {
logFile.Write([]byte(s))
}
ap.Tail = append(ap.Tail, s)
if len(ap.Tail) > 20 {
ap.Tail = ap.Tail[len(ap.Tail)-20:]
Expand Down
1 change: 1 addition & 0 deletions internal/plotConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
MaxActivePlotPerPhase1 int
UseTargetForTmp2 bool
BucketSize int
SavePlotLogDir string
}

type PlotConfig struct {
Expand Down
1 change: 1 addition & 0 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (server *Server) createNewPlot(config *Config) {
DisableBitField: config.DisableBitField,
UseTargetForTmp2: config.UseTargetForTmp2,
BucketSize: config.BucketSize,
SavePlotLogDir: config.SavePlotLogDir,
Phase: "NA",
Tail: nil,
State: PlotRunning,
Expand Down