in pkg/display/graph/flamegraph/flamegraph.go [83:105]
func renderFlameGraphAndWrite(path string, data map[string]interface{}) error {
// render template
var b bytes.Buffer
tmpl, err := template.New("flameGraphTemplate").Parse(flameGraphHTML)
if err != nil {
return fmt.Errorf("failed to parse flame graph template: %v", err)
}
if err = tmpl.Execute(&b, data); err != nil {
return fmt.Errorf("failed to render flame graph: %v", err)
}
// write to file
file, err := os.Create(path)
if err != nil {
return fmt.Errorf("could not create the flame graph file, %v", err)
}
_, err = file.Write(b.Bytes())
if err != nil {
return fmt.Errorf("could not write the flame graph to file, %v", err)
}
logger.Log.Infof("success write the flame graph to: %s", path)
return nil
}