internal/debug: add support for mutex profiles (#16230)
This commit is contained in:
parent
49bcb5fbd5
commit
12f4d28411
@ -140,10 +140,9 @@ func (h *HandlerT) GoTrace(file string, nsec uint) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockProfile turns on CPU profiling for nsec seconds and writes
|
// BlockProfile turns on goroutine profiling for nsec seconds and writes profile data to
|
||||||
// profile data to file. It uses a profile rate of 1 for most accurate
|
// file. It uses a profile rate of 1 for most accurate information. If a different rate is
|
||||||
// information. If a different rate is desired, set the rate
|
// desired, set the rate and write the profile manually.
|
||||||
// and write the profile manually.
|
|
||||||
func (*HandlerT) BlockProfile(file string, nsec uint) error {
|
func (*HandlerT) BlockProfile(file string, nsec uint) error {
|
||||||
runtime.SetBlockProfileRate(1)
|
runtime.SetBlockProfileRate(1)
|
||||||
time.Sleep(time.Duration(nsec) * time.Second)
|
time.Sleep(time.Duration(nsec) * time.Second)
|
||||||
@ -162,6 +161,26 @@ func (*HandlerT) WriteBlockProfile(file string) error {
|
|||||||
return writeProfile("block", file)
|
return writeProfile("block", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MutexProfile turns on mutex profiling for nsec seconds and writes profile data to file.
|
||||||
|
// It uses a profile rate of 1 for most accurate information. If a different rate is
|
||||||
|
// desired, set the rate and write the profile manually.
|
||||||
|
func (*HandlerT) MutexProfile(file string, nsec uint) error {
|
||||||
|
runtime.SetMutexProfileFraction(1)
|
||||||
|
time.Sleep(time.Duration(nsec) * time.Second)
|
||||||
|
defer runtime.SetMutexProfileFraction(0)
|
||||||
|
return writeProfile("mutex", file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMutexProfileFraction sets the rate of mutex profiling.
|
||||||
|
func (*HandlerT) SetMutexProfileFraction(rate int) {
|
||||||
|
runtime.SetMutexProfileFraction(rate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteMutexProfile writes a goroutine blocking profile to the given file.
|
||||||
|
func (*HandlerT) WriteMutexProfile(file string) error {
|
||||||
|
return writeProfile("mutex", file)
|
||||||
|
}
|
||||||
|
|
||||||
// WriteMemProfile writes an allocation profile to the given file.
|
// WriteMemProfile writes an allocation profile to the given file.
|
||||||
// Note that the profiling rate cannot be set through the API,
|
// Note that the profiling rate cannot be set through the API,
|
||||||
// it must be set on the command line.
|
// it must be set on the command line.
|
||||||
|
@ -307,6 +307,21 @@ web3._extend({
|
|||||||
call: 'debug_writeBlockProfile',
|
call: 'debug_writeBlockProfile',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'mutexProfile',
|
||||||
|
call: 'debug_mutexProfile',
|
||||||
|
params: 2
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'setMutexProfileRate',
|
||||||
|
call: 'debug_setMutexProfileRate',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'writeMutexProfile',
|
||||||
|
call: 'debug_writeMutexProfile',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'writeMemProfile',
|
name: 'writeMemProfile',
|
||||||
call: 'debug_writeMemProfile',
|
call: 'debug_writeMemProfile',
|
||||||
|
Loading…
Reference in New Issue
Block a user