-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[MISC] Add benchmark test memory monitoring. #1981
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
Merged
duburcqa
merged 16 commits into
Genesis-Embodied-AI:main
from
hughperkins:hp/add-mem-monitoring
Jan 6, 2026
+158
−2
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48b45ed
--mem-monitoring-filepath
hughperkins 4506521
comment out other tests
hughperkins ef646f0
mkdir logs
hughperkins 37cc553
lgs -lh logs
hughperkins 5281ac4
add tryfirst=True
hughperkins 18393d0
setproctitle
hughperkins 935e048
add setproctilteo pyproject.toml
hughperkins d93c914
move earlier in funciotn
hughperkins e1a2aec
try starting process
hughperkins dbd26a7
add is_mem_monitoring_supported
hughperkins 5d546f3
set process name, and check if mem monitoring supported
hughperkins 444cd62
path to /mnt/data/artifacts
hughperkins 37e8e7b
remove test code
hughperkins 401f4c0
remove more test code
hughperkins 7c2c882
Uncomment workflows.
duburcqa accf4cd
Merge branch 'main' into hp/add-mem-monitoring
duburcqa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| from collections import defaultdict | ||
| import csv | ||
| import subprocess | ||
| import time | ||
| import os | ||
| import argparse | ||
| import psutil | ||
|
|
||
|
|
||
| def grep(contents: list[str], target): | ||
| return [l for l in contents if target in l] | ||
|
|
||
|
|
||
| def get_cuda_usage() -> dict[int, int]: | ||
| output = subprocess.check_output(["nvidia-smi"]).decode("utf-8") | ||
| section = 0 | ||
| subsec = 0 | ||
| res = {} | ||
| for line in output.split("\n"): | ||
| if line.startswith("|============"): | ||
| section += 1 | ||
| subsec = 0 | ||
| continue | ||
| if line.startswith("+-------"): | ||
| subsec += 1 | ||
| continue | ||
| if section == 2 and subsec == 0: | ||
| if "No running processes" in line: | ||
| continue | ||
| split_line = line.split() | ||
| pid = int(split_line[4]) | ||
| mem = int(split_line[-2].split("MiB")[0]) | ||
| res[pid] = mem | ||
| return res | ||
|
|
||
|
|
||
| def get_test_name_by_pid() -> dict[int, str]: | ||
| test_by_psid = {} | ||
| for proc in psutil.process_iter(["pid", "cmdline"]): | ||
| try: | ||
| cmdline = proc.info["cmdline"] | ||
| if cmdline is None: | ||
| continue | ||
| # Join cmdline to get full command string | ||
| cmd_str = " ".join(cmdline) | ||
| if "pytest: tests" in cmd_str: | ||
| # Find the test name after "::" | ||
| if "::" in cmd_str: | ||
| test_name = cmd_str.partition("::")[2] | ||
| if test_name.strip() != "": | ||
| test_by_psid[proc.info["pid"]] = test_name | ||
| except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): | ||
| # Process may have terminated or we don't have permission | ||
| pass | ||
| return test_by_psid | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--out-csv-filepath", type=str, required=True) | ||
| parser.add_argument("--die-with-parent", action="store_true") | ||
| args = parser.parse_args() | ||
|
|
||
| max_mem_by_test = defaultdict(int) | ||
|
|
||
| f = open(args.out_csv_filepath, "w") | ||
| dict_writer = csv.DictWriter(f, fieldnames=["test", "max_mem_mb"]) | ||
| dict_writer.writeheader() | ||
| old_mem_by_test = {} | ||
| num_results_written = 0 | ||
| disp = False | ||
| while not args.die_with_parent or os.getppid() != 1: | ||
| mem_by_pid = get_cuda_usage() | ||
| test_by_psid = get_test_name_by_pid() | ||
| num_tests = len(test_by_psid) | ||
| _mem_by_test = {} | ||
| for psid, test in test_by_psid.items(): | ||
| if psid not in mem_by_pid: | ||
| continue | ||
| if test.strip() == "": | ||
| continue | ||
| _mem = mem_by_pid[psid] | ||
| _mem_by_test[test] = _mem | ||
| for test, _mem in _mem_by_test.items(): | ||
| max_mem_by_test[test] = max(_mem, max_mem_by_test[test]) | ||
| for _test, _mem in old_mem_by_test.items(): | ||
| if _test not in _mem_by_test: | ||
| dict_writer.writerow({"test": _test, "max_mem_mb": max_mem_by_test[_test]}) | ||
| f.flush() | ||
| num_results_written += 1 | ||
| spinny = "x" if disp else "+" | ||
| print( | ||
| num_tests, | ||
| "tests running, of which", | ||
| len(_mem_by_test), | ||
| "on gpu. Num results written: ", | ||
| num_results_written, | ||
| "[updating]", | ||
| " ", | ||
| end="\r", | ||
| flush=True, | ||
| ) | ||
| old_mem_by_test = _mem_by_test | ||
| disp = not disp | ||
| time.sleep(2.0) | ||
| print("Test monitor exiting") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.