Skip to content

Commit

Permalink
Subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywonchung committed Aug 2, 2023
1 parent 2561338 commit 7899a14
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions zeus/monitor/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from __future__ import annotations

import time
from typing import Optional
from contextlib import suppress

import rich
import typer
Expand All @@ -14,12 +14,7 @@

@app.command()
def energy(gpu_indices: Optional[list[int]] = None) -> None:
"""Measure the time and energy of GPUs during the duration of the CLI program.
This uses the `ZeusMonitor` class for measurement, ane thus `gpu_indices` respect
the `CUDA_VISIBLE_DEVICES` environment variable.
For instance, if `CUDA_VISIBLE_DEVICES=2,3`, GPU index `1` passed into `gpu_indices`
will be interpreted as CUDA device `3`.
"""Measure the time and energy of GPUs using the ZeusMonitor.
Args:
gpu_indices: Indices of GPUs to monitor. Not ommitted, all GPUs will be monitored.
Expand All @@ -34,15 +29,25 @@ def energy(gpu_indices: Optional[list[int]] = None) -> None:


@app.command()
def power(gpu_indices: Optional[list[int]] = None) -> None:
def power(
gpu_indices: Optional[list[int]] = None, sleep_ms: int = 100, wait: bool = False
) -> None:
"""Monitor the power consumption of GPUs during the duration of the CLI program.
Args:
gpu_indices: Indices of GPUs to monitor. Not ommitted, all GPUs will be monitored.
sleep_ms: The number of milliseconds to sleep after each measurement.
wait: If True, the program will wait for the user to press Enter before starting.
"""
while True:
print("Hi")
time.sleep(1)
try:
if wait:
input("Press Enter to start monitoring power consumption.")
while True:
print("Hi")
time.sleep(sleep_ms / 1000)
except KeyboardInterrupt:
raise typer.Exit()


if __name__ == "__main__":
app()

0 comments on commit 7899a14

Please sign in to comment.