The Go tool trace can also generate four different types of traces that may be pertinent to your troubleshooting needs:
- net: A network-blocking profile
- sync: A synchronization-blocking profile
- syscall: A syscall-blocking profile
- sched: A scheduler-latency profile
Let's take a look at an example of how to use these tracing profiles on a web server:
- First, we initialize our main and import the necessary packages. Note the blank identifier for the explicit package name within _ "net/http/pprof". This is used in order to make sure we can make the tracing call:
package main
import (
"io"
"net/http"
_ "net/http/pprof"
"time"
)
- We next set up a simple web server that waits five seconds and returns a string to the end user:
func main() {
handler := func(w http.ResponseWriter, req *http...