Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package ztrace
import (
"bytes"
"fmt"
"github.com/eaglesunshine/trace/stats/describe"
"github.com/eaglesunshine/trace/stats/quantile"
"net"
"strings"
"sync"
"time"

"github.com/eaglesunshine/trace/stats/describe"
"github.com/eaglesunshine/trace/stats/quantile"
)

type ServerRecord struct {
Expand Down Expand Up @@ -84,7 +82,8 @@ func (t *TraceRoute) RecordRecv(v *RecvMetric) bool {
server := t.NewServerRecord(v.RespAddr, uint8(sendInfo.TTL), sendInfo.FlowKey)

server.RecvCnt++
latency := float64(v.TimeStamp.Sub(sendInfo.TimeStamp) / time.Microsecond)
//latency := float64(v.TimeStamp.Sub(sendInfo.TimeStamp) / time.Microsecond)
latency := float64(v.TimeStamp.Sub(sendInfo.TimeStamp).Microseconds())

server.LatencyDescribe.Append(latency, 2)
server.Quantile.Insert(latency)
Expand Down
27 changes: 14 additions & 13 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func New(protocol string, dest string, src string, af string, maxPath int64, max
defer func() {
if e := recover(); e != nil {
logrus.Error(e)
buf := make([]byte, 64<<10) //64*2^10, 64KB
buf := make([]byte, 64<<10) //64*2^10, 64KB
buf = buf[:runtime.Stack(buf, false)]
err = fmt.Errorf("panic recovered: %s\n %s", e, buf)
}
Expand Down Expand Up @@ -172,12 +172,12 @@ func (t *TraceRoute) TraceUDP() (err error) {
var handlers []func() error

for i := 0; i < t.MaxPath; i++ {
handlers=append(handlers, func() error {
handlers = append(handlers, func() error {
return t.SendIPv4UDP()
})
}

handlers=append(handlers, func() error {
handlers = append(handlers, func() error {
return t.ListenIPv4ICMP()
})

Expand All @@ -188,12 +188,12 @@ func (t *TraceRoute) TraceTCP() (err error) {
var handlers []func() error

for i := 0; i < t.MaxPath; i++ {
handlers=append(handlers, func() error {
handlers = append(handlers, func() error {
return t.SendIPv4TCP()
})
}

handlers=append(handlers, func() error {
handlers = append(handlers, func() error {
return t.ListenIPv4ICMP()
})

Expand All @@ -203,13 +203,14 @@ func (t *TraceRoute) TraceTCP() (err error) {
func (t *TraceRoute) TraceICMP() (err error) {
var handlers []func() error

for i := 0; i < t.MaxPath; i++ {
handlers=append(handlers, func() error {
return t.SendIPv4ICMP()
})
}
handlers = append(handlers, t.SendIPv4ICMP)
//for i := 0; i < t.MaxPath; i++ {
// handlers=append(handlers, func() error {
// return t.SendIPv4ICMP()
// })
//}

handlers=append(handlers, func() error {
handlers = append(handlers, func() error {
return t.ListenIPv4ICMP()
})

Expand Down Expand Up @@ -246,7 +247,7 @@ func GoroutineNotPanic(handlers ...func() error) (err error) {
defer func() {
if e := recover(); e != nil {
logrus.Error(e)
buf := make([]byte, 64<<10) //64*2^10, 64KB
buf := make([]byte, 64<<10) //64*2^10, 64KB
buf = buf[:runtime.Stack(buf, false)]
err = fmt.Errorf("panic recovered: %s\n %s", e, buf)
}
Expand All @@ -263,4 +264,4 @@ func GoroutineNotPanic(handlers ...func() error) (err error) {
wg.Wait()

return
}
}