<?xml version="1.0" encoding="utf-8"?>
<modification>
	<name>SQL Query Time Log</name>
    <version>0.2</version>
    <code>SQL Query Time Log</code>
    <author>Otvet</author>
	
	<file path="system/library/db.php">
		<operation>
			<search><![CDATA[
			return $this->db->query($sql);
			]]></search>
			<add position="replace"><![CDATA[			
		$min_time = 10;//МИНИМАЛЬНОЕ ВРЕМЯ ИСПОЛНЕНИЯ ЗАПРОСА В МС, ЗАПИСЫВАЕМОЕ В ЛОГ
        $file = debug_backtrace();
        $name = (!isset($file[0]['file'])) ? 'N/A' : $file[0]['file'];
        $start = (time() + microtime());
        $query_out = $this->db->query($sql);
        $end = (time() + microtime());
        $sql_time = round($end - $start, 5)*1000;
        if ($sql_time > $min_time) {
        file_put_contents(DIR_LOGS.'sql_time.log', ("\nСтраница:".$_SERVER['REQUEST_URI']."\nИсточник:" . $name . "\nВремя выполнения: " . $sql_time . "мс \n\n" . $sql . "\n\n----------------------\n"), FILE_APPEND); }
        return $query_out;
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[
			return $this->adaptor->query($sql, $params);
			]]></search>
			<add position="replace"><![CDATA[			
		$min_time = 10;//МИНИМАЛЬНОЕ ВРЕМЯ ИСПОЛНЕНИЯ ЗАПРОСА В МС, ЗАПИСЫВАЕМОЕ В ЛОГ
        $file = debug_backtrace();
        $name = (!isset($file[0]['file'])) ? 'N/A' : $file[0]['file'];
        $start = (time() + microtime());
        $query_out = $this->adaptor->query($sql, $params);
        $end = (time() + microtime());
        $sql_time = round($end - $start, 5)*1000;
        if ($sql_time > $min_time) {
        file_put_contents(DIR_LOGS.'sql_time.log', ("\nСтраница:".$_SERVER['REQUEST_URI']."\nИсточник:" . $name . "\nВремя выполнения: " . $sql_time . "мс \n\n" . $sql . "\n\n----------------------\n"), FILE_APPEND); }
        return $query_out;
			]]></add>
		</operation>
	</file>
</modification>