Skip to content

Commit 08b80ca

Browse files
committed
runtime: note interactions between GC and MemProfile
Change-Id: Icce28fc4937cc73c0712c054161222f034381c2f Reviewed-on: https://go-review.googlesource.com/16876 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 92cc3c4 commit 08b80ca

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/runtime/mprof.go

+9
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ func (r *MemProfileRecord) Stack() []uintptr {
368368
return r.Stack0[0:]
369369
}
370370

371+
// MemProfile returns a profile of memory allocated and freed per allocation
372+
// site.
373+
//
371374
// MemProfile returns n, the number of records in the current memory profile.
372375
// If len(p) >= n, MemProfile copies the profile into p and returns n, true.
373376
// If len(p) < n, MemProfile does not change p and returns n, false.
@@ -377,6 +380,12 @@ func (r *MemProfileRecord) Stack() []uintptr {
377380
// These are sites where memory was allocated, but it has all
378381
// been released back to the runtime.
379382
//
383+
// The returned profile may be up to two garbage collection cycles old.
384+
// This is to avoid skewing the profile toward allocations; because
385+
// allocations happen in real time but frees are delayed until the garbage
386+
// collector performs sweeping, the profile only accounts for allocations
387+
// that have had a chance to be freed by the garbage collector.
388+
//
380389
// Most clients should use the runtime/pprof package or
381390
// the testing package's -test.memprofile flag instead
382391
// of calling MemProfile directly.

0 commit comments

Comments
 (0)