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.
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%
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
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.
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
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.
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>
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.
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
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
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.
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.
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.
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.
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>
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.
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.
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