protected function ResetCounters()
 {
     if (self::$m_bEnabled_Duration) {
         $this->m_fStarted = MyHelpers::getmicrotime();
     }
     if (self::$m_bEnabled_Memory) {
         $this->m_iInitialMemory = self::memory_get_usage();
     }
 }
 public function Exec()
 {
     if ($this->sSql != '') {
         $iRepeat = utils::ReadParam('repeat', 3);
         try {
             $fRefTime = MyHelpers::getmicrotime();
             for ($i = 0; $i < $iRepeat; $i++) {
                 $resQuery = CMDBSource::Query($this->sSql);
             }
             $this->fExecDuration = (MyHelpers::getmicrotime() - $fRefTime) / $iRepeat;
             // This is not relevant...
             if (preg_match_all('|\\s*JOIN\\s*\\(\\s*`|', $this->sSql, $aMatches)) {
                 $this->iTableCount = 1 + count($aMatches[0]);
             } else {
                 $this->iTableCount = 1;
             }
         } catch (Exception $e) {
             $this->aErrors[] = "Failed to execute the SQL:" . $e->getMessage();
             $resQuery = null;
         }
         if ($resQuery) {
             while ($aRow = CMDBSource::FetchArray($resQuery)) {
                 $this->aRows[] = $aRow;
             }
             CMDBSource::FreeResult($resQuery);
         }
     }
 }
Exemple #3
0
 protected function CreateObject($sClass, $aData, $sClassDesc = '')
 {
     $mu_t1 = MyHelpers::getmicrotime();
     $oMyObject = MetaModel::NewObject($sClass);
     foreach ($aData as $sProp => $value) {
         if (is_array($value)) {
             // transform into a link set
             $sCSVSpec = implode('|', $value);
             $oAttDef = MetaModel::GetAttributeDef($sClass, $sProp);
             $value = $oAttDef->MakeValueFromString($sCSVSpec, $bLocalizedValue = false, $sSepItem = '|', $sSepAttribute = ';', $sSepValue = ':', $sAttributeQualifier = '"');
         }
         $oMyObject->Set($sProp, $value);
     }
     $iId = $oMyObject->DBInsertTrackedNoReload($this->m_oChange, true);
     $sClassId = "{$sClass} ({$sClassDesc})";
     $this->m_aCreatedByDesc[$sClassId][] = $iId;
     $this->m_aCreatedByClass[$sClass][] = $iId;
     $mu_t2 = MyHelpers::getmicrotime();
     $this->m_aStatsByClass[$sClass][] = $mu_t2 - $mu_t1;
     return $iId;
 }
 protected function DoBenchmark($sOqlQuery)
 {
     echo "<h5>Testing query: {$sOqlQuery}</h5>";
     $fStart = MyHelpers::getmicrotime();
     $oFilter = DBObjectSearch::FromOQL($sOqlQuery);
     $fParsingDuration = MyHelpers::getmicrotime() - $fStart;
     $fStart = MyHelpers::getmicrotime();
     $sSQL = $oFilter->MakeSelectQuery();
     $fBuildDuration = MyHelpers::getmicrotime() - $fStart;
     $fStart = MyHelpers::getmicrotime();
     $res = CMDBSource::Query($sSQL);
     $fQueryDuration = MyHelpers::getmicrotime() - $fStart;
     // The fetch could not be repeated with the same results
     // But we've seen so far that is was very very quick to exec
     // So it makes sense to benchmark it a single time
     $fStart = MyHelpers::getmicrotime();
     $aRow = CMDBSource::FetchArray($res);
     $fDuration = MyHelpers::getmicrotime() - $fStart;
     $fFetchDuration = $fDuration;
     $fStart = MyHelpers::getmicrotime();
     $sOql = $oFilter->ToOQL();
     $fToOqlDuration = MyHelpers::getmicrotime() - $fStart;
     if (false) {
         echo "<ul style=\"font-size:smaller;\">\n";
         echo "<li>Parsing: {$fParsingDuration}</li>\n";
         echo "<li>Build: {$fBuildDuration}</li>\n";
         echo "<li>Query: {$fQueryDuration}</li>\n";
         echo "<li>Fetch: {$fFetchDuration}</li>\n";
         echo "<li>ToOql: {$fToOqlDuration}</li>\n";
         echo "</ul>\n";
     }
     // Everything but the ToOQL (wich is interesting, anyhow)
     $fTotal = $fParsingDuration + $fBuildDuration + $fQueryDuration + $fFetchDuration;
     return array('rows' => CMDBSource::NbRows($res), 'duration (s)' => round($fTotal, 4), 'parsing (%)' => round(100 * $fParsingDuration / $fTotal, 1), 'build SQL (%)' => round(100 * $fBuildDuration / $fTotal, 1), 'query exec (%)' => round(100 * $fQueryDuration / $fTotal, 1), 'fetch (%)' => round(100 * $fFetchDuration / $fTotal, 1), 'to OQL (%)' => round(100 * $fToOqlDuration / $fTotal, 1), 'parsing+build (%)' => round(100 * ($fParsingDuration + $fBuildDuration) / $fTotal, 1));
 }