// =========================================================================== // 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. // =========================================================================== global proc profile (string $dgProfileSheet) { dgTimerSpreadsheet -e -ip $dgProfileSheet; // play the timeline once string $oldPlayBackOption = `playbackOptions -q -loop`; playbackOptions -e -loop "once"; currentTime -edit `playbackOptions -query -min`; // loop through the timeline int $minFrame = `playbackOptions -query -min`; int $maxFrame = `playbackOptions -query -max`; int $i = $minFrame; int $j = 0; int $numIterations = `intField -q -value numRunsTextField`; for ($j = 0; $j < $numIterations; $j++) { for ($i = $minFrame; $i < $maxFrame; $i++) { currentTime -edit $i; } currentTime -edit $minFrame; } playbackOptions -e -loop $oldPlayBackOption; dgTimerSpreadsheet -e -rp $dgProfileSheet; } global proc resetDGTable(string $dgProfileSheet) { // reset the data dgTimerSpreadsheet -e -rd $dgProfileSheet; } global proc writeProfileData (string $fileName, string $melProcSheet) { // write the data to disk if (size($fileName)) { dgTimerSpreadsheet -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_dgProfiler.kCommaSeparated")) + " (*.csv) (*.csv)"; string $fileName[] = `fileDialog2 -fileMode 0 -fileFilter $fileFilter -caption (uiRes("m_dgProfiler.kSaveProfileData"))`; if (size($fileName)) { // grab the file name and write the data out writeProfileData($fileName[0], $melProcSheet); } } global proc graphSelectedNode(string $dgProfileSheet) { // grab the selected node // from the table string $nodeName = `dgTimerSpreadsheet -q -csn $dgProfileSheet`; // and graph it select -r $nodeName; HypergraphDGWindow; } global proc filterGraphTable(int $enable, string $dgProfileSheet) { // grab the selected node type name // get the table to filter by that type string $nodeTypeFilter = ""; if ($enable) { $nodeTypeFilter = `textField -q -text filterTypeField`; } dgTimerSpreadsheet -e -filterNodeEnable $enable $dgProfileSheet; dgTimerSpreadsheet -e -filterNodeType $nodeTypeFilter $dgProfileSheet; } global proc highlightGraphTable(int $enable, string $dgProfileSheet) { float $percentage = `floatField -q -value highlightPercentageField`; if ($enable) { if ($percentage < 0) { $percentage = 0; } } else { $percentage = 0; } dgTimerSpreadsheet -e -highlightPercentageEnable $enable $dgProfileSheet; dgTimerSpreadsheet -e -highlightPercentage $percentage $dgProfileSheet; } global proc setNodeTypeFilter(string $dgProfileSheet) { string $nodeTypeFilter = `textField -q -text filterTypeField`; dgTimerSpreadsheet -e -filterNodeType $nodeTypeFilter $dgProfileSheet; } global proc setHighlightPercentage(string $dgProfileSheet) { float $percentage = `floatField -q -value highlightPercentageField`; if ($percentage < 0) { $percentage = 0; } dgTimerSpreadsheet -e -highlightPercentage $percentage $dgProfileSheet; } global proc dgProfiler() { string $DGPWindowTitle = (uiRes("m_dgProfiler.kDGPWindowTitle")); string $window = `window -width 1182 -height 600 -menuBar true -title $DGPWindowTitle`; string $menuBarLayout = `menuBarLayout`; menu -label (uiRes("m_dgProfiler.kDGPWindowProfilingMain")); menuItem -label (uiRes("m_dgProfiler.kDGPWindowProfileMenu")) startProfilingMI; menuItem -label (uiRes("m_dgProfiler.kDGPWindowFilterNodes")) filterNodesMI; menuItem -label (uiRes("m_dgProfiler.kDGPWindowGraph")) graphSelectedNodeMI; menuItem -label (uiRes("m_dgProfiler.kDGPWindowSaveProfile")) saveProfilingDataMI; menuItem -label (uiRes("m_dgProfiler.kDGPWindowReset")) resetDataMI; setParent ..; // the pane sizes are in percentages, we only want to alter the lower one paneLayout -configuration "horizontal2" -paneSize 2 100 10; string $profiler = `dgTimerSpreadsheet`; string $form = `formLayout -numberOfDivisions 100`; string $filterButton = `checkBox -label (uiRes("m_dgProfiler.kDGPWindowEnableFilter")) -onCommand ("filterGraphTable 1 " + $profiler) -offCommand ("filterGraphTable 0 " + $profiler)`; string $filterText = `text -label (uiRes("m_dgProfiler.kDGPWindowFilterLabel"))`; string $filterTypeTextField = `textField -width 400 -changeCommand ("setNodeTypeFilter " + $profiler) filterTypeField`; string $highlightButton = `checkBox -label (uiRes("m_dgProfiler.kDGPWindowHighlightEnable")) -onCommand ("highlightGraphTable 1 " + $profiler) -offCommand ("highlightGraphTable 0 " + $profiler)`; string $highlightText = `text -label (uiRes("m_dgProfiler.kDGPWindowHighlightLabel"))`; string $highlightTextField = `floatField -width 200 -changeCommand ("setHighlightPercentage " + $profiler) highlightPercentageField`; string $numRunsText = `text -label (uiRes("m_dgProfiler.kDGPWindowNumRunsLabel"))`; string $numRunsTextField = `intField -width 200 -value 1 -minValue 1 numRunsTextField`; string $profileButton = `button -width 200 -label (uiRes("m_dgProfiler.kDGPWindowProfileButton")) -command ("profile " + $profiler) startProfilingButton`; string $graphButton = `button -width 200 -label (uiRes("m_dgProfiler.kDGPWindowGraphButton")) -command ("graphSelectedNode " + $profiler) graphSelectedNodeButton`; string $resetButton = `button -width 200 -label (uiRes("m_dgProfiler.kDGPWindowResetButton")) -command ("resetDGTable " + $profiler) resetProfilingDataButton`; formLayout -edit // Filter list by node type -attachForm $filterText "top" 5 -attachForm $filterText "left" 5 -attachNone $filterText "bottom" -attachNone $filterText "right" -attachForm $filterTypeTextField "top" 5 -attachControl $filterTypeTextField "left" 5 $filterText -attachNone $filterTypeTextField "bottom" -attachNone $filterTypeTextField "right" -attachForm $filterButton "top" 5 -attachControl $filterButton "left" 5 $filterTypeTextField -attachNone $filterButton "bottom" -attachNone $filterButton "right" // Highlight nodes by %age of execution time -attachControl $highlightText "top" 15 $filterText -attachForm $highlightText "left" 5 -attachNone $highlightText "bottom" -attachNone $highlightText "right" -attachControl $highlightTextField "top" 5 $filterTypeTextField -attachControl $highlightTextField "left" 5 $highlightText -attachNone $highlightTextField "bottom" -attachNone $highlightTextField "right" -attachControl $highlightButton "top" 10 $filterButton -attachControl $highlightButton "left" 5 $highlightTextField -attachNone $highlightButton "bottom" -attachNone $highlightButton "right" // number of runs -attachControl $numRunsText "top" 5 $highlightTextField -attachForm $numRunsText "left" 5 -attachNone $numRunsText "bottom" -attachNone $numRunsText "right" -attachControl $numRunsTextField "top" 5 $highlightTextField -attachControl $numRunsTextField "left" 5 $numRunsText -attachNone $numRunsTextField "bottom" -attachNone $numRunsTextField "right" // Profile! -attachControl $profileButton "top" 10 $numRunsTextField -attachForm $profileButton "left" 5 -attachNone $profileButton "bottom" -attachNone $profileButton "right" // Graph Node -attachControl $graphButton "top" 10 $numRunsTextField -attachControl $graphButton "left" 5 $profileButton -attachNone $graphButton "bottom" -attachNone $graphButton "right" // Reset Data -attachControl $resetButton "top" 10 $numRunsTextField -attachControl $resetButton "left" 5 $graphButton -attachNone $resetButton "bottom" -attachNone $resetButton "right" $form; showWindow; // add the commands for the menu item here menuItem -e -command ("profile " + $profiler) startProfilingMI; menuItem -e -command ("filterGraphTable 1 " + $profiler) filterNodesMI; menuItem -e -command ("graphSelectedNode " + $profiler) graphSelectedNodeMI; menuItem -e -command ("saveSpreadsheetDataWindow " + $profiler) saveProfilingDataMI; menuItem -e -command ("resetDGTable " + $profiler) resetDataMI; }