Profiler API¶
Overview¶
MXNet has a built-in profiler which is compatibule with both Intel® VTune™ Amplifier as well as Chrome’s chrome://tracing visualization engine. When built witht he USE_VTUNE=1 flag, MXNet makes actual VTune API calls to define Domains, Frames, Tasks, Events Counters, and Markers. For a detailed explanation of these, see Instrumentation and Tracing Technology API Reference
mxnet.profiler |
Profiler setting methods. |
API Reference¶
Profiling system control¶
profiler.set_config |
Set up the configure of profiler (only accepts keyword arguments). |
profiler.set_state |
Set up the profiler state to ‘run’ or ‘stop’. |
profiler.pause |
Pause profiling. |
profiler.resume |
Resume paused profiling. |
profiler.dump |
Dump profile and stop profiler. |
profiler.dumps |
Return a printable string of aggregate profile stats. |
Profiling Objects¶
These profiling objects can be created and accessed from python in order to resord performance information of the python code paths
profiler.Domain |
Profiling domain, used to group sub-objects like tasks, counters, etc into categories |
profiler.Task |
Profiling Task class. |
profiler.Frame |
Profiling Frame class. |
profiler.Event |
Profiling Event class. |
profiler.Counter |
Profiling Counter class. |
profiler.Marker |
Set marker for an instant in time. |
Example usage¶
profiler.set_config(profile_all=True,
filename='chrome_tracing_profile.json', # File used for chrome://tracing visualization
continuous_dump=True,
aggregate_stats=True) # Stats printed by dumps() call
profiler.set_state('run') # Start profiling engine
#
# Profile this section of code
#
profiler.pause() # Pause profiling
#
# Don't profile this section
#
profiler.resume() # Resume profiling
#
# Profile this section of code
#
profiler.set_state('stop') # Stop profiling engine (optional)
print(profiler.dumps()) # Print aggregate statistics if aggregate_stats was set to True
API Reference¶
Profiler setting methods.
-
mxnet.profiler.
set_config
(**kwargs)[source]¶ Set up the configure of profiler (only accepts keyword arguments).
Parameters: - filename (string,) – output file for profile data
- profile_all (boolean,) – all profile types enabled
- profile_symbolic (boolean,) – whether to profile symbolic operators
- profile_imperative (boolean,) – whether to profile imperative operators
- profile_memory (boolean,) – whether to profile memory usage
- profile_api (boolean,) – whether to profile the C API
- contiguous_dump (boolean,) – whether to periodically dump profiling data to file
- dump_period (float,) – seconds between profile data dumps
- aggregate_stats (boolean,) – whether to maintain aggregate stats in memory for console dump. Has some negative performance impact.
- profile_process (string) – whether to profile kvstore server or worker. server can only be profiled when kvstore is of type dist. if this is not passed, defaults to worker
-
mxnet.profiler.
profiler_set_config
(mode='symbolic', filename='profile.json')[source]¶ Set up the configure of profiler (Deprecated).
Parameters: - mode (string, optional) – Indicates whether to enable the profiler, can be ‘symbolic’, or ‘all’. Defaults to symbolic.
- filename (string, optional) – The name of output trace file. Defaults to ‘profile.json’.
-
mxnet.profiler.
set_state
(state='stop', profile_process='worker')[source]¶ Set up the profiler state to ‘run’ or ‘stop’.
Parameters: - state (string, optional) – Indicates whether to run the profiler, can be ‘stop’ or ‘run’. Default is stop.
- profile_process (string) – whether to profile kvstore server or worker. server can only be profiled when kvstore is of type dist. if this is not passed, defaults to worker
-
mxnet.profiler.
profiler_set_state
(state='stop')[source]¶ Set up the profiler state to ‘run’ or ‘stop’ (Deprecated).
Parameters: state (string, optional) – Indicates whether to run the profiler, can be ‘stop’ or ‘run’. Default is stop.
-
mxnet.profiler.
dump
(finished=True, profile_process='worker')[source]¶ Dump profile and stop profiler. Use this to save profile in advance in case your program cannot exit normally.
Parameters: - finished (boolean) – Indicates whether to stop statistic output (dumping) after this dump. Default is True
- profile_process (string) – whether to profile kvstore server or worker. server can only be profiled when kvstore is of type dist. if this is not passed, defaults to worker
-
mxnet.profiler.
dump_profile
()[source]¶ Dump profile and stop profiler. Use this to save profile in advance in case your program cannot exit normally.
-
mxnet.profiler.
dumps
(reset=False)[source]¶ Return a printable string of aggregate profile stats.
Parameters: reset (boolean) – Indicates whether to clean aggeregate statistical data collected up to this point
-
mxnet.profiler.
pause
(profile_process='worker')[source]¶ Pause profiling.
Parameters: profile_process (string) – whether to profile kvstore server or worker. server can only be profiled when kvstore is of type dist. if this is not passed, defaults to worker
-
mxnet.profiler.
resume
(profile_process='worker')[source]¶ Resume paused profiling.
Parameters: profile_process (string) – whether to profile kvstore server or worker. server can only be profiled when kvstore is of type dist. if this is not passed, defaults to worker
-
class
mxnet.profiler.
Domain
(name)[source]¶ Profiling domain, used to group sub-objects like tasks, counters, etc into categories Serves as part of ‘categories’ for chrome://tracing
Note: Domain handles are never destroyed.
Parameters: name (string) – Name of the domain -
new_task
(name)[source]¶ Create new Task object owned by this domain
Parameters: name (string) – Name of the task
-
new_frame
(name)[source]¶ Create new Frame object owned by this domain
Parameters: name (string) – Name of the frame
-
-
class
mxnet.profiler.
Task
(domain, name)[source]¶ Profiling Task class.
A task is a logical unit of work performed by a particular thread. Tasks can nest; thus, tasks typically correspond to functions, scopes, or a case block in a switch statement. You can use the Task API to assign tasks to threads.
This is different from Frame in that all profiling statistics for passes through the task’s begin and endpoints are accumulated together into a single statistical analysys, rather than a separate analysis for each pass (as with a Frame)
Parameters: - domain (Domain object) – Domain to which this object belongs
- name (string) – Name of the task
-
class
mxnet.profiler.
Frame
(domain, name)[source]¶ Profiling Frame class.
Use the frame API to insert calls to the desired places in your code and analyze performance per frame, where frame is the time period between frame begin and end points. When frames are displayed in Intel VTune Amplifier, they are displayed in a separate track, so they provide a way to visually separate this data from normal task data.
This is different from Task in that each ‘Frame’ duration will be a discretely-numbered event in the VTune output, as well as its rate (frame-rate) shown. This is analogous to profiling each frame of some visual output, such as rendering a video game frame.
Parameters: - domain (Domain object) – Domain to which this object belongs
- name (string) – Name of the frame
-
class
mxnet.profiler.
Event
(name)[source]¶ Profiling Event class.
The event API is used to observe when demarcated events occur in your application, or to identify how long it takes to execute demarcated regions of code. Set annotations in the application to demarcate areas where events of interest occur. After running analysis, you can see the events marked in the Timeline pane. Event API is a per-thread function that works in resumed state. This function does not work in paused state.
Parameters: name (string) – Name of the event
-
class
mxnet.profiler.
Counter
(domain, name, value=None)[source]¶ Profiling Counter class.
The counter event can track a value as it changes over time.
Parameters: - domain (Domain object) – Domain to which this object belongs
- name (string) – Name of the counter
- value (integer, optional) – Initial value of the counter