Skip to content

Commit

Permalink
Test: Add statistics in conn testing (v2fly#1444)
Browse files Browse the repository at this point in the history
* Add statistics in conn testing

Occasional error is observed when we execute long test
Print time and memory for better troubleshooting in the future

* fix: units import version error

Co-authored-by: Kslr <[email protected]>
Co-authored-by: Kslr <[email protected]>
  • Loading branch information
3 people authored Apr 6, 2022
1 parent e0df70b commit 5b9f782
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion testing/scenarios/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/retry"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/common/units"
)

func xor(b []byte) []byte {
Expand Down Expand Up @@ -198,7 +199,18 @@ func testUDPConn(port net.Port, payloadSize int, timeout time.Duration) func() e
}

func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func() error {
return func() error {
return func() (err1 error) {
start := time.Now()
defer func() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Println("testConn finishes:", time.Since(start).Milliseconds(), "ms\t",
err1, "\tAlloc =", units.ByteSize(m.Alloc).String(),
"\tTotalAlloc =", units.ByteSize(m.TotalAlloc).String(),
"\tSys =", units.ByteSize(m.Sys).String(),
"\tNumGC =", m.NumGC)
}()
payload := make([]byte, payloadSize)
common.Must2(rand.Read(payload))

Expand Down

0 comments on commit 5b9f782

Please sign in to comment.