Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions cmd/shui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func main() {
// Define configuration defaults.
viper.SetDefault("count", 1)
viper.SetDefault("delay", 3)
viper.SetDefault("disable-config", false)
viper.SetDefault("display", "raw")
viper.SetDefault("elasticsearch-addr", "")
viper.SetDefault("elasticsearch-index", "")
Expand Down Expand Up @@ -149,6 +150,10 @@ func main() {
viper.SetDefault("version", false)

// Define arguments.
flag.Bool(
"disable-config",
viper.GetBool("disable-config"),
"Disable config loading, even if \"config\" is provided.")
flag.Bool("help", false, "Show usage.")
flag.Bool("history", viper.GetBool("history"), "Whether or not to use or preserve history.")
flag.Bool("show-help", viper.GetBool("show-help"), "Whether or not to show help displays.")
Expand Down Expand Up @@ -196,17 +201,21 @@ func main() {

// Define configuration sources.
viper.BindPFlags(flag.CommandLine)
viper.SetConfigFile(viper.GetString("config"))
err = viper.ReadInConfig()
if err != nil {
// Exclude errors that indicate a missing configuration file.
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
// FIXME There is currently a bug preventing Viper from ever returning
// `ConfigFileNotFoundError`. For now, skip over any configuration file errors.
//
// See: https://github.com/spf13/viper/issues/1783
// panic(err)
slog.Warn(err.Error())

// Load a configuration file.
if !viper.GetBool("disable-config") {
viper.SetConfigFile(viper.GetString("config"))
err = viper.ReadInConfig()
if err != nil {
// Exclude errors that indicate a missing configuration file.
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
// FIXME There is currently a bug preventing Viper from ever returning
// `ConfigFileNotFoundError`. For now, skip over any configuration file errors.
//
// See: https://github.com/spf13/viper/issues/1783
// panic(err)
slog.Warn(err.Error())
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions internal/lib/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,21 @@ func runQueryExec(query string, history bool) bool {

// Executes a query as a process to profile.
func runQueryProfile(pid string, history bool) bool {
var success = true

slog.Debug("Profiling pid", "pid", pid)

pidInt, err := strconv.Atoi(pid)
e(err)
AddResult(pid, runProfile(pidInt), history)

return true
if _, err := os.FindProcess(pidInt); err != nil {
AddResult(pid, runProfile(pidInt), history)
} else {
slog.Error("Pid not found", "pid", pid)
success = false
}

return success
}

// Reads standard input for results.
Expand Down
Loading