Measure operations duration

This commit is contained in:
Romain Quetiez
2025-07-04 14:29:27 +02:00
parent 57d610fc16
commit f8ae1fd2d8
4 changed files with 28 additions and 2 deletions

View File

@@ -864,6 +864,7 @@ class DisplayableGraph extends SimpleGraph
*/
public static function FromRelationGraph(RelationGraph $oGraph, $iGroupingThreshold = 20, $bDirectionDown = true, $bForPdf = false)
{
$oKPI = new ExecutionKPI();
$oNewGraph = new DisplayableGraph();
$oNewGraph->bDirectionDown = $bDirectionDown;
$iPreviousTimeLimit = ini_get('max_execution_time');
@@ -1017,6 +1018,7 @@ class DisplayableGraph extends SimpleGraph
}
set_time_limit(intval($iPreviousTimeLimit));
$oKPI->ComputeStats('FromRelationGraph', '');
return $oNewGraph;
}
@@ -1027,6 +1029,7 @@ class DisplayableGraph extends SimpleGraph
*/
public function InitFromGraphviz()
{
$oKPI = new ExecutionKPI();
$sDot = $this->DumpAsXDot();
if (strpos($sDot, 'digraph') === false)
{
@@ -1054,6 +1057,7 @@ class DisplayableGraph extends SimpleGraph
}
}
}
$oKPI->ComputeStats('InitFromGraphviz', '');
}
public function GetBoundingBox()

View File

@@ -283,6 +283,8 @@ class RelationGraph extends SimpleGraph
*/
public function IsPartOfContext(DBObject $oObj, &$aRootCauses)
{
$oKPI = new ExecutionKPI();
$bRet = false;
$sFinalClass = get_class($oObj);
$aParentClasses = MetaModel::EnumParentClasses($sFinalClass, ENUM_PARENT_CLASSES_ALL);
@@ -313,6 +315,7 @@ class RelationGraph extends SimpleGraph
}
}
}
$oKPI->ComputeStats(__METHOD__, get_class($oObj));
return $bRet;
}
@@ -329,6 +332,7 @@ class RelationGraph extends SimpleGraph
*/
public function ComputeRelatedObjectsDown($sRelCode, $iMaxDepth, $bEnableRedundancy, $aUnreachableObjects = array())
{
$oKPI = new ExecutionKPI();
//echo "<h5>Sources only...</h5>\n".$this->DumpAsHtmlImage()."<br/>\n";
// Build the graph out of the sources
foreach ($this->aSourceNodes as $oSourceNode)
@@ -336,8 +340,10 @@ class RelationGraph extends SimpleGraph
$this->AddRelatedObjects($sRelCode, true, $oSourceNode, $iMaxDepth, $bEnableRedundancy);
//echo "<h5>After processing of {$oSourceNode->GetId()}</h5>\n".$this->DumpAsHtmlImage()."<br/>\n";
}
$oKPI->ComputeAndReport(__FUNCTION__.' - AddRelatedObjects');
// Mark the unreachable nodes
$oKPI = new ExecutionKPI();
foreach ($aUnreachableObjects as $oObj)
{
$sNodeId = RelationObjectNode::MakeId($oObj);
@@ -347,14 +353,18 @@ class RelationGraph extends SimpleGraph
$oNode->SetProperty('is_reached_allowed', false);
}
}
$oKPI->ComputeAndReport(__FUNCTION__.' - Mark unreachable nodes');
// Determine the reached nodes
$oKPI = new ExecutionKPI();
foreach ($this->aSourceNodes as $oSourceNode)
{
$oSourceNode->ReachDown('is_reached', true);
//echo "<h5>After reaching from {$oSourceNode->GetId()}</h5>\n".$this->DumpAsHtmlImage()."<br/>\n";
}
$oKPI->ComputeAndReport(__FUNCTION__.' - Determine reached nodes');
$oKPI = new ExecutionKPI();
// Mark also the "context" nodes as reached and record the "root causes" for each node
$oIterator = new RelationTypeIterator($this, 'Node');
foreach($oIterator as $oNode)
@@ -367,9 +377,13 @@ class RelationGraph extends SimpleGraph
$oNode->ReachDown('is_reached', true);
}
}
$oKPI->ComputeAndReport(__FUNCTION__.' - Mark context nodes as reached');
$oKPI = new ExecutionKPI();
if ( MetaModel::GetConfig()->Get('relations.complete_analysis')) {
$this->ApplyUserRightsOnGraph();
}
$oKPI->ComputeAndReport(__FUNCTION__.' - Apply user rights on graph');
}
/**
@@ -384,6 +398,7 @@ class RelationGraph extends SimpleGraph
*/
public function ComputeRelatedObjectsUp($sRelCode, $iMaxDepth, $bEnableRedundancy)
{
$oKPI = new ExecutionKPI();
//echo "<h5>Sinks only...</h5>\n".$this->DumpAsHtmlImage()."<br/>\n";
// Build the graph out of the sinks
foreach ($this->aSinkNodes as $oSinkNode)
@@ -407,6 +422,7 @@ class RelationGraph extends SimpleGraph
if ( MetaModel::GetConfig()->Get('relations.complete_analysis')) {
$this->ApplyUserRightsOnGraph();
}
$oKPI->ComputeStats('GetRelatedObjects-Up', '');
}

View File

@@ -517,8 +517,10 @@ EOF
@fclose($rFile);
$aOutput = array();
$CommandLine = "\"$sDotExecutable\" -v -Tpng < \"$sDotFilePath\" -o\"$sImageFilePath\" 2>&1";
$oKPI = new ExecutionKPI();
exec($CommandLine, $aOutput, $iRetCode);
$oKPI->ComputeStats('Graphviz execution png', 'png');
if ($iRetCode != 0)
{
$sHtml = '';
@@ -573,8 +575,10 @@ EOF
@fclose($rFile);
$aOutput = array();
$CommandLine = "\"$sDotExecutable\" -v -Tdot < \"$sDotFilePath\" -o\"$sXdotFilePath\" 2>&1";
$oKPI = new ExecutionKPI();
exec($CommandLine, $aOutput, $iRetCode);
$oKPI->ComputeStats('Graphviz execution dot', 'dot');
if ($iRetCode != 0)
{
$sHtml = '';

View File

@@ -1862,6 +1862,7 @@ EOF
}
// Remove excluded classes from the graph
$oKPI = new ExecutionKPI();
if (count($aExcludedClasses) > 0) {
$oIterator = new RelationTypeIterator($oRelGraph, 'Node');
foreach ($oIterator as $oNode) {
@@ -1871,6 +1872,7 @@ EOF
}
}
}
$oKPI->ComputeAndReport('Filtering nodes');
$oGraph = DisplayableGraph::FromRelationGraph($oRelGraph, $iGroupingThreshold, ($sDirection == 'down'));
$oGraph->InitFromGraphviz();