Skip to content

Commit 12f4d28

Browse files
authored
internal/debug: add support for mutex profiles (#16230)
1 parent 49bcb5f commit 12f4d28

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

internal/debug/api.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ func (h *HandlerT) GoTrace(file string, nsec uint) error {
140140
return nil
141141
}
142142

143-
// BlockProfile turns on CPU profiling for nsec seconds and writes
144-
// profile data to file. It uses a profile rate of 1 for most accurate
145-
// information. If a different rate is desired, set the rate
146-
// and write the profile manually.
143+
// BlockProfile turns on goroutine profiling for nsec seconds and writes profile data to
144+
// file. It uses a profile rate of 1 for most accurate information. If a different rate is
145+
// desired, set the rate and write the profile manually.
147146
func (*HandlerT) BlockProfile(file string, nsec uint) error {
148147
runtime.SetBlockProfileRate(1)
149148
time.Sleep(time.Duration(nsec) * time.Second)
@@ -162,6 +161,26 @@ func (*HandlerT) WriteBlockProfile(file string) error {
162161
return writeProfile("block", file)
163162
}
164163

164+
// MutexProfile turns on mutex profiling for nsec seconds and writes profile data to file.
165+
// It uses a profile rate of 1 for most accurate information. If a different rate is
166+
// desired, set the rate and write the profile manually.
167+
func (*HandlerT) MutexProfile(file string, nsec uint) error {
168+
runtime.SetMutexProfileFraction(1)
169+
time.Sleep(time.Duration(nsec) * time.Second)
170+
defer runtime.SetMutexProfileFraction(0)
171+
return writeProfile("mutex", file)
172+
}
173+
174+
// SetMutexProfileFraction sets the rate of mutex profiling.
175+
func (*HandlerT) SetMutexProfileFraction(rate int) {
176+
runtime.SetMutexProfileFraction(rate)
177+
}
178+
179+
// WriteMutexProfile writes a goroutine blocking profile to the given file.
180+
func (*HandlerT) WriteMutexProfile(file string) error {
181+
return writeProfile("mutex", file)
182+
}
183+
165184
// WriteMemProfile writes an allocation profile to the given file.
166185
// Note that the profiling rate cannot be set through the API,
167186
// it must be set on the command line.

internal/web3ext/web3ext.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ web3._extend({
307307
call: 'debug_writeBlockProfile',
308308
params: 1
309309
}),
310+
new web3._extend.Method({
311+
name: 'mutexProfile',
312+
call: 'debug_mutexProfile',
313+
params: 2
314+
}),
315+
new web3._extend.Method({
316+
name: 'setMutexProfileRate',
317+
call: 'debug_setMutexProfileRate',
318+
params: 1
319+
}),
320+
new web3._extend.Method({
321+
name: 'writeMutexProfile',
322+
call: 'debug_writeMutexProfile',
323+
params: 1
324+
}),
310325
new web3._extend.Method({
311326
name: 'writeMemProfile',
312327
call: 'debug_writeMemProfile',

0 commit comments

Comments
 (0)