github.com/coreos/mantle@v0.13.0/cmd/kola/bootchart.go (about) 1 // Copyright 2015 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "fmt" 19 "os" 20 21 "github.com/spf13/cobra" 22 23 "github.com/coreos/mantle/kola" 24 "github.com/coreos/mantle/platform" 25 ) 26 27 var cmdBootchart = &cobra.Command{ 28 Run: runBootchart, 29 PreRun: preRun, 30 Use: "bootchart > bootchart.svg", 31 Short: "Boot performance graphing tool", 32 Long: ` 33 Boot a single instance and plot how the time was spent. 34 35 Note that this actually uses systemd-analyze plot rather than 36 systemd-bootchart since the latter requires setting a different 37 init process. 38 39 This must run as root! 40 `} 41 42 func init() { 43 root.AddCommand(cmdBootchart) 44 } 45 46 func runBootchart(cmd *cobra.Command, args []string) { 47 if len(args) != 0 { 48 fmt.Fprintf(os.Stderr, "No args accepted\n") 49 os.Exit(2) 50 } 51 52 var err error 53 outputDir, err = kola.SetupOutputDir(outputDir, kolaPlatform) 54 if err != nil { 55 fmt.Fprintf(os.Stderr, "Setup failed: %v\n", err) 56 os.Exit(1) 57 } 58 59 flight, err := kola.NewFlight(kolaPlatform) 60 if err != nil { 61 fmt.Fprintf(os.Stderr, "Flight failed: %v\n", err) 62 os.Exit(1) 63 } 64 defer flight.Destroy() 65 66 cluster, err := flight.NewCluster(&platform.RuntimeConfig{ 67 OutputDir: outputDir, 68 }) 69 if err != nil { 70 fmt.Fprintf(os.Stderr, "Cluster failed: %v\n", err) 71 os.Exit(1) 72 } 73 defer cluster.Destroy() 74 75 m, err := cluster.NewMachine(nil) 76 if err != nil { 77 fmt.Fprintf(os.Stderr, "Machine failed: %v\n", err) 78 os.Exit(1) 79 } 80 defer m.Destroy() 81 82 out, stderr, err := m.SSH("systemd-analyze plot") 83 if err != nil { 84 fmt.Fprintf(os.Stderr, "SSH failed: %v: %s\n", err, stderr) 85 os.Exit(1) 86 } 87 88 fmt.Printf("%s", out) 89 }