diff --git a/src/optimization.jl b/src/optimization.jl index 804722b7b..1a98fa04c 100644 --- a/src/optimization.jl +++ b/src/optimization.jl @@ -32,7 +32,11 @@ function optimization_engine( # create working directory original_dir = pwd() - savedir = abspath(joinpath(save_folder, "$(generation)__$(Dates.now())__$(getpid())")) + if Sys.iswindows() + savedir = abspath(joinpath(save_folder, "$(generation)__$(join(split(string(Dates.now()),":"),"-"))__$(getpid())")) + else + savedir = abspath(joinpath(save_folder, "$(generation)__$(Dates.now())__$(getpid())")) + end mkdir(savedir) cd(savedir) diff --git a/src/utils_begin.jl b/src/utils_begin.jl index f9e938025..3cf05ca25 100644 --- a/src/utils_begin.jl +++ b/src/utils_begin.jl @@ -324,19 +324,20 @@ Determines what the maximum memory is based on the device type (apple, windows, function localhost_memory() if Sys.isapple() cmd = `sysctl hw.memsize` # for OSX - mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^3 + mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^3 # GiB elseif Sys.isunix() # General Unix command (including macOS and Linux) cmd = `free -b` # get memory in bytes - mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^3 + mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^3 # GiB elseif Sys.iswindows() # Windows command - cmd = `wmic ComputerSystem get TotalPhysicalMemory` - mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^3 + cmd = `powershell -Command "Get-CimInstance Win32_ComputerSystem | Select-Object -ExpandProperty TotalPhysicalMemory"` + mem_bytes = parse(Int, readchomp(cmd)) + mem_size = mem_bytes / 1024^3 # GiB elseif Sys.islinux() # Linux-specific command cmd = `grep MemTotal /proc/meminfo` - mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^2 # Linux reports in KB + mem_size = parse(Int, match(r"\d+", readchomp(cmd)).match) / 1024^2 # GiB else error("couldn't determine the mem_size") end diff --git a/src/utils_end.jl b/src/utils_end.jl index 67244282e..dc4e1c4cc 100644 --- a/src/utils_end.jl +++ b/src/utils_end.jl @@ -808,19 +808,27 @@ A plot with the following characteristics: [], [] end end - """ get_julia_process_memory_usage() Returns memory used by current julia process """ function get_julia_process_memory_usage() - pid = getpid() - mem_info = read(`ps -p $pid -o rss=`, String) - mem_usage_kb = parse(Int, strip(mem_info)) + if Sys.iswindows() + pid = getpid() + # Use PowerShell to get the current process's WorkingSet (memory in bytes) + cmd = `powershell -Command "(Get-Process -Id $pid).WorkingSet64"` + mem_bytes_str = readchomp(cmd) + mem_bytes = parse(Int, mem_bytes_str) + return mem_bytes + else + pid = getpid() + mem_info = read(`ps -p $pid -o rss=`, String) + mem_usage_kb = parse(Int, strip(mem_info)) return mem_usage_kb * 1024 end + """ save(memtrace::MemTrace, filename::String="memtrace.txt")