c1234e7c by astaxie

fix the responseWriter

1 parent b611b9da
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
13 "fmt" 13 "fmt"
14 "io" 14 "io"
15 "log" 15 "log"
16 "net/http"
17 "os" 16 "os"
18 "path" 17 "path"
19 "runtime" 18 "runtime"
...@@ -46,7 +45,7 @@ func ProcessInput(input string, w io.Writer) { ...@@ -46,7 +45,7 @@ func ProcessInput(input string, w io.Writer) {
46 p := pprof.Lookup("block") 45 p := pprof.Lookup("block")
47 p.WriteTo(w, 2) 46 p.WriteTo(w, 2)
48 case "get cpuprof": 47 case "get cpuprof":
49 GetCPUProfile(w.(http.ResponseWriter)) 48 GetCPUProfile(w)
50 case "get memprof": 49 case "get memprof":
51 MemProf(w) 50 MemProf(w)
52 case "gc summary": 51 case "gc summary":
...@@ -71,24 +70,21 @@ func MemProf(w io.Writer) { ...@@ -71,24 +70,21 @@ func MemProf(w io.Writer) {
71 } 70 }
72 71
73 // start cpu profile monitor 72 // start cpu profile monitor
74 func GetCPUProfile(rw http.ResponseWriter) { 73 func GetCPUProfile(w io.Writer) {
75 sec := 30 74 sec := 30
76 rw.Header().Set("Content-Type", "application/octet-stream")
77 filename := "cpu-" + strconv.Itoa(pid) + ".pprof" 75 filename := "cpu-" + strconv.Itoa(pid) + ".pprof"
78 f, err := os.Create(filename) 76 f, err := os.Create(filename)
79 if err != nil { 77 if err != nil {
80 rw.Header().Set("Content-Type", "text/plain; charset=utf-8") 78 fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err)
81 rw.WriteHeader(http.StatusInternalServerError)
82 fmt.Fprintf(rw, "Could not enable CPU profiling: %s\n", err)
83 log.Fatal("record cpu profile failed: ", err) 79 log.Fatal("record cpu profile failed: ", err)
84 } 80 }
85 fmt.Fprintf(rw, "start cpu profileing\n")
86 pprof.StartCPUProfile(f) 81 pprof.StartCPUProfile(f)
87 time.Sleep(time.Duration(sec) * time.Second) 82 time.Sleep(time.Duration(sec) * time.Second)
88 pprof.StopCPUProfile() 83 pprof.StopCPUProfile()
89 fmt.Fprintf(rw, "create cpu profile %s \n", filename) 84
85 fmt.Fprintf(w, "create cpu profile %s \n", filename)
90 _, fl := path.Split(os.Args[0]) 86 _, fl := path.Split(os.Args[0])
91 fmt.Fprintf(rw, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename) 87 fmt.Fprintf(w, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename)
92 } 88 }
93 89
94 // print gc information to io.Writer 90 // print gc information to io.Writer
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!