-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add debug gops Signed-off-by: ysicing <i@ysicing.me>
- Loading branch information
Showing
7 changed files
with
344 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2023 ysicing(ysicing.me, ysicing@ysicing.cloud) All rights reserved. | ||
// Use of this source code is covered by the following dual licenses: | ||
// (1) Y PUBLIC LICENSE 1.0 (YPL 1.0) | ||
// (2) Affero General Public License 3.0 (AGPL 3.0) | ||
// License that can be found in the LICENSE file. | ||
|
||
package debug | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
tops "github.com/ysicing/tiga/internal/pkg/gops" | ||
"github.com/ysicing/tiga/pkg/factory" | ||
) | ||
|
||
func GOpsCommand(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "gops", | ||
Short: "gops is a tool to list and diagnose Go processes.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(os.Args) > 3 { | ||
_, err := strconv.Atoi(os.Args[3]) | ||
if err == nil { | ||
f.GetLog().Infof("fetch pid %s process info", os.Args[3]) | ||
tops.ProcessInfo(os.Args[3:]) // shift off the command name | ||
return | ||
} | ||
} | ||
f.GetLog().Info("fetch all process info") | ||
tops.Processes() | ||
}, | ||
} | ||
cmd.AddCommand(treeCommand()) | ||
cmd.AddCommand(processCommand()) | ||
return cmd | ||
} | ||
|
||
// treeCommand displays a process tree. | ||
func treeCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "tree", | ||
Short: "Display parent-child tree for Go processes.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
tops.DisplayProcessTree() | ||
}, | ||
} | ||
} | ||
|
||
// processCommand displays information about a Go process. | ||
func processCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "process", | ||
Aliases: []string{"pid", "proc"}, | ||
Short: "Prints information about a Go process.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
tops.ProcessInfo(args) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.