March 2020
Intermediate to advanced
406 pages
8h 39m
English
GCTRACE is utilized during runtime to view a single line that's been printed to stderr showing the total memory collected and the length of the pause during each collection. At the time of writing, this line is organized as follows:
gc# @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, #P
We can instrument a simple HTTP server to provide an example of how this works. First, we write a simple HTTP server with a simple response of Hello Gophers to the root of localhost:8080:
package mainimport ( "fmt" "net/http")func hello(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello Gophers")}func main() { http.HandleFunc("/", hello) err := http.ListenAndServe(":8080", nil) if err != nil { fmt.Println(err) }}
Next, ...
Read now
Unlock full access