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

Fix savedir, request mem and mem usage #803

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

# 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())"))

Check warning on line 36 in src/optimization.jl

View check run for this annotation

Codecov / codecov/patch

src/optimization.jl#L35-L36

Added lines #L35 - L36 were not covered by tests
else
savedir = abspath(joinpath(save_folder, "$(generation)__$(Dates.now())__$(getpid())"))

Check warning on line 38 in src/optimization.jl

View check run for this annotation

Codecov / codecov/patch

src/optimization.jl#L38

Added line #L38 was not covered by tests
end
mkdir(savedir)
cd(savedir)

Expand Down
11 changes: 6 additions & 5 deletions src/utils_begin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,20 @@
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

Check warning on line 327 in src/utils_begin.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_begin.jl#L327

Added line #L327 was not covered by tests
elseif Sys.isunix()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit worried about this Sys.isunix() test before Sys.islinux() test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing was changed with respect to that (just a comment that this in GiB)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but should we move the Sys.isunix() check as the last option?

I fear that a Linux system might fall into this if statement and not go in the Sys.islinux()

# 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

Check warning on line 331 in src/utils_begin.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_begin.jl#L331

Added line #L331 was not covered by tests
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

Check warning on line 336 in src/utils_begin.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_begin.jl#L334-L336

Added lines #L334 - L336 were not covered by tests
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

Check warning on line 340 in src/utils_begin.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_begin.jl#L340

Added line #L340 was not covered by tests
else
error("couldn't determine the mem_size")
end
Expand Down
17 changes: 13 additions & 4 deletions src/utils_end.jl
Original file line number Diff line number Diff line change
Expand Up @@ -808,19 +808,28 @@
[], []
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()

Check warning on line 818 in src/utils_end.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_end.jl#L817-L818

Added lines #L817 - L818 were not covered by tests
# 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

Check warning on line 823 in src/utils_end.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_end.jl#L820-L823

Added lines #L820 - L823 were not covered by tests
else
pid = getpid()
mem_info = read(`ps -p $pid -o rss=`, String)
mem_usage_kb = parse(Int, strip(mem_info))

Check warning on line 827 in src/utils_end.jl

View check run for this annotation

Codecov / codecov/patch

src/utils_end.jl#L825-L827

Added lines #L825 - L827 were not covered by tests
end
return mem_usage_kb * 1024
end


"""
save(memtrace::MemTrace, filename::String="memtrace.txt")

Expand Down
Loading