Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net/http"
- "os"
- "flag"
- "time"
- "runtime/pprof"
- _ "net/http/pprof"
- )
- var memprofile = flag.String("memprofile", "", "write memory profile to this file")
- func mainHandler(w http.ResponseWriter, req *http.Request) {
- fmt.Fprintf(w, "Hey you are here")
- req.Body.Close()
- }
- func main() {
- flag.Parse()
- //code for enabling the memory profiler
- if *memprofile != "" {
- fmt.Println("Enabling Memory profiling");
- f, err := os.Create(*memprofile)
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error creating memprofile file: %s\n", err.Error())
- os.Exit(1)
- }
- pprof.WriteHeapProfile(f)
- f.Close()
- }
- //end of code for enabling memory profiler
- http.HandleFunc("/", mainHandler)
- go http.ListenAndServe(":8080", nil)
- timer := time.NewTimer(time.Second * 300)
- <- timer.C
- os.Exit(0)
- }
Advertisement
Add Comment
Please, Sign In to add comment