1
0
mirror of https://github.com/golang/go synced 2024-11-18 05:44:47 -07:00

internal/trace: change Less to make sorting events deterministice

The existing code just used timestamps. The new code uses more fields
    when timestamps are equal.

	Revised to shorten code per reviewer comments.

Change-Id: Ibd0824d0acd7644484d536b1a754a0da156fac3d
Reviewed-on: https://go-review.googlesource.com/113721
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Peter Weinberger 2018-05-21 10:45:59 -04:00
parent ef880a2f61
commit 1764609b8b

View File

@ -133,7 +133,7 @@ func order1007(m map[int][]*Event) (events []*Event, err error) {
ev.Ts = ts
}
}
sort.Stable(eventList(events))
sort.Sort(eventList(events))
return
}
@ -243,7 +243,20 @@ func (l orderEventList) Len() int {
}
func (l orderEventList) Less(i, j int) bool {
return l[i].ev.Ts < l[j].ev.Ts
a, b := l[i].ev, l[j].ev
if a.Ts != b.Ts {
return a.Ts < b.Ts
}
if a.Type != b.Type {
return a.Type < b.Type
}
if a.P != b.P {
return a.P < b.P
}
if a.G != b.G {
return a.G < b.G
}
return a.Args[0] < b.Args[0]
}
func (l orderEventList) Swap(i, j int) {