khalfella

Untitled

Mar 4th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net/http"
  6. "os"
  7. "flag"
  8. "time"
  9. "runtime/pprof"
  10. _ "net/http/pprof"
  11. )
  12.  
  13. var memprofile = flag.String("memprofile", "", "write memory profile to this file")
  14.  
  15. func mainHandler(w http.ResponseWriter, req *http.Request) {
  16. fmt.Fprintf(w, "Hey you are here")
  17. req.Body.Close()
  18. }
  19.  
  20. func main() {
  21.  
  22. flag.Parse()
  23.  
  24. //code for enabling the memory profiler
  25. if *memprofile != "" {
  26. fmt.Println("Enabling Memory profiling");
  27. f, err := os.Create(*memprofile)
  28. if err != nil {
  29. fmt.Fprintf(os.Stderr, "Error creating memprofile file: %s\n", err.Error())
  30. os.Exit(1)
  31. }
  32. pprof.WriteHeapProfile(f)
  33. f.Close()
  34. }
  35. //end of code for enabling memory profiler
  36.  
  37.  
  38. http.HandleFunc("/", mainHandler)
  39. go http.ListenAndServe(":8080", nil)
  40. timer := time.NewTimer(time.Second * 300)
  41. <- timer.C
  42. os.Exit(0)
  43. }
Advertisement
Add Comment
Please, Sign In to add comment