1
0
mirror of https://github.com/google/gops.git synced 2024-11-30 08:36:53 +02:00
Commit Graph

285 Commits

Author SHA1 Message Date
Tobias Klauser
8918f15c19 Allow to specify CPU usage period as duration string
The current implementation assumes the given duration in seconds.
Instead, also allow to specify a duration in the format as expected by
`time.ParseDuration` and use that if found. If a plain integer is
specified, it is still parsed as a duration in seconds.
2021-07-01 12:01:38 +02:00
Tobias Klauser
f870d0110a Restore CPU usage report format
Commit 78435f89 changed the existing output format for the CPU usage
from `cpu usage:` to `cpu usage (all):`.

This might break existing scripts relying on this format. Revert that
part of the change and only report the CPU usage for the given period
with a suffix:

cpu usage:	0.087%
cpu usage (1s):	1.42%
2021-07-01 12:01:38 +02:00
Tobias Klauser
48d3575c6a go.mod, vendor: update dependencies
Update direct dependencies to the following versions:

  github.com/shirou/gopsutil/v3 v3.21.5
  github.com/xlab/treeprint v1.1.0
  golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
2021-07-01 10:00:02 +02:00
村口大白鹅
78435f89d8
Support for reporting the percent of CPU time usage within given time (#143) 2021-04-17 13:14:45 -07:00
Tobias Klauser
0bf845d3d5 agent: mention SO_REUSEPORT in Options.ReuseSocketAddrAndPort godoc
The godoc comment mentions SO_REUSEADDR twice, fix this.
2021-03-31 01:05:10 +02:00
Tobias Klauser
55729d43c2 agent: use filepath.Join to construct portfile path
If gopsdir contains a trailing slash, the resulting portfile path will
contain a trailing double slash which might lead to problems in some
circumstances. Moreover iut could also be problematic on platforms where
other path separators are used (e.g. Windows).

Fix this by using filepath.Join to construct the path.
2021-03-09 12:42:07 +01:00
Tobias Klauser
9a13441a02 Switch to use github.com/shirou/gopsutil/v3
Use the properly versioned Go module github.com/shirou/gopsutil/v3
instead of github.com/shirou/gopsutil (which does not provide a go.mod
file).
2021-03-01 21:30:25 +01:00
Tobias Klauser
81f7a00714 README.md: add GitHub action status badge 2021-03-01 10:00:41 +01:00
Tobias Klauser
dc7f958b78 Add GitHub action for CI testing
This extends the testing currently done in CircleCI:

* run CI on macOS in addition to Linux and Windows
* testing with multiple Go versions (1.12 through 1.16), not just Go
  1.12 like CircleCI
* checks that the code is properly gofmt'ed
* checks proper module vendoring
2021-02-26 10:38:08 +01:00
Pavel Borzenkov
a3d463ce8a vendor: sync 'vendor' dir with go.mod
The commit contains changes produced by 'go mod vendor' command. It
syncs the dependencies listed in `go.mod` file with the ones in
`vendor/` directory.

With this change `go build -mod=vendor` works again.
2021-02-24 16:46:44 +01:00
Tobias Klauser
268f11e4fc agent: allow to set SO_REUSEPORT on listening socket
Introduce Option.SocketReuseAddrAndPort which, if set, will lead to the
SO_REUSEPORT socket option being set on the listening socket on
Unix-like OSes. This also sets SO_REUSEADDR which is already the default
in net.Listen (see net.setDefaultSockopts).

Setting these options increases the chance to re-bind() to the same
address and port upon agent restart if Options.Addr is set.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-12-09 19:27:52 +01:00
Tobias Klauser
b55933ebc4 Use strings.Builder
It's been there since Go 1.10 and go.mod requires at least Go 1.12.
2020-11-03 13:47:01 +01:00
Tobias Klauser
d64b2d5ce7 Fix formatting for multiple of 24 hours
In case a process has been running for a multiple of 24 hours, the
process runtime will be formatted as DD-MM:SS instead of DD-HH:MM:SS.
Fix this and add a test for fmtEtimeDuration.
2020-11-03 13:47:01 +01:00
yarcat
5d514cabbb
goprocess: add test for FindAll (#127)
The test verifies that #123 is fixed and prevents future regressions.
2020-09-10 10:12:57 +02:00
JBD
c9150606f9
Fix the worker concurrency model (#126)
Limit the number of concurrent workers by starting a fixed number of goroutines and providing work by an input channel.

Fixes #123
2020-09-07 14:23:34 -07:00
sans
6fb0d860e5
README.md: fix typo (#119) 2020-08-12 11:16:51 +02:00
sans
b96604fa98
goprocess: fix EMFILE error on macOS Catalina (#118)
Limit the number of concurrent goroutines to avoid EMFILE on macOS Catalina.
2020-08-05 10:11:35 +02:00
Tobias Klauser
983b7ba5c9
agent: report additional runtime.MemStats fields (#116)
Report PauseEnd, NumForcedGC and GCCPUFraction from runtime.Memstats.
2020-07-06 12:55:48 +02:00
Tobias Klauser
f7e323ca2e
internal: use filepath.Join in PIDFile (#114)
Use filepath.Join to create a path with correct path delimiters on
Windows.

Based on a change by @42wim submitted in #107
2020-05-30 09:42:52 +02:00
Tobias Klauser
1e1db3f61d
internal: add gops subdirectory in ConfigDir (#112)
Use a subdirectory of the directory returned by os.UserConfigDir instead
of the UserConfigDir directly. This was missed in #103. Also add a test.

Based on a change by @42wim submitted in #107
2020-05-30 09:40:59 +02:00
Tobias Klauser
38c00cd8c2
circleci: test on Windows (#113) 2020-05-30 09:39:11 +02:00
Tobias Klauser
ccffbf8d4a
agent: check error return values (#109)
In func handle, check the error return values of pprof.WriteHeapProfile
and trace.Start.
2020-05-25 10:43:40 +02:00
Tobias Klauser
10df6abaad
Update dependencies (#108)
Updated by running go get -u && go mod tidy && go mod vendor. As a nice
side effect this will get rid of the indirect dependency
github.com/shirou/w32 which is no longer needed by
github.com/shirou/gopsutil
2020-05-18 19:30:29 +02:00
Tobias Klauser
4fa525724f
Update module vendoring (#106)
Run go mod tidy && go mod vendor to clean up vendored modules. This
will drop any unused (sub-)package from the vendor directory.
2020-05-14 23:45:10 +02:00
Tobias Klauser
2715d03f64
agent: clean up socket and port file on SIGTERM and SIGQUIT (#104)
In case the agent is exiting due to a SIGTERM or SIGQUIT it is leaking
the port files in the gops config directory, as e.g. reported in
cilium/cilium#11455

Make sure the socket is cleaned up and port files in the gops config
directory are removed upon these signals by also relaying these signals
to the signal channel in gracefulShutdown. In case of SIGTERM, which is
the "normal" termination signal, exit the process with exit status 0.
2020-05-14 14:06:09 -07:00
Yasushi Saito
932d9779da
Remove dependency on kardianos/osext (#89)
It's superseded by the standard os package in go 1.8+
2020-05-14 22:04:21 +02:00
Tobias Klauser
ea7dd03981
Remove unnecessary type conversion (#105) 2020-05-14 22:03:09 +02:00
Tobias Klauser
ed67c5b345
Use os.UserConfigDir for internal.ConfigDir if available (#103)
On Go ≥ 1.13 the os package has os.ConfigDir
(https://golang.org/pkg/os/#UserConfigDir) which returns the default
root directory to use for user-specific configuration data. Use this in
internal.ConfigDir if available, while still making sure that any
directory specified in GOPS_CONFIG_DIR takes precedence.
2020-05-14 22:01:34 +02:00
Tobias Klauser
f1b8f2b15c
Add prefix to profile dump file names (#101)
When getting profile dumps for further processing, it's hard to distinguish
CPU and heap profiles from the file names alone. Make this easier by
adding a prefix (cpu or heap) to the file name depending on the type of
profile.
2020-04-29 10:44:32 -07:00
Dan Peterson
3a98d6d245
agent: silence error on listener close (#97)
As part of agent.Close, Close is called on the listener. This has
Accept return a "use of closed network connection" error, which is
expected. This error is logged but it would be nice if it wasn't.

Unfortunately, there's not a great way to check for this
error (https://golang.org/issues/4373) so use a best-effort
strings.Contains check.
2020-02-29 14:34:15 -08:00
Tobias Klauser
9025be33d5
Don't log path to profile dump twice (#98)
The path to the profile dump is already logged after writing the file
(cmd.go line 121). Remove the duplicate log line.

Co-authored-by: Emmanuel T Odeke <odeke@ualberta.ca>
2020-02-29 14:27:25 -08:00
Jakub Łukasiewicz
71c4255d55
Check $XDG_CONFIG_HOME before falling to ~/.config (#99) 2020-02-29 14:24:56 -08:00
JBD
59c8be2ead
Improve the help text (#94)
Avoid using tabs, remove help from "subcommands" list,
don't differentiate the profiling commands from others.
2019-08-01 22:19:10 -07:00
JBD
6cdc0c0a4a
Update CircleCI to Go 1.12 (#93) 2019-07-29 13:06:16 -07:00
JBD
2aa6a2cfed Switch to Go modules 2019-07-27 15:21:33 -07:00
JBD
fbf94b913d Revert "Switch to Go modules"
This reverts commit 28cfbaf001.
2019-07-27 15:16:00 -07:00
JBD
28cfbaf001 Switch to Go modules 2019-07-27 15:09:47 -07:00
Yash Ladha
036f72c5be Fix exit code if a valid cmd is passed (#91) 2019-03-27 10:35:05 -07:00
Pavlos Ratis
954ead6c72 add support for elapsed time (etime) (#80) 2019-03-20 14:59:55 -07:00
Bernerd Schaefer
05b5a27491 agent: include newlines in warning log messages (#87)
The warnings that agent prints to os.Stderr did not previously include
newlines causing program output to get jumbled up when an error occurs.
We see this most often when calling `Close()`, which causes the listener
to print `gops: accept tcp 127.0.0.1:9999: use of closed network
connection` which breaks whatever is logged next.
2019-03-20 11:58:46 -07:00
JBD
9fda3b87c7 Add Go modules and missing vendored file 2019-01-25 10:45:53 -08:00
Tanabe Ken-ichi
f341a40f99 Add gitignore to ignore gops and remove the binary (#85) 2018-09-03 00:25:10 -07:00
JBD
89672dbe3c fix out of bounds panic 2018-07-11 12:15:44 -07:00
Michal Rostecki
60aa68d3cc cmd: Check error returned by GetPort (#83)
Before this change, error returned by internal.GetPort was
assigned to err variable, but this assignment was ineffectual
and error was ignored.
2018-07-11 10:12:00 -07:00
Shi Han
e4108e7e73 address breaking changes from xlab/treeprint (#84)
A PR of xlab/treeprint (https://github.com/xlab/treeprint/pull/6)
which was merged might break gops in the future.
The PR removed treeprint.EdgeTypeStart. To set the root node,
we can now use SetValue(value Value) instead.

In this commit,

    dep ensure -update github.com/xlab/treeprint

was executed to update the library and then fix is applied.
2018-07-11 10:08:06 -07:00
Michal Rostecki
62b4d22266 vendor: dep ensure -update github.com/shirou/gopsutil (#79)
gopsutil library is licensed under BSD, but the previous version
contained some GPL-licensed code which is a violation of GPL
license. The updated version doesn't contain GPL-licensed code
anymore.

https://github.com/shirou/gopsutil/issues/518
2018-04-29 22:11:38 -07:00
Pavlos Ratis
3bb2ff8d85 Update README with the latest changes (#67) 2018-04-23 16:44:40 -07:00
Jack Mordaunt
160b358b10 Fixed data race. (#68) 2018-03-10 21:24:15 -08:00
Pavlos Ratis
48c083dd34 add command to display a process tree (#72)
Implemented a command, where users can list all running Go
processes in a tree-like format (like pstree).

Example:

$ gops tree
...
├── 13744
│   └── 71746 (gops) {go1.10}
├── 1
│   └── 13962 (gocode) {go1.9}
└── 557
    └── 635 (com.docker.supervisor) {go1.9.2}
        └── 638 (com.docker.driver.amd64-linux) {go1.9.2}
2018-03-10 19:43:39 -08:00
Suhas Karanth
0e2aa5d22e dep ensure -update github.com/go-ole/go-ole (#70) 2018-03-03 12:00:58 -08:00