1
0
mirror of https://github.com/google/gops.git synced 2024-11-19 20:31:58 +02:00
Commit Graph

69 Commits

Author SHA1 Message Date
Mahe Tardy
0463c1d363 agent: add the off-heap BuckHashSys mstat
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>
2024-11-05 12:44:43 +01:00
Mahe Tardy
51efca2c3e agent: use in-use instead of inuse for consistency
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>
2024-11-05 12:44:43 +01:00
Mahe Tardy
dcd9131fb9 agent: fix mistakes in off-heap mstat naming
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>
2024-11-05 12:44:43 +01:00
Simon Blixenkrone
48b357e78c check for net error closed error instead of hack 2024-05-03 18:44:43 +02:00
Tobias Klauser
582fc2828e agent: move check for EROFS/EPERM outside of saveConfig
Rather than duplicating the check in saveConfig, check for EROFS or
EPERM on the error returned by saveConfig.
2023-10-24 18:19:38 +02:00
Glib Smaga
22cdba11b7 Remove named returns
Named returns should only be used with naked returns, or a
deferred function. And in general are better avoided
2023-10-05 21:43:22 +02:00
Tobias Klauser
710ef44cc3 agent: check listener instead of portfile in Listen
After #213 the portfile might no longer be written, thus check the
listener to determine whether the agent is already listening.
2023-10-05 17:21:37 +02:00
Alex Lyashko
dae615bb91 ignore EROFS and EPERM errors on config saving
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>
2023-10-05 16:06:42 +02:00
Alex Lyashko
cf6d865718 minor: move some code to saveConfig() to make it more readable
Signed-off-by: Alex Lyashko <alex.lyashko@gmail.com>
2023-10-05 16:06:42 +02:00
Alex Lyashko
f80c10051e minor: reorder code and group it
and gracefulShutdown() should be called on success only.

Signed-off-by: Alex Lyashko <alex.lyashko@gmail.com>
2023-10-05 16:06:42 +02:00
segevda
a241038823
replace ioutil usages with io and os (#202)
ioutil was deprecated in go1.16 and its functions now directly call io
and os functions. It is recommended to use these implementations in new
code.
2023-02-10 14:03:23 +01: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
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
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
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
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
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
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
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
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
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
Rambone
390a41310a Report more Stack info, as stack-mspan-inuse、stack-mspan-sys etc. (#63) 2017-11-20 10:28:44 -08:00
Rambone
dcc978d6e8 make ConfigDir configurable (#61)
make ConfigDir configurable

* internal: retrieve ConfigDir from GOPS_CONFIG_DIR environment variable

* make code graceful

* code optimize
2017-11-13 00:52:04 -07:00
Daniel Fireman
ed4f1f24a6 Introducing support to debug.SetGCPercent. (#56)
* 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.
2017-10-06 17:50:40 -06:00
JBD
1a41b817e5 agent: don't close on interrupt by default (#49) 2017-09-11 19:50:16 -07:00
Shawn Smith
b0c5c02b30 agent: fix godoc typo (#34) 2017-03-08 21:06:37 -08:00
Nick K
288e543fee add remote mode support (#30) 2017-03-02 11:51:14 -08:00
Cezar Sá Espinola
c8ccacaea5 agent: prettier formatting for units printed by memstats (#28) 2017-02-17 16:06:16 -08:00
Jaana Burcu Dogan
671bd43984 gops: add Go execution trace support 2017-01-20 13:10:54 -08:00
Cezar Sá Espinola
ad978d77e6 agent: avoid truncating stacktrace if it's bigger than 64kb (#29)
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.
2017-01-13 12:27:22 -08:00
Jaana Burcu Dogan
0e47ba961c rename vitals to stats 2017-01-03 01:15:13 -08:00
Jaana Burcu Dogan
664fdf9107 agent: use shorthand to write the heap profile 2017-01-03 01:06:27 -08:00
Jaana Burcu Dogan
b95fa4807e handle error if CPU profile cannot start 2017-01-03 00:56:44 -08:00
Jaana Burcu Dogan
4698eb04b6 agent: fix race between Close and listener assert 2016-12-20 12:56:40 -08:00
Jaana Burcu Dogan
108d4a8a8e agent: stat portfile only if filename exists 2016-12-20 12:48:15 -08:00
Jaana Burcu Dogan
7973d7aa4f agent: simplify options, allow only one listener 2016-12-20 12:23:05 -08:00
Cezar Sa Espinola
707d15f9b7
agent: basic tests for starting and stopping the agent 2016-12-15 23:13:44 -02:00
Cezar Sa Espinola
ca8282f029
agent: allow starting the agent without installing a signal handler
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.
2016-12-15 23:08:52 -02:00
Jaana Burcu Dogan
397849b2e1 remove obsolete TODO 2016-11-26 18:38:59 -08:00
Kean Pedersen
4480e70e5d agent: corrected spelling error on godoc 2016-11-15 10:37:56 -08:00
Jialin Wu
7a6fc281fb agent: fix time ago issue (#14) 2016-11-15 09:59:59 -08:00
Jaana Burcu Dogan
c0c78ac94f move config to internal 2016-11-14 23:07:31 -08:00
Alejandro Ramon Lopez del Huerto
982467e9e3 replace unix socket by tcp
Fixes #10.
2016-11-14 22:59:09 -08:00
Garrett Squire
4f88388a37 add runtime vitals (#9)
Fixes #5.
2016-11-14 11:07:06 -08:00
Jaana Burcu Dogan
50ad24c982 agent: remove debug annotations from heap profile 2016-11-13 21:00:00 -08:00
Jaana Burcu Dogan
a0334e989c support cpu profile 2016-11-13 20:38:17 -08:00
Jaana Burcu Dogan
58675bffed remove Println 2016-11-13 20:07:25 -08:00