|
|
Created:
12 years ago by atom Modified:
12 years ago Reviewers:
CC:
golang-dev, dvyukov, rsc Visibility:
Public. |
Descriptionruntime: add garbage collector statistics
If the constant CollectStats is non-zero and GOGCTRACE=1
the garbage collector will print basic statistics about executed
GC instructions.
Patch Set 1 #Patch Set 2 : diff -r 2e9e27f95e17 https://go.googlecode.com/hg/ #Patch Set 3 : diff -r 2e9e27f95e17 https://go.googlecode.com/hg/ #Patch Set 4 : diff -r 8a08842f7978 https://code.google.com/p/go/ #MessagesTotal messages: 8
Hello golang-dev@googlegroups.com (cc: rsc), I'd like you to review this change to https://go.googlecode.com/hg/
Sign in to reply to this message.
On Sun, Mar 3, 2013 at 10:41 AM, <0xE2.0x9A.0x9B@gmail.com> wrote: > Reviewers: golang-dev1, > > Message: > Hello golang-dev@googlegroups.com (cc: rsc), > > I'd like you to review this change to > https://go.googlecode.com/hg/ > > > Description: > runtime: add garbage collector statistics > > If the constant CollectStats is non-zero and GOGCTRACE=1 > the garbage collector will print basic statistics about executed > GC instructions. > > Please review this at https://codereview.appspot.com/7413049/ > > Affected files: > M src/pkg/runtime/mgc0.c > > > Index: src/pkg/runtime/mgc0.c > =================================================================== > --- a/src/pkg/runtime/mgc0.c > +++ b/src/pkg/runtime/mgc0.c > @@ -17,6 +17,7 @@ > enum { > Debug = 0, > DebugMark = 0, // run second pass to check mark > + CollectStats = 0, > > // Four bits per word (see #defines below). > wordsPerBitmapWord = sizeof(void*)*8/4, > @@ -165,8 +166,25 @@ > GC_DEFAULT_PTR = GC_NUM_INSTR, > GC_MAP_NEXT, > GC_CHAN, > + > + GC_NUM_INSTR2 > }; > > +static struct { > + uint64 ptr_sum; The codebase does not use underscores FWIW > + uint64 ptr_cnt; > + uint64 nbytes; > + uint64 nobj_sum; > + uint64 nobj_cnt; > + uint64 nobj_notype; > + uint64 nobj_typelookups_ok; > + uint64 rescans; > + uint64 rescan_nbytes; > + uint64 instr[GC_NUM_INSTR2]; > + uint64 putempty; > + uint64 getfull; > +} gcstats; > + > // markonly marks an object. It returns true if the object > // has been marked by this function, false otherwise. > // This function isn't thread-safe and doesn't append the object to any > buffer. > @@ -315,6 +333,11 @@ > n = ptrbuf_end - ptrbuf; > *ptrbufpos = ptrbuf; > > + if(CollectStats) { > + runtime·xadd64(&gcstats.ptr_sum, n); > + runtime·xadd64(&gcstats.ptr_cnt, 1); > + } > + > // If buffer is nearly full, get a new one. > if(wbuf == nil || nobj+n >= nelem(wbuf->obj)) { > if(wbuf != nil) > @@ -621,6 +644,12 @@ > runtime·printf("scanblock %p %D\n", b, (int64)n); > } > > + if(CollectStats) { > + runtime·xadd64(&gcstats.nbytes, n); > + runtime·xadd64(&gcstats.nobj_sum, nobj); > + runtime·xadd64(&gcstats.nobj_cnt, 1); > + } > + > if(ti != 0) { > pc = (uintptr*)(ti & ~(uintptr)PC_BITS); > precise_type = (ti & PRECISE); > @@ -634,8 +663,14 @@ > stack_top.count = 1; > } > } else if(UseSpanType) { > + if(CollectStats) > + runtime·xadd64(&gcstats.nobj_notype, 1); > + > type = runtime·gettype(b); > if(type != 0) { > + if(CollectStats) > + > runtime·xadd64(&gcstats.nobj_typelookups_ok, 1); > + > t = (Type*)(type & ~(uintptr)(PtrSize-1)); > switch(type & (PtrSize-1)) { > case TypeInfo_SingleObject: > @@ -692,6 +727,9 @@ > end_b = (uintptr)b + n - PtrSize; > > for(;;) { > + if(CollectStats) > + runtime·xadd64(&gcstats.instr[pc[0]], 1); > + > obj = nil; > objti = 0; > switch(pc[0]) { > @@ -1164,6 +1202,9 @@ > static void > putempty(Workbuf *b) > { > + if(CollectStats) > + runtime·xadd64(&gcstats.putempty, 1); > + > runtime·lfstackpush(&work.empty, &b->node); > } > > @@ -1173,6 +1214,9 @@ > { > int32 i; > > + if(CollectStats) > + runtime·xadd64(&gcstats.getfull, 1); > + > if(b != nil) > runtime·lfstackpush(&work.empty, &b->node); > b = (Workbuf*)runtime·lfstackpop(&work.full); > @@ -1747,7 +1791,7 @@ > gc(struct gc_args *args) > { > int64 t0, t1, t2, t3, t4; > - uint64 heap0, heap1, obj0, obj1; > + uint64 heap0, heap1, obj0, obj1, ninstr; > GCStats stats; > M *mp; > uint32 i; > @@ -1764,6 +1808,9 @@ > m->gcing = 1; > runtime·stoptheworld(); > > + if(CollectStats) > + runtime·memclr((byte*)&gcstats, sizeof(gcstats)); > + > for(mp=runtime·allm; mp; mp=mp->alllink) > runtime·settype_flush(mp, false); > > @@ -1859,6 +1906,27 @@ > stats.nhandoff, stats.nhandoffcnt, > work.sweepfor->nsteal, work.sweepfor->nstealcnt, > stats.nprocyield, stats.nosyield, stats.nsleep); > + if(CollectStats) { > + runtime·printf("scan: %D bytes, %D objects, %D > untyped, %D types from MSpan\n", > + gcstats.nbytes, gcstats.nobj_cnt, > gcstats.nobj_notype, gcstats.nobj_typelookups_ok); > + if(gcstats.ptr_cnt != 0) > + runtime·printf("avg ptrbufsize: %D > (%D/%D)\n", > + gcstats.ptr_sum/gcstats.ptr_cnt, > gcstats.ptr_sum, gcstats.ptr_cnt); > + if(gcstats.nobj_cnt != 0) > + runtime·printf("avg nobj: %D (%D/%D)\n", > + gcstats.nobj_sum/gcstats.nobj_cnt, > gcstats.nobj_sum, gcstats.nobj_cnt); > + runtime·printf("rescans: %D, %D bytes\n", > gcstats.rescans, gcstats.rescan_nbytes); > + > + runtime·printf("instruction counts:\n"); > + ninstr = 0; > + for(i=0; i<nelem(gcstats.instr); i++) { > + runtime·printf("\t%d:\t%D\n", i, > gcstats.instr[i]); > + ninstr += gcstats.instr[i]; > + } > + runtime·printf("\ttotal:\t%D\n", ninstr); > + > + runtime·printf("putempty: %D, getfull: %D\n", > gcstats.putempty, gcstats.getfull); > + } > } > > runtime·MProf_GC(); > > > -- > > ---You received this message because you are subscribed to the Google Groups > "golang-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-dev+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > >
Sign in to reply to this message.
On 2013/03/03 08:56:20, dvyukov wrote: > On Sun, Mar 3, 2013 at 10:41 AM, <mailto:0xE2.0x9A.0x9B@gmail.com> wrote: > > > > +static struct { > > + uint64 ptr_sum; > > The codebase does not use underscores FWIW > > > + uint64 ptr_cnt; > > + uint64 nbytes; > > + uint64 nobj_sum; > > + uint64 nobj_cnt; > > + uint64 nobj_notype; > > + uint64 nobj_typelookups_ok; How to rename nobj_typelookups_ok? > > + uint64 rescans; > > + uint64 rescan_nbytes; > > + uint64 instr[GC_NUM_INSTR2]; > > + uint64 putempty; > > + uint64 getfull; > > +} gcstats; > > +
Sign in to reply to this message.
On 2013/03/03 09:01:29, atom wrote: > On 2013/03/03 08:56:20, dvyukov wrote: > > On Sun, Mar 3, 2013 at 10:41 AM, <mailto:0xE2.0x9A.0x9B@gmail.com> wrote: > > > > > > +static struct { > > > + uint64 ptr_sum; > > > > The codebase does not use underscores FWIW > > > > > + uint64 ptr_cnt; > > > + uint64 nbytes; > > > + uint64 nobj_sum; > > > + uint64 nobj_cnt; > > > + uint64 nobj_notype; > > > + uint64 nobj_typelookups_ok; > > How to rename nobj_typelookups_ok? ntypelookup?
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, dvyukov@google.com (cc: golang-dev@googlegroups.com, rsc@golang.org), Please take another look.
Sign in to reply to this message.
*** Submitted as https://code.google.com/p/go/source/detail?r=a565c143b41b *** runtime: add garbage collector statistics If the constant CollectStats is non-zero and GOGCTRACE=1 the garbage collector will print basic statistics about executed GC instructions. R=golang-dev, dvyukov CC=golang-dev, rsc https://codereview.appspot.com/7413049
Sign in to reply to this message.
|