mirror of https://github.com/liamg/aminal.git
Add option for generating CPU profile (#248)
This commit is contained in:
parent
ed8656930a
commit
a355d10656
|
@ -28,6 +28,7 @@ func getConfig() *config.Config {
|
|||
shell := ""
|
||||
debugMode := false
|
||||
slomo := false
|
||||
cpuProfile := ""
|
||||
|
||||
if flag.Parsed() == false {
|
||||
flag.BoolVar(&showVersion, "version", showVersion, "Output version information")
|
||||
|
@ -35,6 +36,7 @@ func getConfig() *config.Config {
|
|||
flag.StringVar(&shell, "shell", shell, "Specify the shell to use")
|
||||
flag.BoolVar(&debugMode, "debug", debugMode, "Enable debug logging")
|
||||
flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)")
|
||||
flag.StringVar(&cpuProfile, "cpuprofile", cpuProfile, "Write a CPU profile to this file")
|
||||
|
||||
flag.Parse() // actual parsing and fetching flags from the command line
|
||||
}
|
||||
|
@ -69,6 +71,10 @@ func getConfig() *config.Config {
|
|||
conf.Slomo = slomo
|
||||
}
|
||||
|
||||
if actuallyProvidedFlags["cpuprofile"] {
|
||||
conf.CPUProfile = cpuProfile
|
||||
}
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
DebugMode bool `toml:"debug"`
|
||||
Slomo bool `toml:"slomo"`
|
||||
ColourScheme ColourScheme `toml:"colours"`
|
||||
DPIScale float32 `toml:"dpi-scale"`
|
||||
Shell string `toml:"shell"`
|
||||
|
@ -16,6 +14,11 @@ type Config struct {
|
|||
SearchURL string `toml:"search_url"`
|
||||
MaxLines uint64 `toml:"max_lines"`
|
||||
CopyAndPasteWithMouse bool `toml:"copy_and_paste_with_mouse"`
|
||||
|
||||
// Developer options.
|
||||
DebugMode bool `toml:"debug"`
|
||||
Slomo bool `toml:"slomo"`
|
||||
CPUProfile string `toml:"cpu_profile"`
|
||||
}
|
||||
|
||||
type KeyMappingConfig map[string]string
|
||||
|
|
23
main.go
23
main.go
|
@ -2,12 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/liamg/aminal/gui"
|
||||
"github.com/liamg/aminal/platform"
|
||||
"github.com/liamg/aminal/terminal"
|
||||
"github.com/riywo/loginshell"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
||||
|
@ -29,8 +32,13 @@ func initialize(unitTestfunc callback) {
|
|||
}
|
||||
defer logger.Sync()
|
||||
|
||||
logger.Infof("Allocating pty...")
|
||||
if conf.CPUProfile != "" {
|
||||
logger.Infof("Starting CPU profiling...")
|
||||
stop := startCPUProf(conf.CPUProfile)
|
||||
defer stop()
|
||||
}
|
||||
|
||||
logger.Infof("Allocating pty...")
|
||||
pty, err := platform.NewPty(80, 25)
|
||||
if err != nil {
|
||||
logger.Fatalf("Failed to allocate pty: %s", err)
|
||||
|
@ -78,3 +86,12 @@ func initialize(unitTestfunc callback) {
|
|||
logger.Fatalf("Render error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func startCPUProf(filename string) func() {
|
||||
profileFile, err := os.Create(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(profileFile)
|
||||
return pprof.StopCPUProfile
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue