Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
86559e9e
Unverified
Commit
86559e9e
authored
Sep 27, 2018
by
Steven Allen
Committed by
GitHub
Sep 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5527 from ipfs/feat/pprof-lock
pprof: create HTTP endpoint for setting MutexProfileFraction
parents
727bf49e
12746433
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+1
-0
core/corehttp/mutex_profile.go
core/corehttp/mutex_profile.go
+45
-0
test/sharness/t0110-gateway.sh
test/sharness/t0110-gateway.sh
+15
-0
No files found.
cmd/ipfs/daemon.go
View file @
86559e9e
...
...
@@ -448,6 +448,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
corehttp
.
VersionOption
(),
defaultMux
(
"/debug/vars"
),
defaultMux
(
"/debug/pprof/"
),
corehttp
.
MutexFractionOption
(
"/debug/pprof-mutex/"
),
corehttp
.
MetricsScrapingOption
(
"/debug/metrics/prometheus"
),
corehttp
.
LogOption
(),
}
...
...
core/corehttp/mutex_profile.go
0 → 100644
View file @
86559e9e
package
corehttp
import
(
"net"
"net/http"
"runtime"
"strconv"
core
"github.com/ipfs/go-ipfs/core"
)
// MutexFractionOption allows to set runtime.SetMutexProfileFraction via HTTP
// using POST request with parameter 'fraction'.
func
MutexFractionOption
(
path
string
)
ServeOption
{
return
func
(
_
*
core
.
IpfsNode
,
_
net
.
Listener
,
mux
*
http
.
ServeMux
)
(
*
http
.
ServeMux
,
error
)
{
mux
.
HandleFunc
(
path
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
http
.
MethodPost
{
w
.
WriteHeader
(
http
.
StatusMethodNotAllowed
)
return
}
if
err
:=
r
.
ParseForm
();
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
asfr
:=
r
.
Form
.
Get
(
"fraction"
)
if
len
(
asfr
)
==
0
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
return
}
fr
,
err
:=
strconv
.
Atoi
(
asfr
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
log
.
Infof
(
"Setting MutexProfileFraction to %d"
,
fr
)
runtime
.
SetMutexProfileFraction
(
fr
)
})
return
mux
,
nil
}
}
test/sharness/t0110-gateway.sh
View file @
86559e9e
...
...
@@ -106,6 +106,21 @@ test_expect_success "output only has one transfer encoding header" '
test_cmp tecount_out tecount_exp
'
curl_pprofmutex
()
{
curl
-f
-X
POST
"http://127.0.0.1:
$apiport
/debug/pprof-mutex/?fraction=
$1
"
}
test_expect_success
"set mutex fraction for pprof (negative so it doesn't enable)"
'
curl_pprofmutex -1
'
test_expect_success
"test failure conditions of mutex pprof endpoint"
'
test_must_fail curl_pprofmutex &&
test_must_fail curl_pprofmutex that_is_string &&
test_must_fail curl -f -X GET "http://127.0.0.1:$apiport/debug/pprof-mutex/?fraction=-1"
'
test_expect_success
"setup index hash"
'
mkdir index &&
echo "<p></p>" > index/index.html &&
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment