package main

import (
	"flag"
	"fmt"
	"os"

	"github.com/jfraeys/fetch_ml/tools"
)

func main() {
	cpuProfile := flag.String("cpu-profile", "", "Path to a CPU profile file to analyze")
	flag.Parse()

	if *cpuProfile == "" {
		_, _ = fmt.Fprintln(os.Stderr, "usage: profiler -cpu-profile <file>")
		os.Exit(2)
	}

	p := tools.NewProfiler(tools.ProfileConfig{CPUProfile: *cpuProfile})
	analysis, err := p.AnalyzeProfiles()
	if err != nil {
		_, _ = fmt.Fprintf(os.Stderr, "failed to analyze profiles: %v\n", err)
		os.Exit(1)
	}

	p.PrintAnalysis(analysis)
}
