Skip to content

Instantly share code, notes, and snippets.

@bxcodec
Last active April 19, 2018 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bxcodec/18bdfad7dea41eef9feb5342f208c4a8 to your computer and use it in GitHub Desktop.
Save bxcodec/18bdfad7dea41eef9feb5342f208c4a8 to your computer and use it in GitHub Desktop.
profiling_api
package main
import (
"fmt"
"log"
"net/http"
"net/http/pprof"
)
func Sample(w http.ResponseWriter, r *http.Request) {
ProcessBigArray()
w.WriteHeader(http.StatusOK)
w.Write([]byte("Hi!"))
}
func main() {
handler := http.NewServeMux()
handler.HandleFunc("/hi", Sample)
// Add Profiling Endpoint
handler.HandleFunc("/debug/pprof/", pprof.Index)
handler.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
handler.HandleFunc("/debug/pprof/profile", pprof.Profile)
handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
handler.HandleFunc("/debug/pprof/trace", pprof.Trace)
log.Println("Server running on port: 9090")
log.Fatal(http.ListenAndServe(":9090", handler))
}
func ProcessBigArray() {
for i := 0; i < 500; i++ {
arr := bigArray()
if arr == nil {
fmt.Println("Array is Nil")
}
}
}
func bigArray() *[]int {
s := make([]int, 1000000)
return &s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment