Skip to content

Enhance log file handling in copy_local_to_tmpdir and oss_parse #14

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 20 additions & 8 deletions tritonparse/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,33 @@ def copy_local_to_tmpdir(local_path: str, verbose: bool = False) -> str:
Copy local log files to a temporary directory.

Args:
local_path: Path to local directory containing logs
local_path: Path to local directory or single file containing logs
verbose: Whether to print verbose information

Returns:
Path to temporary directory containing copied logs

Raises:
RuntimeError: If the local_path does not exist
"""
if not os.path.exists(local_path):
raise RuntimeError(f"Path does not exist: {local_path}")

temp_dir = tempfile.mkdtemp()

# Handle single file case
if os.path.isfile(local_path):
if os.path.basename(local_path).startswith(LOG_PREFIX):
if verbose:
logger.info(f"Copying single file {local_path} to {temp_dir}")
shutil.copy2(local_path, temp_dir)
return temp_dir

# Handle directory case
if not os.path.isdir(local_path):
raise RuntimeError(
f"Path is neither a file nor a directory: {local_path}")

for item in os.listdir(local_path):
item_path = os.path.join(local_path, item)
if os.path.isfile(item_path) and os.path.basename(item_path).startswith(
Expand Down Expand Up @@ -319,13 +338,6 @@ def save_logs(out_dir: Path, parsed_logs: str, overwrite: bool, verbose: bool) -
if not out_dir.is_absolute():
out_dir = out_dir.resolve()

if out_dir.exists():
if not overwrite:
raise RuntimeError(
f"{out_dir} already exists, pass --overwrite to overwrite"
)
shutil.rmtree(out_dir)

os.makedirs(out_dir, exist_ok=True)

logger.info(f"Copying parsed logs from {parsed_logs} to {out_dir}")
Expand Down
25 changes: 13 additions & 12 deletions tritonparse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def oss_parse(args):
source = Source(args.source, verbose)
rank_config = RankConfig.from_cli_args(args.rank, args.all_ranks, source.type)

# Check output directory early if specified
if args.out is not None:
out_dir = Path(args.out)
if out_dir.exists():
if not args.overwrite:
raise RuntimeError(
f"{out_dir} already exists, pass --overwrite to overwrite"
)
shutil.rmtree(out_dir)
os.makedirs(out_dir, exist_ok=True)

# For signpost logging (not implemented in Python version)

if source.type == SourceType.LOCAL:
Expand All @@ -75,18 +86,8 @@ def oss_parse(args):

elif source.type == SourceType.LOCAL_FILE:
local_path = source.value

if args.out is not None:
out_dir = Path(args.out)
if out_dir.exists():
if not args.overwrite:
raise RuntimeError(
f"{out_dir} already exists, pass --overwrite to overwrite"
)
shutil.rmtree(out_dir)

os.makedirs(out_dir, exist_ok=True)
return
# Copy the single file to a temp directory, then parse it
logs = copy_local_to_tmpdir(local_path, verbose)

parsed_log_dir, _ = parse_logs(logs, rank_config, verbose)
if args.out is not None:
Expand Down