-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for execution traces (#23)
* Add support for execution traces - Only available on Go 1.7+ * Fix support for Go 1.6 and earlier
- Loading branch information
1 parent
7b053ad
commit 1c16f11
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// +build go1.7 | ||
|
||
package profile | ||
|
||
import "runtime/trace" | ||
|
||
// Trace profile controls if execution tracing will be enabled. It disables any previous profiling settings. | ||
func TraceProfile(p *profile) { p.mode = traceMode } | ||
|
||
var startTrace = trace.Start | ||
var stopTrace = trace.Stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build !go1.7 | ||
|
||
package profile | ||
|
||
import "io" | ||
|
||
// mock trace support for Go 1.6 and earlier. | ||
|
||
func startTrace(w io.Writer) error { return nil } | ||
func stopTrace() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build go1.7 | ||
|
||
package profile_test | ||
|
||
import "github.com/pkg/profile" | ||
|
||
func ExampleTraceProfile() { | ||
// use execution tracing, rather than the default cpu profiling. | ||
defer profile.Start(profile.TraceProfile).Stop() | ||
} |