runtime: simplify CPU profiling code

This makes Go's CPU profiling code somewhat more idiomatic; e.g.,
using := instead of forward declaring variables, using "int" for
element counts instead of "uintptr", and slices instead of C-style
pointer+length.  This makes the code easier to read and eliminates a
lot of type conversion clutter.

Additionally, in sigprof we can collect just maxCPUProfStack stack
frames, as cpuprof won't use more than that anyway.

Change-Id: I0235b5ae552191bcbb453b14add6d8c01381bd06
Reviewed-on: https://go-review.googlesource.com/6072
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
This commit is contained in:
Matthew Dempsky 2015-02-25 14:41:21 +09:00 committed by Dmitry Vyukov
parent a32dd83253
commit 3c8a89daf3
11 changed files with 50 additions and 58 deletions

View file

@ -468,9 +468,9 @@ func traceEvent(ev byte, stack bool, args ...uint64) {
}
var nstk int
if gp == _g_ {
nstk = callers(1, &buf.stk[0], len(buf.stk))
nstk = callers(1, buf.stk[:])
} else if gp != nil {
nstk = gcallers(mp.curg, 1, &buf.stk[0], len(buf.stk))
nstk = gcallers(mp.curg, 1, buf.stk[:])
}
id := trace.stackTab.put(buf.stk[:nstk])
data = traceAppend(data, uint64(id))