Commit ac49e673 authored by Matthew Dempsky's avatar Matthew Dempsky Committed by Russ Cox

runtime: convert cpuprof from C to Go

LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/132440043
parent a19e638d
......@@ -49,22 +49,3 @@ func NumGoroutine() int {
}
func gcount() int32
// CPUProfile returns the next chunk of binary CPU profiling stack trace data,
// blocking until data is available. If profiling is turned off and all the profile
// data accumulated while it was on has been returned, CPUProfile returns nil.
// The caller must save the returned data before calling CPUProfile again.
//
// Most clients should use the runtime/pprof package or
// the testing package's -test.cpuprofile flag instead of calling
// CPUProfile directly.
func CPUProfile() []byte
// SetCPUProfileRate sets the CPU profiling rate to hz samples per second.
// If hz <= 0, SetCPUProfileRate turns off profiling.
// If the profiler is on, the rate cannot be changed without first turning it off.
//
// Most clients should use the runtime/pprof package or
// the testing package's -test.cpuprofile flag instead of calling
// SetCPUProfileRate directly.
func SetCPUProfileRate(hz int)
......@@ -2395,13 +2395,13 @@ runtime·badreflectcall(void) // called from assembly
static struct {
Mutex lock;
void (*fn)(uintptr*, int32);
int32 hz;
} prof;
static void System(void) {}
static void ExternalCode(void) {}
static void GC(void) {}
extern void runtime·cpuproftick(uintptr*, int32);
extern byte runtime·etext[];
// Called if we receive a SIGPROF signal.
......@@ -2418,7 +2418,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
m = 0;
USED(m);
if(prof.fn == nil || prof.hz == 0)
if(prof.hz == 0)
return;
// Profiling runs concurrently with GC, so it must not allocate.
......@@ -2537,10 +2537,10 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
}
}
if(prof.fn != nil) {
if(prof.hz != 0) {
runtime·lock(&prof.lock);
if(prof.fn != nil)
prof.fn(stk, n);
if(prof.hz != 0)
runtime·cpuproftick(stk, n);
runtime·unlock(&prof.lock);
}
mp->mallocing--;
......@@ -2548,15 +2548,11 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
// Arrange to call fn with a traceback hz times a second.
void
runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
runtime·setcpuprofilerate(int32 hz)
{
// Force sane arguments.
if(hz < 0)
hz = 0;
if(hz == 0)
fn = nil;
if(fn == nil)
hz = 0;
// Disable preemption, otherwise we can be rescheduled to another thread
// that has profiling enabled.
......@@ -2568,7 +2564,6 @@ runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
runtime·resetcpuprofiler(0);
runtime·lock(&prof.lock);
prof.fn = fn;
prof.hz = hz;
runtime·unlock(&prof.lock);
runtime·lock(&runtime·sched.lock);
......
......@@ -864,7 +864,7 @@ void runtime·freezetheworld(void);
void runtime·unwindstack(G*, byte*);
void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp);
void runtime·resetcpuprofiler(int32);
void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
void runtime·setcpuprofilerate(int32);
void runtime·usleep(uint32);
int64 runtime·cputicks(void);
int64 runtime·tickspersecond(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment