Add trace_analysis/src/trace_analysis/cli.py
This commit is contained in:
parent
6c4d7d2436
commit
2b530d98d8
1 changed files with 30 additions and 0 deletions
30
trace_analysis/src/trace_analysis/cli.py
Normal file
30
trace_analysis/src/trace_analysis/cli.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from .core import analyze_spikes
|
||||
|
||||
def main():
|
||||
"""CLI entrypoint for spike analysis."""
|
||||
parser = argparse.ArgumentParser(description="Analyse eBPF trace events for migration performance spikes.")
|
||||
parser.add_argument("--input", required=True, help="Path to JSON file with eBPF events.")
|
||||
parser.add_argument("--output", required=True, help="Output path for spike analysis report.")
|
||||
args = parser.parse_args()
|
||||
|
||||
input_path = Path(args.input)
|
||||
output_path = Path(args.output)
|
||||
|
||||
if not input_path.exists():
|
||||
raise FileNotFoundError(f"Input file not found: {input_path}")
|
||||
|
||||
report = analyze_spikes(str(input_path))
|
||||
|
||||
# Validate structure (migration_type, timestamp, spike_count mandatory)
|
||||
if not all(k in report for k in ("migration_type", "timestamp", "spike_count")):
|
||||
raise ValueError("Report missing required fields: migration_type, timestamp, spike_count")
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with output_path.open("w", encoding="utf-8") as f:
|
||||
json.dump(report, f, indent=2, default=str)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue