Last active
April 19, 2018 04:48
-
-
Save bxcodec/18bdfad7dea41eef9feb5342f208c4a8 to your computer and use it in GitHub Desktop.
profiling_api
This file contains hidden or 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
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