Skip to content

Commit 8f64f02

Browse files
author
wardlin
committed
update
1 parent a8b7a0b commit 8f64f02

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

stats.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"github.com/eaglesunshine/trace/stats/quantile"
1313
)
1414

15-
var recordLock sync.Mutex
16-
1715
type ServerRecord struct {
1816
TTL uint8
1917
Addr string
@@ -96,11 +94,7 @@ func (t *TraceRoute) getServer(addr string, ttl uint8, key string, sendTimeStamp
9694

9795
server.RecvCnt++
9896

99-
server.Rtt = float64(receiveTimeStamp.Sub(sendTimeStamp) / time.Microsecond)
100-
101-
// latency := float64(receiveTimeStamp.Sub(sendTimeStamp) / time.Microsecond)
102-
// server.LatencyDescribe.Append(latency, 2)
103-
// server.Quantile.Insert(latency)
97+
server.Rtt = float64(receiveTimeStamp.Sub(sendTimeStamp) / time.Nanosecond)
10498

10599
if server.Name == "" {
106100
server.LookUPAddr()
@@ -110,8 +104,8 @@ func (t *TraceRoute) getServer(addr string, ttl uint8, key string, sendTimeStamp
110104
}
111105

112106
func (t *TraceRoute) addLastHop(ttl uint8) {
113-
recordLock.Lock()
114-
defer recordLock.Unlock()
107+
t.RecordLock.Lock()
108+
defer t.RecordLock.Unlock()
115109

116110
t.LastArrived += 1
117111
if t.LastArrived <= t.MaxPath {

trace.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ type TraceRoute struct {
5757
LastArrived int
5858
Hops []HopData
5959
StartTime time.Time
60+
RecordLock sync.Mutex
61+
SendMap map[string]*SendMetric
6062
}
6163
type StatsDB struct {
6264
Cache *tsyncmap.Map
6365
SendCnt *uint64
6466
}
6567

6668
func NewStatsDB(key string) *StatsDB {
67-
cacheTimeout := time.Duration(6 * time.Second)
68-
checkFreq := time.Duration(1 * time.Second)
69+
cacheTimeout := 6 * time.Second
70+
checkFreq := 1 * time.Second
6971
var cnt uint64
7072
px := &StatsDB{
7173
Cache: tsyncmap.NewMap(key, cacheTimeout, checkFreq, false),

0 commit comments

Comments
 (0)