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 := ""
|
shell := ""
|
||||||
debugMode := false
|
debugMode := false
|
||||||
slomo := false
|
slomo := false
|
||||||
|
cpuProfile := ""
|
||||||
|
|
||||||
if flag.Parsed() == false {
|
if flag.Parsed() == false {
|
||||||
flag.BoolVar(&showVersion, "version", showVersion, "Output version information")
|
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.StringVar(&shell, "shell", shell, "Specify the shell to use")
|
||||||
flag.BoolVar(&debugMode, "debug", debugMode, "Enable debug logging")
|
flag.BoolVar(&debugMode, "debug", debugMode, "Enable debug logging")
|
||||||
flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)")
|
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
|
flag.Parse() // actual parsing and fetching flags from the command line
|
||||||
}
|
}
|
||||||
|
@ -69,6 +71,10 @@ func getConfig() *config.Config {
|
||||||
conf.Slomo = slomo
|
conf.Slomo = slomo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if actuallyProvidedFlags["cpuprofile"] {
|
||||||
|
conf.CPUProfile = cpuProfile
|
||||||
|
}
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DebugMode bool `toml:"debug"`
|
|
||||||
Slomo bool `toml:"slomo"`
|
|
||||||
ColourScheme ColourScheme `toml:"colours"`
|
ColourScheme ColourScheme `toml:"colours"`
|
||||||
DPIScale float32 `toml:"dpi-scale"`
|
DPIScale float32 `toml:"dpi-scale"`
|
||||||
Shell string `toml:"shell"`
|
Shell string `toml:"shell"`
|
||||||
|
@ -16,6 +14,11 @@ type Config struct {
|
||||||
SearchURL string `toml:"search_url"`
|
SearchURL string `toml:"search_url"`
|
||||||
MaxLines uint64 `toml:"max_lines"`
|
MaxLines uint64 `toml:"max_lines"`
|
||||||
CopyAndPasteWithMouse bool `toml:"copy_and_paste_with_mouse"`
|
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
|
type KeyMappingConfig map[string]string
|
||||||
|
|
23
main.go
23
main.go
|
@ -2,12 +2,15 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
"github.com/liamg/aminal/gui"
|
"github.com/liamg/aminal/gui"
|
||||||
"github.com/liamg/aminal/platform"
|
"github.com/liamg/aminal/platform"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
"github.com/riywo/loginshell"
|
"github.com/riywo/loginshell"
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
||||||
|
@ -29,8 +32,13 @@ func initialize(unitTestfunc callback) {
|
||||||
}
|
}
|
||||||
defer logger.Sync()
|
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)
|
pty, err := platform.NewPty(80, 25)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("Failed to allocate pty: %s", err)
|
logger.Fatalf("Failed to allocate pty: %s", err)
|
||||||
|
@ -78,3 +86,12 @@ func initialize(unitTestfunc callback) {
|
||||||
logger.Fatalf("Render error: %s", err)
|
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