diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2014-01-16 12:54:46 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2014-01-16 12:54:46 +0400 |
| commit | c0b9e6218c63a21e12305f8f7fbe7c92bdcbcbde (patch) | |
| tree | f7a88d3075dca0519358f184e20feb36b36155a7 /src/pkg/runtime/proc.c | |
| parent | 4722b1cbd3c734b67c0e3c1cd4458cdbd51e5844 (diff) | |
| download | go-c0b9e6218c63a21e12305f8f7fbe7c92bdcbcbde.tar.xz | |
runtime: output how long goroutines are blocked
Example of output:
goroutine 4 [sleep for 3 min]:
time.Sleep(0x34630b8a000)
src/pkg/runtime/time.goc:31 +0x31
main.func·002()
block.go:16 +0x2c
created by main.main
block.go:17 +0x33
Full program and output are here:
http://play.golang.org/p/NEZdADI3Td
Fixes #6809.
R=golang-codereviews, khr, kamil.kisiel, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/50420043
Diffstat (limited to 'src/pkg/runtime/proc.c')
| -rw-r--r-- | src/pkg/runtime/proc.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index bc371260fc..064e8cb248 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -237,6 +237,7 @@ void runtime·goroutineheader(G *gp) { int8 *status; + int64 waitfor; switch(gp->status) { case Gidle: @@ -261,7 +262,16 @@ runtime·goroutineheader(G *gp) status = "???"; break; } - runtime·printf("goroutine %D [%s]:\n", gp->goid, status); + + // approx time the G is blocked, in minutes + waitfor = 0; + if((gp->status == Gwaiting || gp->status == Gsyscall) && gp->waitsince != 0) + waitfor = (runtime·nanotime() - gp->waitsince) / (60LL*1000*1000*1000); + + if(waitfor < 1) + runtime·printf("goroutine %D [%s]:\n", gp->goid, status); + else + runtime·printf("goroutine %D [%s, %D minutes]:\n", gp->goid, status, waitfor); } void @@ -1112,6 +1122,7 @@ execute(G *gp) runtime·throw("execute: bad g status"); } gp->status = Grunning; + gp->waitsince = 0; gp->preempt = false; gp->stackguard0 = gp->stackguard; m->p->schedtick++; @@ -1535,6 +1546,7 @@ runtime·exitsyscall(void) if(g->isbackground) // do not consider blocked scavenger for deadlock detection incidlelocked(-1); + g->waitsince = 0; if(exitsyscallfast()) { // There's a cpu for us, so we can run. m->p->syscalltick++; |
