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

59 Commits

Author SHA1 Message Date
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
Jaana Burcu Dogan
c3bb8a5007 add experimental pprof support 2016-11-13 20:04:40 -08:00
Jaana Burcu Dogan
d53c7a7dab report units for memstats 2016-11-13 19:20:53 -08:00
Jaana Burcu Dogan
3e9327ceed agent: document that agent works via an unsecure unix socket
Fixes #3.
2016-11-11 17:05:41 -08:00
Jaana Burcu Dogan
4f1bed2a2a delete extra space 2016-11-07 17:44:13 -08:00
Jaana Burcu Dogan
cfcb6f4a13 Rename agent.Listen to agent.Start. 2016-11-07 13:08:04 -08:00
Jaana Burcu Dogan
f0e5971049 allow users to start the agent manually 2016-11-07 13:01:35 -08:00
Jaana Burcu Dogan
397847ad39 rename Stack signal to StackTrace 2016-11-05 23:46:11 -07:00
Jaana Burcu Dogan
cea4a3c5ef fix TODO message 2016-11-05 23:45:55 -07:00
Jaana Burcu Dogan
29b45c622d move to github.com/google, fix the build 2016-11-05 13:03:31 -07:00
Jaana Burcu Dogan
a5baba5014 move signal package one level up 2016-11-04 00:57:30 -07:00