Profiler

Profiler

Polls profiler server for instructions on behalf of a task and collects and uploads profiles as requested.

If heap profiling is enabled, the heap profiler must be enabled before heap profiles can be collected.

Constructor

new Profiler()

Methods

(async) collectProfile()

Waits for profiler server to tell it to collect a profile, then collects a profile and uploads it.

Returns:
Type Description

time, in ms, to wait before asking profiler server again about collecting another profile.

(async) createProfile()

Talks to profiler server, which hangs until server indicates job should be profiled and then indicates what type of profile should be collected.

If any problem is encountered, an error will be thrown.

Returns:
Type Description

a RequestProfile specifying which type of profile should be collected and other information needed to collect and upload a profile of the specified type.

TODO (issue #28): right now, this call could hang for up to an hour when this method is the only thing on the event loop, keeping the program open even when all work is done. Should expose the ability to cancel the http request made here, and then determine when to cancel this request.

Public to allow for testing.

(async) profile()

Collects a profile of the type specified by profileType field of prof. If any problem is encountered, for example the profileType is not recognized or profiling is disabled for the specified profileType, an error will be thrown.

Public to allow for testing.

(async) profileAndUpload()

Collects a profile of the type specified by the profileType field of prof. If any problem is encountered, like a problem collecting or uploading the profile, a message will be logged, and the error will otherwise be ignored.

Public to allow for testing.

(async) runLoop()

Endlessly polls the profiler server for instructions, and collects and uploads profiles as requested.

(async) start()

Starts an endless loop to poll profiler server for instructions, and collects and uploads profiles as requested. If there is a problem when collecting a profile or uploading a profile to profiler server, this problem will be logged at the error level and otherwise ignored. If there is a problem polling profiler server for instructions on the type of profile to be collected, this problem will be logged at the error level and getting profile type will be retried.

(async) writeHeapProfile()

Collects a heap profile, converts profile to compressed, base64 encoded string, and adds profileBytes field to prof with this string.

Public to allow for testing.

(async) writeTimeProfile()

Collects a time profile, converts profile to compressed, base64 encoded string, and puts this string in profileBytes field of prof.

Public to allow for testing.