1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00
Commit Graph

257 Commits

Author SHA1 Message Date
Glib Smaga
024cce5849 internal/cmd: Move code here from the main package 2022-08-30 14:31:29 +02:00
Tobias Klauser
9f8280461a Only report CPU percentage per period if period is > 0
The change in #154 lead to the CPU usage being reported for a 0s
duration:

cpu usage (0s):	NaN%

Fix this by only reporting CPU usage per period if the user specified a
positive duration.
2022-07-08 10:33:55 +02:00
Tobias Klauser
c14dce915a ci: run tests with -race 2022-07-07 18:07:51 +02:00
Tobias Klauser
5ddd2779fb agent: fix data race in Listen
Fix the following data race in agent.Listen:

==================
WARNING: DATA RACE
Write at 0x0000007620a0 by goroutine 9:
  github.com/google/gops/agent.Listen()
      /home/tklauser/go/src/github.com/google/gops/agent/agent.go:112 +0x207
  github.com/google/gops/agent.TestAgentClose()
      /home/tklauser/go/src/github.com/google/gops/agent/agent_test.go:21 +0x6e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1486 +0x47

Previous read at 0x0000007620a0 by goroutine 8:
  github.com/google/gops/agent.listen()
      /home/tklauser/go/src/github.com/google/gops/agent/agent.go:130 +0x5a

Goroutine 9 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1486 +0x724
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1839 +0x99
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1439 +0x213
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1837 +0x7e4
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1719 +0xa71
  main.main()
      _testmain.go:57 +0x2e4

Goroutine 8 (finished) created at:
  github.com/google/gops/agent.Listen()
      /home/tklauser/go/src/github.com/google/gops/agent/agent.go:123 +0x43b
  github.com/google/gops/agent.TestListen()
      /home/tklauser/go/src/github.com/google/gops/agent/agent_test.go:13 +0x57
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1486 +0x47
==================
--- FAIL: TestAgentClose (0.00s)
    testing.go:1312: race detected during execution of test
FAIL
FAIL	github.com/google/gops/agent	0.026s
2022-07-07 18:07:51 +02:00
Tobias Klauser
8442404056 internal: inline getOSUserConfigDir 2022-06-27 09:52:46 +02:00
Tobias Klauser
bf851ab3df Sort tree output by PPID
Otherwise the processes might appear in arbitrary order and
disassociated from their parent process. Also avoid printing a stray
newline after the tree.

Before:

```
...
├── 2493
│   └── 4952 (gops) {go1.18.1}
├── 1
│   └── 117 (com.docker.vmnetd) {go1.17.5}
├── 4405
│   └── 4416 (gopls) {go1.18.2}
└── 4404

```

After:

```
...
├── 1
│   └── 117 (com.docker.vmnetd) {go1.17.5}
├── 2493
│   └── 4945 (gops) {go1.18.3}
└── 4404
    └── 4405 (gopls) {go1.18.2}
        └── 4416 (gopls) {go1.18.2}
```
2022-06-24 22:54:34 +02:00
Tobias Klauser
14e2449428
internal: remove getOSUserConfigDir fallback for Go ≤ 1.13 (#170) 2022-06-24 05:13:01 -07:00
Tobias Klauser
35533050c7 go.mod, vendor: update dependencies
Update direct dependencies to the following versions:

- github.com/shirou/gopsutil/v3 v3.22.4
- golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
2022-05-30 14:10:58 +02:00
Tobias Klauser
72a03a3c85
Bump minimum Go version to 1.13 (#169) 2022-05-30 03:03:16 -07:00
Tobias Klauser
33938f8089 Remove CircleCI
CircleCI tests currently seem fail consistently. GitHub actions
introduced in #136 are providing the same coverage (and more), have been
running stable for over a year and are easier to maintain. Thus, remove
Circle CI integration.

Ref. https://github.com/google/gops/pull/136#issuecomment-786529797
2022-05-04 23:47:46 +02:00
Tobias Klauser
53ee352cc8 goprocess: use debug/buildinfo on Go 1.18 and newer
Use package debug/buildinfo [1] introduced in Go 1.18 [2] when possible.
This should avoid previous issues with rsc.io/goversion where Go
processes were no longer listed.

[1] https://pkg.go.dev/debug/buildinfo
[2] https://go.dev/doc/go1.18#debug/buildinfo

For #102
For #159
For #160
2022-05-04 22:48:20 +02:00
Tobias Klauser
3d102a4755 Update CI to Go 1.18
Also only test on the minimum supported version (currently Go 1.12) and
the latest two versions supported by the Go project.
2022-05-04 22:48:20 +02:00
DuckSoft
4e16ac7815
Fix minor white space issue in README.md (#162) 2022-03-16 13:42:24 +01:00
Eli Bendersky
3e83813cbc
Fix minor typo in README.md (#161) 2022-02-10 08:13:40 +00:00
Elton SV
e6cb0303ad
Error out when the given duration is negative (#155)
Validate processInfo period & log a fatal error in the case of negative duration.
2021-11-10 14:15:35 +01:00
Tobias Klauser
db6b6e9ba0 agent: rename setsockoptReuseAddrAndPort to setReuseAddrAndPortSockopts 2021-10-11 18:06:37 +02:00
Tobias Klauser
f38bd6a1ee agent: fix solaris build
Solaris doesn't provide the SO_REUSEPORT socket option.
2021-10-11 18:06:37 +02:00
Tobias Klauser
f57f013e90 go.mod, vendor: update gopsutil and go-ole to fix windows/arm64 build
Update github.com/shirou/gopsutil/v3 to v3.21.9 and
github.com/go-ole/go-ole to latest master to fix the build on
windows/arm64.
2021-10-08 18:51:17 +02:00
Tobias Klauser
e9831286ac go.mod, vendor: update dependencies
Update direct dependencies to the following versions:

  github.com/shirou/gopsutil/v3 v3.21.8
  golang.org/x/sys v0.0.0-20210902050250-f475640dd07b
2021-09-03 09:57:33 +02:00
Tobias Klauser
c5ab645ce5 Use Go 1.17 in CI
Also drop tests for 1.13 and 1.14, these are no longer supported
upstream. Keep 1.12 though as this is the mimimum supported version for
gops.
2021-09-03 09:57:33 +02:00
Tobias Klauser
a22894be16 Add //go:build tags for Go 1.17
Run Go 1.17 gofmt to add //go:build tags.
2021-09-03 09:57:33 +02:00
Tobias Klauser
f5057debe6 README.md: update installation instructions
Using `go get -u github.com/google/gops` fails to install gops when
using Go modules. Update the installation instructions accordingly.

For #147
2021-07-15 10:52:58 +02:00
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