Beispiel #1
0
<?php

$module_id = "perfmon";
$RIGHT = $APPLICATION->GetGroupRight($module_id);
if ($RIGHT >= "R") {
    IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/options.php");
    IncludeModuleLangFile(__FILE__);
    $arAllOptions = array(array("max_display_url", GetMessage("PERFMON_OPTIONS_MAX_DISPLAY_URL"), array("text", 6)), array("warning_log", GetMessage("PERFMON_OPTIONS_WARNING_LOG"), array("checkbox")), array("cache_log", GetMessage("PERFMON_OPTIONS_CACHE_LOG"), array("checkbox")), array("sql_log", GetMessage("PERFMON_OPTIONS_SQL_LOG"), array("checkbox")), array("sql_backtrace", GetMessage("PERFMON_OPTIONS_SQL_BACKTRACE"), array("checkbox")), array("slow_sql_log", GetMessage("PERFMON_OPTIONS_SLOW_SQL_LOG"), array("checkbox"), GetMessage("PERFMON_OPTIONS_SLOW_SQL_NOTE")), array("slow_sql_time", GetMessage("PERFMON_OPTIONS_SLOW_SQL_TIME"), array("text", 6)));
    $aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("MAIN_TAB_SET"), "ICON" => "perfmon_settings", "TITLE" => GetMessage("MAIN_TAB_TITLE_SET")), array("DIV" => "edit2", "TAB" => GetMessage("MAIN_TAB_RIGHTS"), "ICON" => "perfmon_settings", "TITLE" => GetMessage("MAIN_TAB_TITLE_RIGHTS")));
    $tabControl = new CAdminTabControl("tabControl", $aTabs);
    CModule::IncludeModule($module_id);
    if ($REQUEST_METHOD == "POST" && strlen($Update . $Apply . $RestoreDefaults) > 0 && $RIGHT == "W" && check_bitrix_sessid()) {
        require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/perfmon/prolog.php";
        if ($_REQUEST["clear_data"] === "y") {
            CPerfomanceComponent::Clear();
            CPerfomanceSQL::Clear();
            CPerfomanceHit::Clear();
            CPerfomanceError::Clear();
            CPerfomanceCache::Clear();
        }
        if (array_key_exists("ACTIVE", $_REQUEST)) {
            $ACTIVE = intval($_REQUEST["ACTIVE"]);
            CPerfomanceKeeper::SetActive($ACTIVE > 0, time() + $ACTIVE);
        }
        if (strlen($RestoreDefaults) > 0) {
            COption::RemoveOption("perfmon");
        } else {
            foreach ($arAllOptions as $arOption) {
                $name = $arOption[0];
                $val = $_REQUEST[$name];
                if ($arOption[2][0] == "checkbox" && $val != "Y") {
while ($arQuery = $rsQueries->Fetch()) {
    $arQuery["STAT"] = array();
    $arQuery["WHERE"] = array();
    $arQuery["JOIN"] = array();
    $q = new CPerfQuery();
    if ($q->parse($q->transform2select($arQuery["SQL_TEXT"]))) {
        foreach ($arColumns as $column_name) {
            $arQuery["WHERE"][$column_name] = $q->find_value($arSuggest["TABLE_NAME"], $column_name);
            if ($arQuery["WHERE"][$column_name] == "") {
                $arQuery["JOIN"][$column_name] = $q->find_join($arSuggest["TABLE_NAME"], $column_name);
            } else {
                $arQuery["JOIN"][$column_name] = "";
            }
        }
    }
    $sql = CPerfomanceSQL::Format($arQuery["SQL_TEXT"]);
    $sql = htmlspecialcharsEx($sql);
    $sql = preg_replace("/(" . preg_quote($arSuggest["TABLE_NAME"]) . "\\s+(?i:as\\s+)*" . $arSuggest["TABLE_ALIAS"] . ")\\s+/", "<b>\\1</b> ", $sql);
    foreach (explode(",", $arSuggest["COLUMN_NAMES"]) as $column_name) {
        $sql = str_replace($arSuggest["TABLE_ALIAS"] . "." . $column_name, "<b>" . $arSuggest["TABLE_ALIAS"] . "." . $column_name . "</b>", $sql);
    }
    $arQuery["FORMATTED_SQL_TEXT"] = $sql;
    foreach ($arColumns as $column_name) {
        if ($arQuery["WHERE"][$column_name]) {
            $arColStat = CPerfQueryStat::GatherColumnStatByValue($arSuggest["TABLE_NAME"], $column_name, trim($arQuery["WHERE"][$column_name], "'"));
            if ($arColStat && $arColStat["TABLE_ROWS"] > 0) {
                $arQuery["STAT"][$column_name] = $arColStat["COLUMN_ROWS"] / $arColStat["TABLE_ROWS"];
            }
        } elseif ($arQuery["JOIN"][$column_name]) {
            $arColStat = CPerfQueryStat::GatherColumnStatOverall($arSuggest["TABLE_NAME"], $column_name);
            if ($arColStat && $arColStat["TABLE_ROWS"] > 0) {
Beispiel #3
0
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$APPLICATION->SetTitle(GetMessage("PERFMON_EXPLAIN_TITLE"));
$ID = IntVal($ID);
$sTableID = "tbl_perfmon_explain";
$lAdmin = new CAdminList($sTableID);
if ($DBType == "mysql") {
    $arHeader = array(array("id" => "select_type", "content" => GetMessage("PERFMON_EXPLAIN_F_SELECT_TYPE"), "align" => "left", "default" => true), array("id" => "table", "content" => GetMessage("PERFMON_EXPLAIN_F_TABLE"), "align" => "left", "default" => true), array("id" => "type", "content" => GetMessage("PERFMON_EXPLAIN_F_TYPE"), "align" => "left", "default" => true), array("id" => "possible_keys", "content" => GetMessage("PERFMON_EXPLAIN_F_POSSIBLE_KEYS"), "align" => "left", "default" => true), array("id" => "key", "content" => GetMessage("PERFMON_EXPLAIN_F_KEY"), "align" => "left", "default" => true), array("id" => "key_len", "content" => GetMessage("PERFMON_EXPLAIN_F_KEY_LEN"), "align" => "right", "default" => true), array("id" => "ref", "content" => GetMessage("PERFMON_EXPLAIN_F_REF"), "align" => "left", "default" => true), array("id" => "rows", "content" => GetMessage("PERFMON_EXPLAIN_F_ROWS"), "align" => "right", "default" => true), array("id" => "Extra", "content" => GetMessage("PERFMON_EXPLAIN_F_EXTRA"), "align" => "left", "default" => true));
} elseif ($DBType == "oracle") {
    $arHeader = array(array("id" => "OPERATION", "content" => GetMessage("PERFMON_EXPLAIN_F_OPERATION"), "align" => "left", "default" => true), array("id" => "OBJECT_NAME", "content" => GetMessage("PERFMON_EXPLAIN_F_OBJECT_NAME"), "align" => "left", "default" => true), array("id" => "OBJECT_TYPE", "content" => GetMessage("PERFMON_EXPLAIN_F_OBJECT_TYPE"), "align" => "left", "default" => true), array("id" => "OPTIONS", "content" => GetMessage("PERFMON_EXPLAIN_F_EXTRA"), "align" => "left", "default" => true), array("id" => "CARDINALITY", "content" => GetMessage("PERFMON_EXPLAIN_F_ROWS"), "align" => "right", "default" => true), array("id" => "COST", "content" => GetMessage("PERFMON_EXPLAIN_F_COST"), "align" => "right", "default" => true));
} else {
    $arHeader = array();
}
$lAdmin->AddHeaders($arHeader);
$arPlan = false;
$cData = new CPerfomanceSQL();
$rsSQL = $cData->GetList(array("ID", "SQL_TEXT"), array("=ID" => $ID), array(), false);
$arSQL = $rsSQL->Fetch();
$strSQL = CPerfQuery::transform2select($arSQL["SQL_TEXT"]);
if ($strSQL) {
    if ($DBType == "mysql") {
        $rsData = $DB->Query("explain " . $strSQL, true);
    } elseif ($DBType == "oracle") {
        $rsData = $DB->Query("explain plan for " . $strSQL, true);
        if ($rsData) {
            $rsData = $DB->Query("select * from plan_table order by ID");
            $arPlan = $rsData->Fetch();
        }
    } else {
        $rsData = false;
    }
 $arRes["SQL_TEXT"] = CPerfomanceSQL::Format($arRes["SQL_TEXT"]);
 $row =& $lAdmin->AddRow($f_NAME, $arRes);
 $row->AddViewField("SQL_TIME", perfmon_NumberFormat($f_SQL_TIME, 6));
 if ($f_SQL_COUNT > 0) {
     $row->AddViewField("SQL_TIME_AVG", perfmon_NumberFormat($f_SQL_TIME / $f_SQL_COUNT, 6));
 }
 $row->AddViewField("SQL_COUNT", '<a href="perfmon_sql_list.php?lang=' . LANGUAGE_ID . '&amp;set_filter=Y&amp;find_suggest_id=' . $f_ID . '">' . $f_SQL_COUNT . '</a>');
 $row->AddViewField("COLUMN_NAMES", str_replace(",", "<br>", $f_COLUMN_NAMES));
 if ($f_BANNED == "N") {
     $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-green" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_GREEN_ALT")) . '"></span>');
 } elseif ($f_BANNED == "Y") {
     $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-red" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_RED_ALT")) . '"></span>');
 } else {
     $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-yellow" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_YELLOW_ALT")) . '"></span>');
 }
 $rsQueries = CPerfomanceSQL::GetList(array("ID"), array("=SUGGEST_ID" => $f_ID), array("ID" => "ASC"), false, array("nTopCount" => 1));
 if ($arQuery = $rsQueries->GetNext()) {
     $f_SQL_ID = $arQuery["ID"];
 } else {
     $f_SQL_ID = "";
 }
 if (class_exists("geshi") && $f_SQL_TEXT) {
     $obGeSHi = new GeSHi($arRes["SQL_TEXT"], 'sql');
     $html = $obGeSHi->parse_code();
 } else {
     $html = str_replace(array(" ", "\n"), array(" &nbsp;", "<br>"), htmlspecialcharsbx($arRes["SQL_TEXT"]));
 }
 $html = '<span onmouseover="addTimer(this)" onmouseout="removeTimer(this)" id="' . $f_SQL_ID . '_sql_backtrace">' . $html . '</span>';
 $row->AddViewField("SQL_TEXT", $html);
 $arActions = array(array("DEFAULT" => "Y", "TEXT" => GetMessage("PERFMON_INDEX_DETAILS"), "ACTION" => $lAdmin->ActionRedirect('perfmon_index_detail.php?lang=' . LANG . '&ID=' . $f_ID)));
 if ($f_SQL_ID) {
Beispiel #5
0
		$arClusterNodes[$node["ID"]] = htmlspecialcharsex($node["NAME"]);
}

$lAdmin->AddHeaders($arHeaders);

$arSelectedFields = $lAdmin->GetVisibleHeaderColumns();
if (!is_array($arSelectedFields) || (count($arSelectedFields) < 1))
	$arSelectedFields = array(
		"ID",
		"HIT_ID",
		"NN",
		"QUERY_TIME",
		"SQL_TEXT",
	);

$cData = new CPerfomanceSQL;
$rsData = $cData->GetList($arSelectedFields, $arFilter, array($by => $order), false, array("nPageSize" => CAdminResult::GetNavSize($sTableID)));

$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("PERFMON_SQL_PAGE")));

while ($arRes = $rsData->NavNext(true, "f_")):
	$arRes["SQL_TEXT"] = CPerfomanceSQL::Format($arRes["SQL_TEXT"]);
	$row =& $lAdmin->AddRow($f_NAME, $arRes);

	if ($_REQUEST["mode"] == "excel")
		$row->AddViewField("QUERY_TIME", number_format($f_QUERY_TIME, 6, ".", ""));
	else
		$row->AddViewField("QUERY_TIME", str_replace(" ", "&nbsp;", number_format($f_QUERY_TIME, 6, ".", " ")));