Exemplo n.º 1
0
func runWithOptions(allOpts *options, remaining []string) error {
	pprofRawOutput, err := pprof.GetRaw(allOpts.PProfOptions, remaining)
	if err != nil {
		return fmt.Errorf("could not get raw output from pprof: %v", err)
	}

	callStacks, err := pprof.ParseRaw(pprofRawOutput)
	if err != nil {
		return fmt.Errorf("could not parse raw pprof output: %v", err)
	}

	flameInput, err := renderer.ToFlameInput(callStacks)
	if err != nil {
		return fmt.Errorf("could not convert stacks to flamegraph input: %v", err)
	}

	opts := allOpts.OutputOpts
	if opts.Raw {
		torchlog.Print("Printing raw flamegraph input to stdout")
		fmt.Printf("%s\n", flameInput)
		return nil
	}

	var flameGraphArgs = buildFlameGraphArgs(opts)
	flameGraph, err := renderer.GenerateFlameGraph(flameInput, flameGraphArgs...)
	if err != nil {
		return fmt.Errorf("could not generate flame graph: %v", err)
	}

	if opts.Print {
		torchlog.Print("Printing svg to stdout")
		fmt.Printf("%s\n", flameGraph)
		return nil
	}

	torchlog.Printf("Writing svg to %v", opts.File)
	if err := ioutil.WriteFile(opts.File, flameGraph, 0666); err != nil {
		return fmt.Errorf("could not write output file: %v", err)
	}

	return nil
}
Exemplo n.º 2
0
func runWithOptions(opts *options) error {
	pprofRawOutput, err := pprof.GetRaw(opts.PProfOptions)
	if err != nil {
		return fmt.Errorf("could not get raw output from pprof: %v", err)
	}

	callStacks, err := pprof.ParseRaw(pprofRawOutput)
	if err != nil {
		return fmt.Errorf("could not parse raw pprof output: %v", err)
	}

	flameInput, err := renderer.ToFlameInput(callStacks)
	if err != nil {
		return fmt.Errorf("could not convert stacks to flamegraph input: %v", err)
	}

	if opts.Raw {
		log.Print("Printing raw flamegraph input to stdout")
		fmt.Printf("%s", flameInput)
		return nil
	}

	flameGraph, err := renderer.GenerateFlameGraph(flameInput)
	if err != nil {
		return fmt.Errorf("could not generate flame graph: %v", err)
	}

	if opts.Print {
		log.Print("Printing svg to stdout")
		fmt.Printf("%s", flameGraph)
		return nil
	}

	log.Printf("Writing svg to %v", opts.File)
	if err := ioutil.WriteFile(opts.File, flameGraph, 0666); err != nil {
		return fmt.Errorf("could not write output file: %v", err)
	}

	return nil
}