pymel.core.system.profiler

profiler(*args, **kwargs)

The profiler is used to record timing information from key events within Maya, as an aid in tuning the performance of scenes, scripts and plug-ins. User written plug-ins and Python scripts can also generate profiling information for their own code through the MProfilingScope (C++), MProfilingContextManager (Python) and MProfiler classes in the API. This command provides the ability to control the collection of profiling data and to query information about the recorded events. The recorded information can also be viewed graphically in the Profiler window. The buffer size cannot be changed while sampling is active, it will return an error The reset flag cannot be called while sampling is active, it will return an error. Any changes to the buffer size will only be applied on start of the next recording. You can’t save and load in the same command, save has priority, load would be ignored. In query mode, return type is based on queried flag.

Flags:

Long Name / Short Name Argument Types Properties
addCategory / a unicode ../../../_images/create.gif
  Add a new category for the profiler. Returns the index of the new category.
allCategories / ac bool ../../../_images/query.gif
  Query the names of all categories
bufferSize / b int ../../../_images/create.gif ../../../_images/query.gif
  Toggled : change the buffer size to fit the specified number of events (requires that sampling is off) Query : return the current buffer size The new buffer size will only take effect when next sampling starts. When the buffer is full, the recording stops.
categoryIndex / ci int ../../../_images/create.gif ../../../_images/query.gif
  Used in conjunction with other flags, to indicate the index of the category.
categoryIndexToName / cin int ../../../_images/create.gif ../../../_images/query.gif
  Returns the name of the category with a given index.
categoryName / cn unicode ../../../_images/query.gif
  Used in conjunction with other flags, to indicate the name of the category.
categoryNameToIndex / cni unicode ../../../_images/create.gif ../../../_images/query.gif
  Returns the index of the category with a given name.
categoryRecording / cr bool ../../../_images/create.gif ../../../_images/query.gif
  Toggled : Enable/disable the recording of the category. Query : return if the recording of the category is On. Requires the -categoryIndex or -categoryName flag to specify the category to be queried.
clearAllMelInstrumentation / cam bool ../../../_images/create.gif
  Clear all MEL command or procedure instrumentation.
colorIndex / coi int ../../../_images/create.gif
  Used with -instrumentMel trueto specify the color index to show the profiling result.
eventCPUId / eci bool ../../../_images/query.gif
  Query the CPU ID of the event at the given index. Requires the -eventIndex flag to specify the event to be queried.
eventCategory / eca bool ../../../_images/query.gif
  Query the category index the event at the given index belongs to. Requires the -eventIndex flag to specify the event to be queried.
eventColor / eco bool ../../../_images/query.gif
  Query the color of the event at the given index. Requires the -eventIndex flag to specify the event to be queried.
eventCount / ec bool ../../../_images/query.gif
  Query the number of events in the buffer
eventDescription / ed bool ../../../_images/query.gif
  Query the description of the event at the given index. Requires the -eventIndex flag to specify the event to be queried.
eventDuration / edu bool ../../../_images/query.gif
  Query the duration of the event at the given index, the time unit is microsecond. Note that a signal event has a 0 duration. Requires the -eventIndex flag to specify the event to be queried.
eventIndex / ei int ../../../_images/query.gif
  Used usually in conjunction with other flags, to indicate the index of the event.
eventName / en bool ../../../_images/query.gif
  Query the name of the event at the given index. Requires the -eventIndex flag to specify the event to be queried.
eventStartTime / et bool ../../../_images/query.gif
  Query the time of the event at the given index, the time unit is microsecond. Requires the -eventIndex flag to specify the event to be queried.
eventThreadId / eti bool ../../../_images/query.gif
  Query the thread ID of the event at the given index. Requires the -eventIndex flag to specify the event to be queried.
instrumentMel / instrumentMel bool ../../../_images/create.gif
  Enable/Diable the instrumentation of a MEL command or procedure. When the instrumentation is enabled, the execution of MEL command or procedure can be profiled and shown in the Profiler window. To enable the instrumentation requires the -procedureName, -colorIndex and -categoryIndex flags. To disable the instrumentation requires the -procedureName flag.
