Top Related Projects
Quick Overview
Google's gops is a tool that lets you diagnose your Go programs by reporting information about the running process, such as the Go version, memory usage, and other runtime stats. It's a lightweight, cross-platform tool that can be easily integrated into your Go applications.
Pros
- Lightweight and Cross-Platform: gops is a small, standalone binary that can be easily distributed and used on various platforms, including Windows, macOS, and Linux.
- Comprehensive Diagnostics: gops provides a wide range of information about the running Go process, including memory usage, CPU profiles, stack traces, and more.
- Easy Integration: gops can be easily integrated into your Go applications, allowing you to quickly diagnose and troubleshoot issues during development and production.
- Open-Source: gops is an open-source project, allowing the community to contribute and improve the tool over time.
Cons
- Limited Functionality: While gops provides a lot of useful information, it may not have all the features or diagnostics that some users might need for more complex applications.
- Requires Go Runtime: gops relies on the Go runtime, so it may not be suitable for applications that don't use Go or have a different runtime environment.
- Potential Performance Impact: Depending on how gops is used, it may have a small performance impact on the running application, which could be a concern in some high-performance scenarios.
- Limited Automation: gops is primarily a command-line tool, which may make it less suitable for automated or scripted diagnostics in some cases.
Code Examples
N/A (gops is not a code library)
Getting Started
N/A (gops is not a code library)
Competitor Comparisons
Find, list, and inspect processes from Go (golang).
Pros of go-ps
- Smaller and more focused library, with a single purpose of getting process information.
- Supports multiple platforms, including Windows, Linux, and macOS.
- Provides a simple and straightforward API for retrieving process information.
Cons of go-ps
- Fewer features compared to gops, as it does not provide the same level of process introspection and debugging capabilities.
- May not be as actively maintained or have the same level of community support as gops.
- Lacks some of the advanced features and tools provided by gops, such as the ability to profile and debug running Go processes.
Code Comparison
google/gops:
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage: %s <pid>\n", os.Args[0])
os.Exit(1)
}
pid, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "invalid pid: %v\n", err)
os.Exit(1)
}
agent := gops.NewAgent()
defer agent.Close()
if err := agent.Attach(pid); err != nil {
fmt.Fprintf(os.Stderr, "failed to attach to process: %v\n", err)
os.Exit(1)
}
fmt.Printf("Attached to process %d\n", pid)
select {}
}
mitchellh/go-ps:
func main() {
procs, err := process.Processes()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get processes: %v\n", err)
os.Exit(1)
}
for _, proc := range procs {
fmt.Printf("PID: %d, Command: %s\n", proc.Pid(), proc.Executable())
}
}
psutil for golang
Pros of gopsutil
- Provides a cross-platform library for retrieving system information, including CPU, memory, disk, network, and process-related metrics.
- Supports a wide range of operating systems, including Windows, Linux, macOS, FreeBSD, and OpenBSD.
- Offers a comprehensive set of functions for accessing various system-level data.
Cons of gopsutil
- Lacks the real-time monitoring and profiling capabilities provided by gops.
- May require more manual setup and configuration compared to the more user-friendly gops.
- Focuses more on system-level data retrieval rather than process-level debugging and introspection.
Code Comparison
gops:
func main() {
agent := gops.NewAgent(gops.Options{})
defer agent.Close()
if err := agent.Listen(); err != nil {
log.Fatal(err)
}
// Your application code goes here
}
gopsutil:
func main() {
v, _ := cpu.Percent(time.Second, false)
fmt.Printf("CPU usage: %.2f%%\n", v[0])
m, _ := mem.VirtualMemory()
fmt.Printf("Memory usage: %.2f%%\n", float64(m.Used)/float64(m.Total)*100)
}
Quick and Easy server testing/validation
Pros of Goss
- Goss provides a declarative way to define and test system state, making it easier to ensure consistency across environments.
- Goss supports a wide range of resources, including files, packages, services, and more, allowing for comprehensive system validation.
- Goss has a simple and intuitive syntax, making it accessible for both developers and operations teams.
Cons of Goss
- Goss may have a steeper learning curve compared to gops, as it requires understanding the declarative syntax and resource types.
- Goss is primarily focused on system validation, while gops provides a broader set of tools for Go process introspection.
- Goss may have a smaller community and ecosystem compared to the more widely-used gops.
Code Comparison
Gops (Google's Go Process Signals):
func main() {
gops.PrintAndExit(os.Getpid())
}
Goss:
file:
/etc/passwd:
exists: true
owned-by: root
grouped-by: root
mode: 0644
filetype: file
Top-like interface for container metrics
Pros of ctop
- ctop provides a more user-friendly and intuitive interface for monitoring and managing containers, with a terminal-based dashboard.
- ctop supports a wide range of container runtimes, including Docker, Kubernetes, and Podman, making it a versatile tool.
- ctop offers real-time updates and the ability to sort and filter containers based on various metrics.
Cons of ctop
- ctop is primarily focused on container monitoring and management, while gops has a broader scope for profiling and debugging Go applications.
- ctop may have a steeper learning curve for users who are not familiar with terminal-based tools.
- ctop's functionality is limited to container-related tasks, while gops can be used to diagnose and troubleshoot a wider range of issues in Go applications.
Code Comparison
Google/gops:
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "usage: gops <command> [pid|addr]")
os.Exit(1)
}
cmd := os.Args[1]
switch cmd {
case "version":
fmt.Println(version)
case "stack":
pid, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
printStack(pid)
// ...
}
bcicen/ctop:
func main() {
app := cli.NewApp()
app.Name = "ctop"
app.Usage = "Top-like interface for container metrics"
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "host, H",
Value: "unix:///var/run/docker.sock",
Usage: "docker socket to connect to",
},
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "custom format for container view",
},
// ...
}
app.Action = func(c *cli.Context) error {
return ctop.Run(c)
}
app.Run(os.Args)
}
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
gops
gops is a command to list and diagnose Go processes currently running on your system.
$ gops
983 980 uplink-soecks go1.9 /usr/local/bin/uplink-soecks
52697 52695 gops go1.10 /Users/jbd/bin/gops
4132 4130 foops * go1.9 /Users/jbd/bin/foops
51130 51128 gocode go1.9.2 /Users/jbd/bin/gocode
Installation
To install the latest version of gops:
$ go get github.com/google/gops
or
$ go install github.com/google/gops@latest
To install a specific gops version, for example v0.3.19:
$ go install github.com/google/gops@v0.3.19
Diagnostics
For processes that start the diagnostics agent, gops can report additional information such as the current stack trace, Go version, memory stats, etc.
In order to start the diagnostics agent, see the hello example.
package main
import (
"log"
"time"
"github.com/google/gops/agent"
)
func main() {
if err := agent.Listen(agent.Options{}); err != nil {
log.Fatal(err)
}
time.Sleep(time.Hour)
}
Otherwise, you could set GOPS_CONFIG_DIR
environment variables to assign your config dir.
Default, gops will use the current user's home directory(AppData on windows).
Manual
It is possible to use gops tool both in local and remote mode.
Local mode requires that you start the target binary as the same user that runs gops binary. To use gops in a remote mode you need to know target's agent address.
In Local mode use process's PID as a target; in Remote mode target is a host:port
combination.
Listing all processes running locally
To print all go processes, run gops
without arguments:
$ gops
983 980 uplink-soecks go1.9 /usr/local/bin/uplink-soecks
52697 52695 gops go1.10 /Users/jbd/bin/gops
4132 4130 foops * go1.9 /Users/jbd/bin/foops
51130 51128 gocode go1.9.2 /Users/jbd/bin/gocode
The output displays:
- PID
- PPID
- Name of the program
- Go version used to build the program
- Location of the associated program
Note that processes running the agent are marked with *
next to the PID (e.g. 4132*
).
$ gops <pid> [duration]
To report more information about a process, run gops
followed by a PID:
$ gops <pid>
parent PID: 5985
threads: 27
memory usage: 0.199%
cpu usage: 0.139%
username: jbd
cmd+args: /Applications/Splice.app/Contents/Resources/Splice Helper.app/Contents/MacOS/Splice Helper -pid 5985
local/remote: 127.0.0.1:56765 <-> :0 (LISTEN)
local/remote: 127.0.0.1:56765 <-> 127.0.0.1:50955 (ESTABLISHED)
local/remote: 100.76.175.164:52353 <-> 54.241.191.232:443 (ESTABLISHED)
If an optional duration is specified in the format as expected by
time.ParseDuration
, the CPU
usage for the given time period is reported in addition:
$ gops <pid> 2s
parent PID: 5985
threads: 27
memory usage: 0.199%
cpu usage: 0.139%
cpu usage (2s): 0.271%
username: jbd
cmd+args: /Applications/Splice.app/Contents/Resources/Splice Helper.app/Contents/MacOS/Splice Helper -pid 5985
local/remote: 127.0.0.1:56765 <-> :0 (LISTEN)
local/remote: 127.0.0.1:56765 <-> 127.0.0.1:50955 (ESTABLISHED)
local/remote: 100.76.175.164:52353 <-> 54.241.191.232:443 (ESTABLISHED)
$ gops tree
To display a process tree with all the running Go processes, run the following command:
$ gops tree
...
âââ 1
â  âââ 13962 [gocode] {go1.9}
âââ 557
â  âââ 635 [com.docker.supervisor] {go1.9.2}
â  âââ 638 [com.docker.driver.amd64-linux] {go1.9.2}
âââ 13744
âââ 67243 [gops] {go1.10}
$ gops stack (<pid>|<addr>)
In order to print the current stack trace from a target program, run the following command:
$ gops stack (<pid>|<addr>)
gops stack 85709
goroutine 8 [running]:
runtime/pprof.writeGoroutineStacks(0x13c7bc0, 0xc42000e008, 0xc420ec8520, 0xc420ec8520)
/Users/jbd/go/src/runtime/pprof/pprof.go:603 +0x79
runtime/pprof.writeGoroutine(0x13c7bc0, 0xc42000e008, 0x2, 0xc428f1c048, 0xc420ec8608)
/Users/jbd/go/src/runtime/pprof/pprof.go:592 +0x44
runtime/pprof.(*Profile).WriteTo(0x13eeda0, 0x13c7bc0, 0xc42000e008, 0x2, 0xc42000e008, 0x0)
/Users/jbd/go/src/runtime/pprof/pprof.go:302 +0x3b5
github.com/google/gops/agent.handle(0x13cd560, 0xc42000e008, 0xc420186000, 0x1, 0x1, 0x0, 0x0)
/Users/jbd/src/github.com/google/gops/agent/agent.go:150 +0x1b3
github.com/google/gops/agent.listen()
/Users/jbd/src/github.com/google/gops/agent/agent.go:113 +0x2b2
created by github.com/google/gops/agent.Listen
/Users/jbd/src/github.com/google/gops/agent/agent.go:94 +0x480
# ...
$ gops memstats (<pid>|<addr>)
To print the current memory stats, run the following command:
$ gops memstats (<pid>|<addr>)
$ gops gc (<pid>|<addr>)
If you want to force run garbage collection on the target program, run gc
.
It will block until the GC is completed.
$ gops setgc (<pid>|<addr>)
Sets the garbage collection target to a certain percentage. The following command sets it to 10%:
$ gops setgc (<pid>|<addr>) 10
The following command turns off the garbage collector:
$ gops setgc (<pid>|<addr>) off
$ gops version (<pid>|<addr>)
gops reports the Go version the target program is built with, if you run the following:
$ gops version (<pid>|<addr>)
devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000
$ gops stats (<pid>|<addr>)
To print the runtime statistics such as number of goroutines and GOMAXPROCS
.
Profiling
Pprof
gops supports CPU and heap pprof profiles. After reading either heap or CPU profile,
it shells out to the go tool pprof
and let you interactively examine the profiles.
To enter the CPU profile, run:
$ gops pprof-cpu (<pid>|<addr>)
To enter the heap profile, run:
$ gops pprof-heap (<pid>|<addr>)
Execution trace
gops allows you to start the runtime tracer for 5 seconds and examine the results.
$ gops trace (<pid>|<addr>)
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot