Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
c1234e7c
authored
2014-08-15 15:24:46 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix the responseWriter
1 parent
b611b9da
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
10 deletions
toolbox/profile.go
toolbox/profile.go
View file @
c1234e7
...
...
@@ -13,7 +13,6 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"path"
"runtime"
...
...
@@ -46,7 +45,7 @@ func ProcessInput(input string, w io.Writer) {
p
:=
pprof
.
Lookup
(
"block"
)
p
.
WriteTo
(
w
,
2
)
case
"get cpuprof"
:
GetCPUProfile
(
w
.
(
http
.
ResponseWriter
)
)
GetCPUProfile
(
w
)
case
"get memprof"
:
MemProf
(
w
)
case
"gc summary"
:
...
...
@@ -71,24 +70,21 @@ func MemProf(w io.Writer) {
}
// start cpu profile monitor
func
GetCPUProfile
(
rw
http
.
Response
Writer
)
{
func
GetCPUProfile
(
w
io
.
Writer
)
{
sec
:=
30
rw
.
Header
()
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
filename
:=
"cpu-"
+
strconv
.
Itoa
(
pid
)
+
".pprof"
f
,
err
:=
os
.
Create
(
filename
)
if
err
!=
nil
{
rw
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
fmt
.
Fprintf
(
rw
,
"Could not enable CPU profiling: %s
\n
"
,
err
)
fmt
.
Fprintf
(
w
,
"Could not enable CPU profiling: %s
\n
"
,
err
)
log
.
Fatal
(
"record cpu profile failed: "
,
err
)
}
fmt
.
Fprintf
(
rw
,
"start cpu profileing
\n
"
)
pprof
.
StartCPUProfile
(
f
)
time
.
Sleep
(
time
.
Duration
(
sec
)
*
time
.
Second
)
pprof
.
StopCPUProfile
()
fmt
.
Fprintf
(
rw
,
"create cpu profile %s
\n
"
,
filename
)
fmt
.
Fprintf
(
w
,
"create cpu profile %s
\n
"
,
filename
)
_
,
fl
:=
path
.
Split
(
os
.
Args
[
0
])
fmt
.
Fprintf
(
r
w
,
"Now you can use this to check it: go tool pprof %s %s
\n
"
,
fl
,
filename
)
fmt
.
Fprintf
(
w
,
"Now you can use this to check it: go tool pprof %s %s
\n
"
,
fl
,
filename
)
}
// print gc information to io.Writer
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment