可以使用 MEL/Python 在“分析器”(Profiler)中开始/停止录制,以及检测过程以用于分析。检测是对程序的修改,用于收集信息进行分析。
使用 profiler 命令 -sampling (-s) 标志启用和禁用事件录制;如下所示:
profiler -s true; polyCube; profiler -s false;
若要添加分析类别,请使用 -addCategory 标志;如下所示:
int $melCategoryIndex = `profiler -addCategory "MEL Scripts"`;
定义 MEL 过程,然后使用 -instrumentMel 标志检测此过程。以下示例演示了如何启用称为 Factorial 的过程的检测。
profiler -instrumentMel true -procedureName "Factorial" -categoryIndex $melCategoryIndex -colorIndex 8 -procedureDescription "FactorialDesc" ;
您可以禁用一个或多个过程的检测。若要禁用特定过程,请将 -instrumentMel 设置为 False,并提供要禁用检测的过程的名称:
profiler -instrumentMel false -procedureName "Factorial" -categoryIndex $melCategoryIndex;
若要同时禁用所有检测,请使用 -clearAllMelInstrumentation 标志:
profiler -clearAllMelInstrumentation;
有关上文提到的标志以及其他有用标志(例如:-eventCount,用于查询缓冲区中的事件计数;或 -reset,用于重置“分析器”(Profiler)的数据)的详细信息,请参见 profiler MEL 命令文档。
有关如何与“分析器”(Profiler)的主视图交互的信息,请参见 profilerTool MEL 命令文档。例如,可以在“CPU 视图”(CPU view)和“类别视图”(Category view)之间切换;或框显选定事件。
若要启用和禁用事件录制,请将采样分别设置为 True 和 False,如下所示:
cmds.profiler(sampling = True) cmds.polyCube() cmds.profiler(sampling = False)
若要添加分析类别,请调用 OpenMaya.MProfiler.addCategory(),如下所示:
categoryIndex = OpenMaya.MProfiler.addCategory("Python Scripts")
若要检测过程,请在过程定义中调用 OpenMaya.MProfilingScope();如下所示:
def Factorial(number): # Instrument this procedure profiler = OpenMaya.MProfilingScope(categoryIndex, OpenMaya.MProfiler.kColorE_L1, "Factorial", "FactorialDesc") result = 1 for i in range(1, number+1): result = result * i return result
有关上文提到的标志以及其他有用标志(例如:eventCount,用于查询缓冲区中的事件计数;或 reset,用于重置“分析器”(Profiler)的数据)的详细信息,请参见 profiler Python 命令文档。Python 可以使用 -instrumentMel 标志来检测 MEL 过程。
有关如何与“分析器”(Profiler)的主视图交互的信息,请参见 profilerTool Python 命令文档。例如,可以在“CPU 视图”(CPU view)和“类别视图”(Category view)之间切换;或框显选定事件。
可以在插件中调用 MProfiler::addCategory() 方法,向“分析器”(Profiler)中添加类别。调用 MProfilingScope::MProfilingScope() 以检测要分析的函数。详细信息请参见 MProfiler 和 MProfilingScope C++ API 参考文档,以及 Maya 开发人员帮助中的 Autodesk Maya 2015 Extension 新特性。