enable pprof http handler.
This commit is contained in:
parent
0daab6089f
commit
e82c10b039
23
p2pd/main.go
23
p2pd/main.go
|
@ -17,8 +17,31 @@ import (
|
||||||
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
|
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
|
||||||
multiaddr "github.com/multiformats/go-multiaddr"
|
multiaddr "github.com/multiformats/go-multiaddr"
|
||||||
promhttp "github.com/prometheus/client_golang/prometheus/promhttp"
|
promhttp "github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
go func() {
|
||||||
|
for i := 6060; i < 7080; i++ {
|
||||||
|
addr := fmt.Sprintf("localhost:%d", i)
|
||||||
|
fmt.Printf("registering pprof debug http handler: %s\n", addr)
|
||||||
|
switch err := http.ListenAndServe(addr, nil); err {
|
||||||
|
case nil:
|
||||||
|
// all good, server is running and exited normally.
|
||||||
|
return
|
||||||
|
case http.ErrServerClosed:
|
||||||
|
// all good, server was shut down.
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
// error, try another port
|
||||||
|
fmt.Printf("error registering pprof debug http handler on %s: %s\n", addr, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
identify.ClientVersion = "p2pd/0.1"
|
identify.ClientVersion = "p2pd/0.1"
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package p2pd
|
package p2pd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -27,8 +28,23 @@ func (d *Daemon) trapSignals() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) handleSIGUSR1() {
|
func (d *Daemon) handleSIGUSR1() {
|
||||||
// this is the state dump signal; for now just dht routing table if present
|
// this is the state dump signal
|
||||||
|
fmt.Println("dht routing table:")
|
||||||
if d.dht != nil {
|
if d.dht != nil {
|
||||||
d.dht.RoutingTable().Print()
|
d.dht.RoutingTable().Print()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("---")
|
||||||
|
fmt.Println("connections and streams:")
|
||||||
|
for _, c := range d.host.Network().Conns() {
|
||||||
|
streams := c.GetStreams()
|
||||||
|
protos, _ := d.host.Peerstore().GetProtocols(c.RemotePeer())
|
||||||
|
protoVersion, _ := d.host.Peerstore().Get(c.RemotePeer(), "ProtocolVersion")
|
||||||
|
agent, _ := d.host.Peerstore().Get(c.RemotePeer(), "AgentVersion")
|
||||||
|
fmt.Printf("to=%s; multiaddr=%s; stream_cnt= %d\n, protocols=%v; protoversion=%s; agent=%s\n",
|
||||||
|
c.RemotePeer().Pretty(), c.RemoteMultiaddr(), len(streams), protos, protoVersion, agent)
|
||||||
|
for _, s := range streams {
|
||||||
|
fmt.Println("\tprotocol: ", s.Protocol())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue