function endDataCache($vars = false) { if (!$this->isStarted) { return; } $this->isStarted = false; $arAllVars = array("CONTENT" => ob_get_contents(), "VARS" => $vars !== false ? $vars : $this->vars); $this->cacheEngine->write($arAllVars, $this->baseDir, $this->initDir, $this->filename, $this->TTL); if (static::$showCacheStat) { $written = 0; $path = ''; if ($this->cacheEngine instanceof ICacheEngineStat) { $written = $this->cacheEngine->getWrittenBytes(); $path = $this->cacheEngine->getCachePath(); } elseif ($this->cacheEngine instanceof \ICacheBackend) { /** @noinspection PhpUndefinedFieldInspection */ $written = $this->cacheEngine->written; /** @noinspection PhpUndefinedFieldInspection */ $path = $this->cacheEngine->path; } Diag\CacheTracker::addCacheStatBytes($written); Diag\CacheTracker::add($written, $path, $this->baseDir, $this->initDir, $this->filename, "W"); } if (strlen(ob_get_contents()) > 0) { ob_end_flush(); } else { ob_end_clean(); } }
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); } } }
?> </p> <p><?php echo GetMessage("debug_info_comps_cache"); ?> <?php if (COption::GetOptionString("main", "component_cache_on", "Y") == "Y") { echo GetMessage("debug_info_comps_cache_on"); } else { echo "<a href=\"/bitrix/admin/cache.php\"><font class=\"errortext\">" . GetMessage("debug_info_comps_cache_off") . "</font></a>"; } ?> .</p> <p><?php if (\Bitrix\Main\Data\Cache::getShowCacheStat()) { echo GetMessage("debug_info_cache_size") . " ", CFile::FormatSize(\Bitrix\Main\Diag\CacheTracker::getCacheStatBytes(), 0); } else { echo " "; } ?> </p> <?php $obJSPopup->StartContent(array('buffer' => true)); ?> <div id="BX_DEBUG_TIME_1"> <div class="bx-debug-content bx-debug-content-table"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr class="heading"> <td> </td> <td> </td>
function EndDataCache() { if (!$this->bStarted) { return; } $this->bStarted = false; $arAllVars = ob_get_contents(); $this->_cache->write($arAllVars, $this->basedir, $this->initdir, $this->filename, $this->TTL); if (\Bitrix\Main\Data\Cache::getShowCacheStat()) { $written = 0; $path = ''; if ($this->_cache instanceof \Bitrix\Main\Data\ICacheEngineStat) { $written = $this->_cache->getWrittenBytes(); $path = $this->_cache->getCachePath(); } elseif ($this->_cache instanceof \ICacheBackend) { /** @noinspection PhpUndefinedFieldInspection */ $written = $this->_cache->written; /** @noinspection PhpUndefinedFieldInspection */ $path = $this->_cache->path; } \Bitrix\Main\Diag\CacheTracker::addCacheStatBytes($written); \Bitrix\Main\Diag\CacheTracker::add($written, $path, $this->basedir, $this->initdir, $this->filename, "W"); } if (strlen($arAllVars) > 0) { ob_end_flush(); } else { ob_end_clean(); } }
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); } }
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); } }