public static function writeToDatabase() { $START_EXEC_CURRENT_TIME = microtime(); global $DB, $APPLICATION; $application = \Bitrix\Main\Application::getInstance(); $connection = $application->getConnection(); $connection->stopTracker(); $DB->ShowSqlStat = false; $arQueryDebug = $connection->getTracker()->getQueries(); $arIncludeDebug = $APPLICATION->arIncludeDebug; $cache_log = COption::GetOptionString("perfmon", "cache_log") === "Y"; $large_cache_log = COption::GetOptionString("perfmon", "large_cache_log") === "Y"; $large_cache_size = floatval(COption::GetOptionString("perfmon", "large_cache_size")) * 1024; $sql_log = COption::GetOptionString("perfmon", "sql_log") === "Y"; $slow_sql_log = COption::GetOptionString("perfmon", "slow_sql_log") === "Y"; $slow_sql_time = floatval(COption::GetOptionString("perfmon", "slow_sql_time")); if ($slow_sql_log) { self::removeQueries($arQueryDebug, $arIncludeDebug, $slow_sql_time, $cache_log); } $query_count = 0; $query_time = 0.0; if ($sql_log) { self::countQueries($query_count, $query_time, $arQueryDebug, $arIncludeDebug); } $comps_count = 0; $comps_time = 0.0; if ($sql_log || $cache_log) { self::countComponents($comps_count, $comps_time, $arIncludeDebug); } $cache_count = array(); /** @var \Bitrix\Main\Diag\CacheTracker $arCacheDebug */ $arCacheDebug = null; if ($cache_log) { $arCacheDebug = \Bitrix\Main\Diag\CacheTracker::getCacheTracking(); if ($large_cache_log) { self::removeCaches($large_cache_size, $arCacheDebug, $arIncludeDebug); } self::countCache($arCacheDebug, $cache_count); foreach ($arIncludeDebug as $ar) { if (array_key_exists("REL_PATH", $ar)) { self::countCache($ar["CACHE"], $cache_count); } } } if ($_SERVER["SCRIPT_NAME"] == "/bitrix/urlrewrite.php" && isset($_SERVER["REAL_FILE_PATH"])) { $SCRIPT_NAME = $_SERVER["REAL_FILE_PATH"]; } elseif ($_SERVER["SCRIPT_NAME"] == "/404.php" && isset($_SERVER["REAL_FILE_PATH"])) { $SCRIPT_NAME = $_SERVER["REAL_FILE_PATH"]; } else { $SCRIPT_NAME = $_SERVER["SCRIPT_NAME"]; } $arFields = array("~DATE_HIT" => $DB->GetNowFunction(), "IS_ADMIN" => defined("ADMIN_SECTION") ? "Y" : "N", "REQUEST_METHOD" => $_SERVER["REQUEST_METHOD"], "SERVER_NAME" => $_SERVER["SERVER_NAME"], "SERVER_PORT" => $_SERVER["SERVER_PORT"], "SCRIPT_NAME" => $SCRIPT_NAME, "REQUEST_URI" => $_SERVER["REQUEST_URI"], "INCLUDED_FILES" => function_exists("get_included_files") ? count(get_included_files()) : false, "MEMORY_PEAK_USAGE" => function_exists("memory_get_peak_usage") ? memory_get_peak_usage() : false, "CACHE_TYPE" => COption::GetOptionString("main", "component_cache_on", "Y") == "Y" ? "Y" : "N", "~CACHE_SIZE" => intval($GLOBALS["CACHE_STAT_BYTES"]), "~CACHE_COUNT_R" => intval($cache_count["R"]), "~CACHE_COUNT_W" => intval($cache_count["W"]), "~CACHE_COUNT_C" => intval($cache_count["C"]), "QUERIES" => $query_count, "~QUERIES_TIME" => $query_time, "SQL_LOG" => $sql_log ? "Y" : "N", "COMPONENTS" => $comps_count, "~COMPONENTS_TIME" => $comps_time, "~MENU_RECALC" => $APPLICATION->_menu_recalc_counter); CPerfomanceKeeper::SetPageTimes($START_EXEC_CURRENT_TIME, $arFields); if ($query_count || $comps_count || $cache_count) { $HIT_ID = $DB->Add("b_perf_hit", $arFields); } else { $HIT_ID = false; } $NN = 0; if ($HIT_ID && $cache_log) { self::saveCaches($HIT_ID, false, $arCacheDebug, $NN); } $MM = 0; if ($HIT_ID && $sql_log) { if (is_array($arQueryDebug)) { self::saveQueries($HIT_ID, false, $arQueryDebug, $MM); } } if ($HIT_ID && ($sql_log || $cache_log)) { foreach ($arIncludeDebug as $ii => $ar) { if (!array_key_exists("REL_PATH", $ar)) { continue; } $cache_count = array(); if ($cache_log) { self::countCache($ar["CACHE"], $cache_count); } $arFields = array("HIT_ID" => $HIT_ID, "NN" => $ii, "CACHE_TYPE" => $ar["CACHE_TYPE"], "~CACHE_SIZE" => intval($ar["CACHE_SIZE"]), "~CACHE_COUNT_R" => intval($cache_count["R"]), "~CACHE_COUNT_W" => intval($cache_count["W"]), "~CACHE_COUNT_C" => intval($cache_count["C"]), "COMPONENT_TIME" => $ar["TIME"], "QUERIES" => $ar["QUERY_COUNT"], "QUERIES_TIME" => $ar["QUERY_TIME"], "COMPONENT_NAME" => $ar["REL_PATH"]); $COMP_ID = $DB->Add("b_perf_component", $arFields); if ($sql_log && is_array($ar["QUERIES"])) { self::saveQueries($HIT_ID, $COMP_ID, $ar["QUERIES"], $MM); } if ($cache_log && is_array($ar["CACHE"])) { self::saveCaches($HIT_ID, $COMP_ID, $ar["CACHE"], $NN); } } } global $perfmonErrors; if ($HIT_ID && count($perfmonErrors) > 0) { foreach ($perfmonErrors as $arError) { $arError["HIT_ID"] = $HIT_ID; $DB->Add("b_perf_error", $arError); } } }
public function Stop($rel_path = "", $path = "", $cache_type = "") { /** @global CMain $APPLICATION */ global $APPLICATION; /** @global CDatabase $DB */ global $DB; /** @global int $CACHE_STAT_BYTES */ global $CACHE_STAT_BYTES; if ($this->is_comp) { self::$level--; } $this->arResult = array("PATH" => $path, "REL_PATH" => $rel_path, "QUERY_COUNT" => 0, "QUERY_TIME" => 0, "QUERIES" => array(), "TIME" => getmicrotime() - $this->start_time, "BX_STATE" => $GLOBALS["BX_STATE"], "CACHE_TYPE" => $cache_type, "CACHE_SIZE" => \Bitrix\Main\Data\Cache::getShowCacheStat() ? \Bitrix\Main\Diag\CacheTracker::getCacheStatBytes() : 0, "LEVEL" => self::$level); if ($this->savedTracker) { $application = \Bitrix\Main\Application::getInstance(); $connection = $application->getConnection(); $sqlTracker = $connection->getTracker(); if ($sqlTracker->getCounter() > 0) { $this->arResult["QUERY_COUNT"] = $sqlTracker->getCounter(); $this->arResult["QUERY_TIME"] = $sqlTracker->getTime(); $this->arResult["QUERIES"] = $sqlTracker->getQueries(); } $connection->setTracker($this->savedTracker); $DB->sqlTracker = $connection->getTracker(); $this->savedTracker = null; } if (\Bitrix\Main\Data\Cache::getShowCacheStat()) { $this->arResult["CACHE"] = \Bitrix\Main\Diag\CacheTracker::getCacheTracking(); \Bitrix\Main\Diag\CacheTracker::setCacheTracking($this->arCacheDebugSave); \Bitrix\Main\Diag\CacheTracker::setCacheStatBytes($CACHE_STAT_BYTES = $this->cache_size); } }
$arCacheDebug = \Bitrix\Main\Diag\CacheTracker::getCacheTracking(); if (!empty($arCacheDebug)) { echo '<a title="' . GetMessage("debug_info_query_title") . '" href="javascript:BX_DEBUG_INFO_CACHE.Show(); BX_DEBUG_INFO_CACHE.ShowDetails(\'BX_DEBUG_INFO_CACHE_m_0\');">' . GetMessage("debug_info_cache_size") . "</a> " . " ", CFile::FormatSize(\Bitrix\Main\Diag\CacheTracker::getCacheStatBytes(), 0) . " (" . count($arCacheDebug) . ")<br>"; } else { echo GetMessage("debug_info_cache_size") . " ", CFile::FormatSize(\Bitrix\Main\Diag\CacheTracker::getCacheStatBytes(), 0) . "<br>"; } } } if ($bShowTime || $bShowStat) { echo '</div><div class="empty"></div>'; } if ($bShowStat || $bShowCacheStat) { $APPLICATION->arIncludeDebug[] = array("PATH" => $APPLICATION->GetCurPage(), "QUERY_COUNT" => $totalQueryCount, "QUERY_TIME" => round($totalQueryTime, 4), "QUERIES" => $sqlTracker, "TIME" => $main_exec_time); //CJSPopup require_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/interface/admin_lib.php"; $arCacheDebug = \Bitrix\Main\Diag\CacheTracker::getCacheTracking(); if (!empty($arCacheDebug)) { ?> <script type="text/javascript"> function sortTable(table_id, column_num, reverse) { var table = BX(table_id); var title = table.rows[0].cells[column_num].innerHTML; if (title.charCodeAt(0) == 8595) reverse = true; if (title.charCodeAt(0) == 8593) reverse = false; for (var i = 1; i < table.rows.length; i++) { for (var j = 1; j < table.rows.length; j++)
public function Stop($rel_path = "", $path = "", $cache_type = "") { /** @global CMain $APPLICATION */ global $APPLICATION; /** @global CDatabase $DB */ global $DB; /** @global int $CACHE_STAT_BYTES */ global $CACHE_STAT_BYTES; if ($this->is_comp) { self::$level--; } $this->arResult = array("PATH" => $path, "REL_PATH" => $rel_path, "QUERY_COUNT" => 0, "QUERY_TIME" => 0, "QUERIES" => array(), "TIME" => getmicrotime() - $this->start_time, "BX_STATE" => $GLOBALS["BX_STATE"], "CACHE_TYPE" => $cache_type, "CACHE_SIZE" => \Bitrix\Main\Data\Cache::getShowCacheStat() ? \Bitrix\Main\Diag\CacheTracker::getCacheStatBytes() : 0, "LEVEL" => self::$level); if ($DB->ShowSqlStat) { if ($DB->cntQuery) { $this->arResult["QUERY_COUNT"] = $DB->cntQuery; $this->arResult["QUERY_TIME"] = $DB->timeQuery; $this->arResult["QUERIES"] = $DB->arQueryDebug; } $DB->arQueryDebug = $this->arQueryDebugSave; $DB->cntQuery = $this->cnt_query; $DB->timeQuery = $this->query_time; } if (\Bitrix\Main\Data\Cache::getShowCacheStat()) { $this->arResult["CACHE"] = \Bitrix\Main\Diag\CacheTracker::getCacheTracking(); \Bitrix\Main\Diag\CacheTracker::setCacheTracking($this->arCacheDebugSave); \Bitrix\Main\Diag\CacheTracker::setCacheStatBytes($CACHE_STAT_BYTES = $this->cache_size); } }