]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: add tracing support
authorDmitry Vyukov <dvyukov@google.com>
Fri, 12 Dec 2014 17:56:36 +0000 (18:56 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Wed, 28 Jan 2015 16:40:35 +0000 (16:40 +0000)
runtime/pprof part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: I3143a569cbd33576f19ca47308d1ff5200d8c955
Reviewed-on: https://go-review.googlesource.com/1452
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/pprof/pprof.go

index 236de54f384cabc24effed0da6c188ed1756a0e9..b3d0ae9b648b069d5ea9ed4df980b25bf60bf9c4 100644 (file)
@@ -615,6 +615,33 @@ func StopCPUProfile() {
        <-cpu.done
 }
 
+// TODO(rsc): Decide if StartTrace belongs in this package.
+// See golang.org/issue/9710.
+// StartTrace enables tracing for the current process.
+// While tracing, the trace will be buffered and written to w.
+// StartTrace returns an error if profiling is tracing enabled.
+func StartTrace(w io.Writer) error {
+       if err := runtime.StartTrace(); err != nil {
+               return err
+       }
+       go func() {
+               for {
+                       data := runtime.ReadTrace()
+                       if data == nil {
+                               break
+                       }
+                       w.Write(data)
+               }
+       }()
+       return nil
+}
+
+// StopTrace stops the current tracing, if any.
+// StopTrace only returns after all the writes for the trace have completed.
+func StopTrace() {
+       runtime.StopTrace()
+}
+
 type byCycles []runtime.BlockProfileRecord
 
 func (x byCycles) Len() int           { return len(x) }