aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-01-14 10:39:50 -0500
committerRuss Cox <rsc@golang.org>2014-01-14 10:39:50 -0500
commit3ec60c253d9d419eb7a35a40e01315e3d1497465 (patch)
tree767ad42cc7c581ad12c20129743e1f0da709f7a2 /src/pkg/runtime
parente0dcf73d6163beeb4e92715d2f64fdc0ca9573be (diff)
downloadgo-3ec60c253d9d419eb7a35a40e01315e3d1497465.tar.xz
runtime: emit collection stacks in GODEBUG=allocfreetrace mode
R=khr, dvyukov CC=golang-codereviews https://golang.org/cl/51830043
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/malloc.h1
-rw-r--r--src/pkg/runtime/mgc0.c3
-rw-r--r--src/pkg/runtime/mprof.goc20
3 files changed, 20 insertions, 4 deletions
diff --git a/src/pkg/runtime/malloc.h b/src/pkg/runtime/malloc.h
index 66154c0db6..9f34b55461 100644
--- a/src/pkg/runtime/malloc.h
+++ b/src/pkg/runtime/malloc.h
@@ -521,6 +521,7 @@ enum
void runtime·MProf_Malloc(void*, uintptr, uintptr);
void runtime·MProf_Free(Bucket*, void*, uintptr);
void runtime·MProf_GC(void);
+void runtime·MProf_TraceGC(void);
int32 runtime·gcprocs(void);
void runtime·helpgc(int32 nproc);
void runtime·gchelper(void);
diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c
index 9b7d013700..af4ba42a62 100644
--- a/src/pkg/runtime/mgc0.c
+++ b/src/pkg/runtime/mgc0.c
@@ -2163,6 +2163,9 @@ runtime·gc(int32 force)
a.start_time = runtime·nanotime();
m->gcing = 1;
runtime·stoptheworld();
+
+ if(runtime·debug.allocfreetrace)
+ runtime·MProf_TraceGC();
clearpools();
diff --git a/src/pkg/runtime/mprof.goc b/src/pkg/runtime/mprof.goc
index 5523a91446..51d0224250 100644
--- a/src/pkg/runtime/mprof.goc
+++ b/src/pkg/runtime/mprof.goc
@@ -173,6 +173,18 @@ printstackframes(uintptr *stk, int32 nstk)
}
}
+// Called by collector to report a gc in allocfreetrace mode.
+void
+runtime·MProf_TraceGC(void)
+{
+ uintptr stk[32];
+ int32 nstk;
+
+ nstk = runtime·callers(1, stk, nelem(stk));
+ runtime·printf("MProf_TraceGC\n");
+ printstackframes(stk, nstk);
+}
+
// Called by malloc to record a profiled block.
void
runtime·MProf_Malloc(void *p, uintptr size, uintptr typ)
@@ -183,14 +195,14 @@ runtime·MProf_Malloc(void *p, uintptr size, uintptr typ)
int8 *name;
int32 nstk;
- nstk = runtime·callers(1, stk, 32);
+ nstk = runtime·callers(1, stk, nelem(stk));
runtime·lock(&proflock);
- if(runtime·debug.allocfreetrace) {
+ if(runtime·debug.allocfreetrace) {
type = (Type*)(typ & ~3);
name = typeinfoname(typ & 3);
runtime·printf("MProf_Malloc(p=%p, size=%p, type=%p <%s", p, size, type, name);
if(type != nil)
- runtime·printf(" of %S", *type->string);
+ runtime·printf(" of %S", *type->string);
runtime·printf(">)\n");
printstackframes(stk, nstk);
}
@@ -247,7 +259,7 @@ runtime·blockevent(int64 cycles, int32 skip)
if(rate <= 0 || (rate > cycles && runtime·fastrand1()%rate > cycles))
return;
- nstk = runtime·callers(skip, stk, 32);
+ nstk = runtime·callers(skip, stk, nelem(stk));
runtime·lock(&proflock);
b = stkbucket(BProf, stk, nstk, true);
b->count++;