// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: September 26, 2011 // // Procedure Name: // melProfilerWindow() // // Description: // Brings up the MEL Profiler UI to enable profiling of MEL Procs // in Maya. // // Input Value: // None // // Output Value: // None // global proc resetData (string $melProcSheet) { // start the profiling process, tell the user we've started melProcSpreadsheet -e -resetData $melProcSheet; } global proc stopProfiling (string $melProcSheet) { // start the profiling process, tell the user we've started melProcSpreadsheet -e -removeProfiler $melProcSheet; } global proc startProfiling (string $melProcSheet) { // start the profiling process, tell the user we've started melProcSpreadsheet -e -installProfiler $melProcSheet; } global proc profileProc (string $melProcSheet) { // profile a particular procedure // first, get the procedure name (the way the user would want it run) string $procToProfile; string $result = `promptDialog -title (uiRes("m_melProfilerWindow.kMPProfileProcWindowTitle")) -message (uiRes("m_melProfilerWindow.kMPProfileProcProcName")) -button (uiRes("m_melProfilerWindow.kMPProfileProcProfileButtonLabel")) -button (uiRes("m_melProfilerWindow.kMPProfileProcCancelButtonLabel")) -defaultButton (uiRes("m_melProfilerWindow.kMPProfileProcDefaultButton")) -cancelButton (uiRes("m_melProfilerWindow.kMPProfileProcCancelButton")) -dismissString (uiRes("m_melProfilerWindow.kMPProfileProcDismissString"))`; if ($result == "Profile") { $procToProfile = `promptDialog -query -text`; // profile this proc int $stringLength = `size($procToProfile)`; if ($stringLength) { // profile the proc startProfiling($melProcSheet); eval($procToProfile); stopProfiling($melProcSheet); } } } global proc profileScriptFile(string $melScriptFile, string $melProcSheet) { // profiles a MEL Script file // note that the file needs to have // the proc call in it as well, otherwise // this is just a source operation if (size($melScriptFile) > 0) { string $cmd = "source " + "\"" + $melScriptFile + "\""; // profile the script file startProfiling($melProcSheet); eval($cmd); stopProfiling($melProcSheet); } } global proc profileScriptFileHelper(string $melProcSheet) { // browse to a MEL Script file that we can profile later string $fileFilter = (uiRes("m_melProfilerWindow.kMelScriptFiles")) + " (*.mel) (*.mel)"; string $userChoice[] = `fileDialog2 -fileMode 1 -fileFilter $fileFilter -caption (uiRes("m_melProfilerWindow.kSourceAMelScriptFile")) -okCaption (uiRes("m_melProfilerWindow.kSource"))`; if( size($userChoice) > 0 && $userChoice[0] != "" ) { string $file = fromNativePath($userChoice[0]); profileScriptFile($file, $melProcSheet); } } global proc writeProfileData (string $fileName, string $melProcSheet) { // write the data to disk if (size($fileName)) { melProcSpreadsheet -e -dumpToFile $fileName $melProcSheet; } } global proc saveSpreadsheetDataWindow(string $melProcSheet) { // the user wants to save the sheet // so pop up a file dialog and get the filename they want string $fileFilter = (uiRes("m_melProfilerWindow.kCommaSeparated")) + " (*.csv) (*.csv)"; string $fileName[] = `fileDialog2 -fileMode 0 -fileFilter $fileFilter -caption (uiRes("m_melProfilerWindow.kSaveProfileData"))`; if (size($fileName)) { // grab the file name and write the data out writeProfileData($fileName[0], $melProcSheet); } } global proc writeCallGraphData (string $fileName, string $melProcSheet) { // write the data to disk if (size($fileName)) { melProcSpreadsheet -e -dumpDotFile $fileName $melProcSheet; } } global proc saveCallGraphWindow(string $melProcSheet) { // the user wants to save the call graph data string $fileFilter = (uiRes("m_melProfilerWindow.kDotGraphFormat")) + " (*.dot) (*.dot)"; string $fileName[] = `fileDialog2 -fileMode 0 -fileFilter $fileFilter -caption (uiRes("m_melProfilerWindow.kSaveCallGraphData"))`; if (size($fileName)) { // grab the file name and write the data out writeCallGraphData($fileName[0], $melProcSheet); } } global proc melProfilerWindow() { string $MPWindowTitle = (uiRes("m_melProfilerWindow.kMPWindowTitle")); string $window = `window -width 1182 -height 374 -menuBar true -title $MPWindowTitle`; string $menuBarLayout = `menuBarLayout`; menu -label (uiRes("m_melProfilerWindow.kMPProfilingMain")); menuItem -label (uiRes("m_melProfilerWindow.kMPStartProfiling")) startProfilingMI; menuItem -label (uiRes("m_melProfilerWindow.kMPStopProfiling")) stopProfilingMI; menuItem -label (uiRes("m_melProfilerWindow.kMPProfileProc")) profileProcMI; menuItem -label (uiRes("m_melProfilerWindow.kMPProfileScriptFile")) profileScriptFileMI; menuItem -label (uiRes("m_melProfilerWindow.kMPSaveProfileData")) saveProfilingDataMI; menuItem -label (uiRes("m_melProfilerWindow.kMPSaveCGData")) saveCallGraphDataMI; menuItem -label (uiRes("m_melProfilerWindow.kMPResetData")) resetDataMI; setParent ..; string $form = `formLayout -numberOfDivisions 100`; string $melProcSheet = `melProcSpreadsheet`; // add the commands for the menu item here menuItem -e -command ("startProfiling " + $melProcSheet) startProfilingMI; menuItem -e -command ("stopProfiling " + $melProcSheet) stopProfilingMI; menuItem -e -command ("profileProc " + $melProcSheet) profileProcMI; menuItem -e -command ("profileScriptFileHelper " + $melProcSheet) profileScriptFileMI; menuItem -e -command ("saveSpreadsheetDataWindow " + $melProcSheet) saveProfilingDataMI; menuItem -e -command ("saveCallGraphWindow " + $melProcSheet) saveCallGraphDataMI; menuItem -e -command ("resetData " + $melProcSheet) resetDataMI; formLayout -edit -attachForm $melProcSheet "top" 0 -attachForm $melProcSheet "left" 5 -attachForm $melProcSheet "bottom" 5 -attachForm $melProcSheet "right" 5 $form; showWindow $window; }