Exemplo n.º 1
0
 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));
 }