All off-heap metrics are returned by MemStats except this one so let's
add it to have a better global picture of off-heap memory use.
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Since I renamed these fields in the previous commit, let's take this
opportunity to be consistent with the other fields containing 'in use'.
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Some statistics were mislabeled as related to the stack while those are
off-heap memory statistics. I'm guessing this is due to their proximity
with the stack stats.
Here is the general documentation for these metrics:
https://github.com/golang/go/blob/go1.23.2/src/runtime/mstats.go#L209-L218
// Off-heap memory statistics.
//
// The following statistics measure runtime-internal
// structures that are not allocated from heap memory (usually
// because they are part of implementing the heap). Unlike
// heap or stack memory, any memory allocated to these
// structures is dedicated to these structures.
//
// These are primarily useful for debugging runtime memory
// overheads.>
Fixes: 390a41310a ("Report more Stack info, as stack-mspan-inuse stack-mspan-sys etc. (#63)")
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
agent still works in remote mode and executable environment may not
allow to save any data at all (e.g. in k8s container), so be robust.
Signed-off-by: Alex Lyashko <alex.lyashko@gmail.com>
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.
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 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.
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 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.
* Introducing support to debug.SetGCPercent.
Fixes#8
On my I needed to augment a little bit the communication
protocol to add support to optional parameters.
Using pprof.Lookup("goroutine") instead of runtime.Stack directly
because the former already takes care of expanding the buffer used with
runtime.Stack until it's big enough for the stack.
If the application the agent is being installed on also need to run some
shutdown code during an Interrupt signal, it's important to have the
ability to prevent gops agent from calling os.Exit(). This also adds the
requirement of exposing a method to manually cleanup garbage left by the
gops agent.
To allow custom agent flags now and in the future an Agent type was
created with a public boolean field HandleSignals.