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

Con duct ls #224

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
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
7 changes: 4 additions & 3 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
lgr = logging.getLogger("con-duct")
DEFAULT_LOG_LEVEL = os.environ.get("DUCT_LOG_LEVEL", "INFO").upper()

DUCT_OUTPUT_PREFIX = os.getenv(
"DUCT_OUTPUT_PREFIX", ".duct/logs/{datetime_filesafe}-{pid}_"
)
ENV_PREFIXES = ("PBS_", "SLURM_", "OSG")
SUFFIXES = {
"stdout": "stdout",
Expand Down Expand Up @@ -712,9 +715,7 @@ def from_argv(
"-p",
"--output-prefix",
type=str,
default=os.getenv(
"DUCT_OUTPUT_PREFIX", ".duct/logs/{datetime_filesafe}-{pid}_"
),
default=DUCT_OUTPUT_PREFIX,
help="File string format to be used as a prefix for the files -- the captured "
"stdout and stderr and the resource usage logs. The understood variables are "
"{datetime}, {datetime_filesafe}, and {pid}. "
Expand Down
55 changes: 55 additions & 0 deletions src/con_duct/suite/ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import argparse
import glob
import json
from pprint import pprint
import yaml
from con_duct.__main__ import DUCT_OUTPUT_PREFIX, SummaryFormatter

LS_SUMMARY_FORMAT = (
"Command: {command}\n"
"\tWall Clock Time: {execution_summary[wall_clock_time]:.3f} sec\n"
"\tMemory Peak Usage (RSS): {execution_summary[peak_rss]!S}\n"
"\tVirtual Memory Peak Usage (VSZ): {execution_summary[peak_vsz]!S}\n"
"\tMemory Peak Percentage: {execution_summary[peak_pmem]:.2f!N}%\n"
"\tCPU Peak Usage: {execution_summary[peak_pcpu]:.2f!N}%\n"
)
# "Log files location: {logs_prefix}\n"
# "Memory Peak Usage (RSS): {peak_rss!S}\n"
# "Memory Average Usage (RSS): {average_rss!S}\n"
# "Virtual Memory Peak Usage (VSZ): {peak_vsz!S}\n"
# "Virtual Memory Average Usage (VSZ): {average_vsz!S}\n"
# "Memory Peak Percentage: {peak_pmem:.2f!N}%\n"
# "Memory Average Percentage: {average_pmem:.2f!N}%\n"
# "CPU Peak Usage: {peak_pcpu:.2f!N}%\n"
# "Average CPU Usage: {average_pcpu:.2f!N}%\n"
#


def ls(args: argparse.Namespace) -> int:
pattern = f"{DUCT_OUTPUT_PREFIX[:DUCT_OUTPUT_PREFIX.index('{')]}*_info.json"
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
duct_runs = glob.glob(pattern)
if args.format == "summaries":
formatter = SummaryFormatter() # TODO enable_colors=self.colors)
for info_file in duct_runs:
with open(info_file) as file:
data = json.loads(file.read())
# print(json.dumps(data))
print(formatter.format(LS_SUMMARY_FORMAT, **data))
return 0
if args.format == "json":
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
for info_file in duct_runs:
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
with open(info_file) as file:
print(file.read())
return 0
if args.format == "jsonpp":
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
for info_file in duct_runs:
with open(info_file, "r") as file:
data = json.load(file)
pprint(data)
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
return 0
if args.format == "yaml":
for info_file in duct_runs:
with open(info_file) as file:
data = json.load(file)
print(yaml.dump(data, default_flow_style=False))
return 0
14 changes: 14 additions & 0 deletions src/con_duct/suite/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import sys
from typing import List, Optional
from con_duct.suite.ls import ls
from con_duct.suite.plot import matplotlib_plot
from con_duct.suite.pprint_json import pprint_json

Expand Down Expand Up @@ -46,6 +47,19 @@ def main(argv: Optional[List[str]] = None) -> None:
# )
parser_plot.set_defaults(func=matplotlib_plot)

parser_ls = subparsers.add_parser(
"ls",
help="Print execution information for all runs matching DUCT_OUTPUT_PREFIX.",
)
parser_ls.add_argument(
"-f",
"--format",
choices=("summaries", "json", "jsonpp", "yaml"),
default="summaries", # TODO dry
help="Output format. TODO Fixme",
)
parser_ls.set_defaults(func=ls)

args = parser.parse_args(argv)

if args.command is None:
Expand Down
Loading