@@ -290,106 +290,74 @@ func (a *Agent) Monitor(stopCh <-chan struct{}, q *QueryOptions) (<-chan *Stream
290
290
return frames , errCh
291
291
}
292
292
293
+ // PprofOptions contain a set of parameters for profiling a node or server.
294
+ type PprofOptions struct {
295
+ // ServerID is the server ID, name, or special value "leader" to
296
+ // specify the server that a given profile should be run on.
297
+ ServerID string
298
+
299
+ // NodeID is the node ID that a given profile should be run on.
300
+ NodeID string
301
+
302
+ // Seconds specifies the amount of time a profile should be run for.
303
+ // Seconds only applies for certain runtime profiles like CPU and Trace.
304
+ Seconds int
305
+
306
+ // GC determines if a runtime.GC() should be called before a heap
307
+ // profile.
308
+ GC int
309
+
310
+ // Debug specifies if the output of a lookup profile should be returned
311
+ // in human readable format instead of binary.
312
+ Debug int
313
+ }
314
+
293
315
// CPUProfile returns a runtime/pprof cpu profile for a given server or node.
294
316
// The profile will run for the amount of seconds passed in or default to 1.
295
317
// If no serverID or nodeID are provided the current Agents server will be
296
318
// used.
297
319
//
298
- // The parameters are:
299
- // * serverID: server ID or name to query, also accepts "leader"
300
- // * nodeID: client node ID to query
301
- // * seconds: the amount of time to run the trace for.
302
- //
303
320
// The call blocks until the profile finishes, and returns the raw bytes of the
304
321
// profile.
305
- func (a * Agent ) CPUProfile (serverID , nodeID string , seconds int , q * QueryOptions ) ([]byte , error ) {
306
- if q == nil {
307
- q = & QueryOptions {}
308
- }
309
- if q .Params == nil {
310
- q .Params = make (map [string ]string )
311
- }
312
-
313
- q .Params ["seconds" ] = strconv .Itoa (seconds )
314
- q .Params ["node_id" ] = nodeID
315
- q .Params ["server_id" ] = serverID
316
-
317
- body , err := a .client .rawQuery ("/v1/agent/pprof/profile" , q )
318
- if err != nil {
319
- return nil , err
320
- }
321
-
322
- resp , err := ioutil .ReadAll (body )
323
- if err != nil {
324
- return nil , err
325
- }
326
-
327
- return resp , nil
322
+ func (a * Agent ) CPUProfile (opts PprofOptions , q * QueryOptions ) ([]byte , error ) {
323
+ return a .pprofRequest ("profile" , opts , q )
328
324
}
329
325
330
326
// Trace returns a runtime/pprof trace for a given server or node.
331
327
// The trace will run for the amount of seconds passed in or default to 1.
332
328
// If no serverID or nodeID are provided the current Agents server will be
333
329
// used.
334
330
//
335
- // The parameters are:
336
- // * serverID: server ID or name to query, also accepts "leader"
337
- // * nodeID: client node ID to query
338
- // * seconds: the amount of time to run the trace for.
339
- //
340
331
// The call blocks until the profile finishes, and returns the raw bytes of the
341
332
// profile.
342
- func (a * Agent ) Trace (serverID , nodeID string , seconds int , q * QueryOptions ) ([]byte , error ) {
343
- if q == nil {
344
- q = & QueryOptions {}
345
- }
346
- if q .Params == nil {
347
- q .Params = make (map [string ]string )
348
- }
349
-
350
- q .Params ["seconds" ] = strconv .Itoa (seconds )
351
- q .Params ["node_id" ] = nodeID
352
- q .Params ["server_id" ] = serverID
353
-
354
- body , err := a .client .rawQuery ("/v1/agent/pprof/trace" , q )
355
- if err != nil {
356
- return nil , err
357
- }
358
-
359
- resp , err := ioutil .ReadAll (body )
360
- if err != nil {
361
- return nil , err
362
- }
363
-
364
- return resp , nil
365
-
333
+ func (a * Agent ) Trace (opts PprofOptions , q * QueryOptions ) ([]byte , error ) {
334
+ return a .pprofRequest ("trace" , opts , q )
366
335
}
367
336
368
- // Profile returns a runtime/pprof profile using pprof.Lookup to determine
337
+ // Lookup returns a runtime/pprof profile using pprof.Lookup to determine
369
338
// which profile to run. Accepts a client or server ID but not both simultaneously.
370
339
//
371
- // The parameters are:
372
- // * serverID: server ID or name to query, also accepts "leader"
373
- // * nodeID: client node ID to query
374
- // * profile: the name of the runtime/pprof profile to lookup and run.
375
- // * debug: flag to specify if the profile should return human readable output.
376
- //
377
340
// The call blocks until the profile finishes, and returns the raw bytes of the
378
- // profile.
379
- func (a * Agent ) Profile (serverID , nodeID , profile string , debug , gc int , q * QueryOptions ) ([]byte , error ) {
341
+ // profile unless debug is set.
342
+ func (a * Agent ) Lookup (profile string , opts PprofOptions , q * QueryOptions ) ([]byte , error ) {
343
+ return a .pprofRequest (profile , opts , q )
344
+ }
345
+
346
+ func (a * Agent ) pprofRequest (req string , opts PprofOptions , q * QueryOptions ) ([]byte , error ) {
380
347
if q == nil {
381
348
q = & QueryOptions {}
382
349
}
383
350
if q .Params == nil {
384
351
q .Params = make (map [string ]string )
385
352
}
386
353
387
- q .Params ["debug" ] = strconv .Itoa (debug )
388
- q .Params ["qc" ] = strconv .Itoa (debug )
389
- q .Params ["node_id" ] = nodeID
390
- q .Params ["server_id" ] = serverID
354
+ q .Params ["seconds" ] = strconv .Itoa (opts .Seconds )
355
+ q .Params ["debug" ] = strconv .Itoa (opts .Debug )
356
+ q .Params ["gc" ] = strconv .Itoa (opts .GC )
357
+ q .Params ["node_id" ] = opts .NodeID
358
+ q .Params ["server_id" ] = opts .ServerID
391
359
392
- body , err := a .client .rawQuery (fmt .Sprintf ("/v1/agent/pprof/%s" , profile ), q )
360
+ body , err := a .client .rawQuery (fmt .Sprintf ("/v1/agent/pprof/%s" , req ), q )
393
361
if err != nil {
394
362
return nil , err
395
363
}
0 commit comments