@@ -140,10 +140,9 @@ func (h *HandlerT) GoTrace(file string, nsec uint) error {
140
140
return nil
141
141
}
142
142
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.
147
146
func (* HandlerT ) BlockProfile (file string , nsec uint ) error {
148
147
runtime .SetBlockProfileRate (1 )
149
148
time .Sleep (time .Duration (nsec ) * time .Second )
@@ -162,6 +161,26 @@ func (*HandlerT) WriteBlockProfile(file string) error {
162
161
return writeProfile ("block" , file )
163
162
}
164
163
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
+
165
184
// WriteMemProfile writes an allocation profile to the given file.
166
185
// Note that the profiling rate cannot be set through the API,
167
186
// it must be set on the command line.
0 commit comments