Commit 6e26d46d authored by one's avatar one
Browse files

[xcl-lens] Allow a file as input

parent a049d737
......@@ -61,16 +61,14 @@ mpirun -np 4 xcl-lens \
### Process an Existing File
```bash
xcl-lens cat rccl-log.txt
xcl-lens rccl-log.txt
cat rccl-log.txt | xcl-lens
```
### Verbose Mode
### Options
By default, only the report is printed. Use `-v` or `--verbose` to also print raw log lines:
```bash
xcl-lens -v ./build/all_reduce_perf -b 4 -e 2G -f 2 -w 3 -n 3 -g 1
```
`--summary` is used to suppress the raw log.
`-v` is used to extend summary reports.
## Development
......
......@@ -32,23 +32,63 @@ def main():
log_prefix = f"[Rank {rank}]"
# Parse command line arguments
parser = argparse.ArgumentParser(description="RCCL Log Parser Wrapper")
parser.add_argument(
"--no-raw", action="store_true", help="Don't print raw log lines in addition to the report"
parser = argparse.ArgumentParser(
description="RCCL Log Parser Wrapper\n\n"
"Usage modes:\n"
" 1. Pipe input: cat log.txt | xcl-lens\n"
" 2. Read files: xcl-lens log1.txt log2.txt\n"
" 3. Wrap command: xcl-lens ./all_reduce_perf",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("--summary", action="store_true", help="Print summary report only")
parser.add_argument("-v", "--verbose", action="store_true", help="Print verbose reports")
parser.add_argument(
"command", nargs=argparse.REMAINDER, help="The executable and arguments to run"
"command", nargs=argparse.REMAINDER, help="Executable to run, or log files to read"
)
args = parser.parse_args()
cmd = args.command
# Check if command is provided
if not cmd and rank == 0:
parser.print_help()
sys.exit(1)
# Case 1: No command provided - check for stdin
if not cmd:
if not sys.stdin.isatty():
try:
rccl_parser = RcclLogParser()
for line in sys.stdin:
if not args.summary:
print(f"{line}", end="", flush=True)
rccl_parser.collect(line)
if rank == 0:
rccl_parser.report(verbose=args.verbose)
sys.exit(0)
except KeyboardInterrupt:
sys.exit(130)
else:
if rank == 0:
parser.print_help()
sys.exit(1)
# Case 2: Check if first argument is an existing file (treat as log file)
if os.path.isfile(cmd[0]):
try:
rccl_parser = RcclLogParser()
for filename in cmd:
if not os.path.isfile(filename):
print(f"{log_prefix} Error: File not found: {filename}")
sys.exit(1)
with open(filename, encoding="utf-8", errors="replace") as f:
for line in f:
if not args.summary:
print(f"{line}", end="", flush=True)
rccl_parser.collect(line)
if rank == 0:
rccl_parser.report(verbose=args.verbose)
sys.exit(0)
except KeyboardInterrupt:
sys.exit(130)
# Get the environment variables
env = os.environ.copy()
......@@ -72,7 +112,7 @@ def main():
# Collect all output lines
for line in process.stdout:
if not args.no_raw:
if not args.summary:
print(f"{line}", end="", flush=True)
parser.collect(line)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment