提交 503bf529 编写于 作者: A aarzilli 提交者: Derek Parker

proc: improve performance of FindGoroutine in normal circumstances

FindGoroutine can be slow when there are many goroutines running. This
can not be fixed in the general case, however:

1. Instead of getting the entire list of goroutines at once just get a
   few at a time and return as soon as we find the one we want.

2. Since FindGoroutine is mostly called by ConvertEvalScope and users
   are more likely to request informations about a goroutine running on a
   thread, look within the threads first.
上级 515ccc4b
......@@ -604,20 +604,37 @@ func FindGoroutine(dbp Process, gid int) (*G, error) {
if g == nil || g.ID == 0 {
return g, nil
}
return nil, fmt.Errorf("Unknown goroutine %d", gid)
}
gs, _, err := GoroutinesInfo(dbp, 0, 0)
if err != nil {
return nil, err
// Calling GoroutinesInfo could be slow if there are many goroutines
// running, check if a running goroutine has been requested first.
for _, thread := range dbp.ThreadList() {
g, _ := GetG(thread)
if g != nil && g.ID == gid {
return g, nil
}
}
for i := range gs {
if gs[i].ID == gid {
if gs[i].Unreadable != nil {
return nil, gs[i].Unreadable
const goroutinesInfoLimit = 10
nextg := 0
for nextg >= 0 {
var gs []*G
var err error
gs, nextg, err = GoroutinesInfo(dbp, nextg, goroutinesInfoLimit)
if err != nil {
return nil, err
}
for i := range gs {
if gs[i].ID == gid {
if gs[i].Unreadable != nil {
return nil, gs[i].Unreadable
}
return gs[i], nil
}
return gs[i], nil
}
}
return nil, fmt.Errorf("Unknown goroutine %d", gid)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册