load / l unicode ../../../_images/create.gif ../../../_images/query.gif
  Read the recorded events from the specified file
output / o unicode ../../../_images/create.gif ../../../_images/query.gif
  Output the recorded events to the specified file
procedureDescription / pd unicode ../../../_images/create.gif
  Used with -instrumentMel trueto provide a description of the MEL command or procedure being instrumented. This description can be viewed in the Profiler Tool window.
procedureName / pn unicode ../../../_images/create.gif
  Used with -instrumentMel to specify the name of the procedure to be enabled/disabled the instrumentation.
removeCategory / rc unicode ../../../_images/create.gif
  Remove an existing category for the profiler. Returns the index of the removed category.
reset / r bool ../../../_images/create.gif ../../../_images/query.gif
  reset the profiler’s data (requires that sampling is off)
sampling / s bool ../../../_images/create.gif ../../../_images/query.gif
  Toggled : Enable/disable the recording of events Query : return if the recording of events is On.
signalEvent / sig bool ../../../_images/query.gif
  Query if the event at the given index is a signal event. Requires the -eventIndex flag to specify the event to be queried. A Signal Event only remembers the start moment and has no knowledge about duration. It can be used in cases when the user does not care about the duration but only cares if this event does happen.
signalMelEvent / sim bool ../../../_images/create.gif
  Used with -instrumentMel true, inform profiler that this instrumented MEL command or procedure will be taken as a signal event during profiling. A Signal Event only remembers the start moment and has no knowledge about duration. It can be used in cases when the user does not care about the duration but only cares if this event does happen. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.profiler

Example:

::

import pymel.core as pm

# Start profiling pm.profiler(sampling = True)

# Wait for events to be profiled # Stop profiling pm.profiler(sampling = False)

# Output the result to a file pm.profiler(output = “test.txt”)

# Load a recording from a file to the buffer pm.profiler(load = “test.txt”)

# Reset the tool pm.profiler(reset = True)

# Set the profiler’s buffer size to fit 5 megaBytes pm.profiler(bufferSize = 5)

# Query the profiler’s buffer size pm.profiler(query = True, bufferSize = True) # Result: 20 #

# Add a new category pm.profiler(addCategory = “Test Category”) # Result: 11 #

# Remove an existing category pm.profiler(removeCategory = “Test Category”) # Result: 11 #

# Query the number of categories pm.profiler(query = True, categoryCount = True)

# Query the name of the category at the given index pm.profiler(query = True, categoryIndexToName = 5)

# Query the index of the category with the given name pm.profiler(query = True, categoryNameToIndex = “Maya Qt”)

# Query if it is enabled for the recording of the category at the given index pm.profiler(query = True, categoryRecording = True, categoryIndex = 5)

# Query if it is enabled for the recording of the category with the given name pm.profiler(query = True, categoryRecording = True, categoryName = “Maya Qt”)

# Enable/Disable the recording of the category at the given index pm.profiler(categoryRecording = False, categoryIndex = 5)

# Query the number of the events in the buffer pm.profiler(query = True, eventCount = True)

# Query the time at which the event at the given index start pm.profiler(query = True, eventStartTime = True, eventIndex = 100)

# Query the duration of the event at the given index pm.profiler(query = True, eventDuration = True, eventIndex = 100)

# Query the name of the event at the given index pm.profiler(query = True, eventName = True, eventIndex = 100)

# Query the description of the event at the given index pm.profiler(query = True, eventDescription = True, eventIndex = 100)

# Query the category the the event at the given index belongs to pm.profiler(query = True, eventCategory = True, eventIndex = 100)

# Query the color of the event at the given index pm.profiler(query = True, eventColor = True, eventIndex = 100)

# Query the thread ID of the event at the given index pm.profiler(query = True, eventThreadId = True, eventIndex = 100)

# Query the CPU ID of the event at the given index pm.profiler(query = True, eventCPUId = True, eventIndex = 100)

# Query if the event at the given index is a signal event pm.profiler(query = True, signalEvent = True, eventIndex = 100)