-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
84 lines (71 loc) · 3.38 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import subprocess
from pathlib import Path
import platform
from datetime import datetime
import config_loader
import log_utils as wp
from utils import get_disk_info
from stagging import get_staging_plot_dir
from harvest_disk import harvest_all_disk, calculate_plot
from replot import can_delete_plot, find_plot_to_destroy
def get_nbr_plottable_max(disk_path: str) -> int:
_, _, free = get_disk_info(disk_path)
max_plottable = int(free / config_loader.chia_const[config_loader.Config.compression_level]['gib'])
if max_plottable > 1:
return max_plottable - 1
return max_plottable
def get_binary_path() -> Path:
if platform.system() == 'Windows':
return Path('./binaries/bladebit_cuda.exe')
else:
return Path('./binaries/bladebit_cuda')
def create_plotter_argument(disk_path: str) -> list:
plotter_args = [
get_binary_path(),
'-f', config_loader.Config.farmer_key,
'-n', get_nbr_plottable_max(disk_path),
'-c', config_loader.Config.contract_key,
'--compress', config_loader.Config.compression_level,
'cudaplot'
]
if config_loader.Config.plot_with_128GO_ram_only:
plotter_args = plotter_args + ['--disk-128', '-t1', Path(config_loader.Config.tmp_plot_directory_for_128go_ram_support)]
if config_loader.Config.use_staging_directories and get_staging_plot_dir() is not None:
plotter_args.append(Path(get_staging_plot_dir()))
else:
plotter_args.append(Path(disk_path))
return plotter_args
def run_plot(disk_path: str):
clock_start = datetime.now()
wp.Logger.bladebit_plotter_logger.log(wp.Logger.INFO, 'going to run plot with clock {}'.format(clock_start))
try:
cmd_string = ' '.join(map(str, create_plotter_argument(disk_path)))
wp.Logger.bladebit_plotter_logger.log(wp.Logger.INFO, 'Going to run cmd `{}`'.format(cmd_string))
with subprocess.Popen(cmd_string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True,
text=True) as process:
for line in process.stdout:
wp.Logger.bladebit_plotter_logger.log(wp.Logger.INFO, line.strip())
for line in process.stderr:
wp.Logger.bladebit_plotter_logger.log(wp.Logger.FAILED, line.strip())
process.wait()
if process.returncode == 0:
clock_end = datetime.now()
delta = clock_end - clock_start
wp.Logger.bladebit_plotter_logger.log(wp.Logger.SUCCESS,
'Command executed successfully. Clock is {}, duration is {} ms'.format(clock_end, delta.seconds))
else:
clock_end = datetime.now()
delta = clock_end - clock_start
wp.Logger.bladebit_plotter_logger.log(wp.Logger.FAILED, 'Clock is {}, duration is {} ms. Command failed with error:'.format(clock_end, delta.seconds))
except Exception as e:
wp.Logger.bladebit_plotter_logger.log(wp.Logger.FAILED, 'An error occurred: {}'.format(e))
def plot_runner():
path_plottable = "None"
while path_plottable is not None:
disk_space = harvest_all_disk()
path_plottable = calculate_plot(disk_space)
if path_plottable is not None:
run_plot(path_plottable)
if config_loader.Config.mode == 'replot' and path_plottable is False:
plot_name = find_plot_to_destroy()
path_plottable = can_delete_plot(plot_name)