diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2014-09-02 00:14:22 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-09-02 00:14:22 -0400 |
| commit | ac49e6735bb3757a16816f7400ce823cd6fc8508 (patch) | |
| tree | e2ff90501cb6b2dd7ae66b05ffacc41434d5d20a /src/pkg/runtime/proc.c | |
| parent | a19e638db27d6e03c9f0c0220a547f7ebd9e599a (diff) | |
| download | go-ac49e6735bb3757a16816f7400ce823cd6fc8508.tar.xz | |
runtime: convert cpuprof from C to Go
LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/132440043
Diffstat (limited to 'src/pkg/runtime/proc.c')
| -rw-r--r-- | src/pkg/runtime/proc.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 1a82c8e541..d1ebd853bb 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -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); |
