您的位置:首页 > 博客中心 > 数据库 >

搭建4.xdebug+mysql general_log

时间:2022-03-14 03:47

1.先把tgz的包在本地解压,把里面的tar包传到 centos的/root目录,使用tar -xvf 解压tar包,解压出了xdebug-2.2.4、package.xml,
2。进入xdebug,执行phpize
3.不报错的话 执行./configure --enable-xdebug
4、make && make install

6.vi /etc/php.ini,后面加入
    [Xdebug]
    zend_extension ="/usr/lib/php/modules/xdebug.so"
    xdebug.profiler_enable=on
    xdebug.trace_output_dir="/tmp/xdebug"
    xdebug.profiler_output_dir="/tmp/xdebug"
    xdebug.remote_enable=on
    xdebug.remote_handler=dbgp
7.建立log输出目录 mkdir -p /tmp/xdebug
8.给log输出目录赋权限 chmod 777 /tmp/xdebug
9.重启apache ,service httpd restart
10.访问网站后,在/tmp/xdebug中会有日志
11、使用wincachegrind查看日志。
12、分析日志:overall中 call:调用次数;self 方法自己的时间;cum 方法总时间,包括了调用其他方法的

安装xhprof函数级别的性能分析()
1、1.先把tgz的包在本地解压,把里面的tar包传到 centos的/root目录,使用tar -xvf 解压tar包,解压出了xdebug-2.2.4、package.xml,
2。进入xhprof,再进入cd extension/,执行phpize
3、./configure --with-php-config=/usr/bin/php-config
4、make && make install
5.建立目录 mkdir -p /tmp/xhprof
6.给l目录赋权限 chmod 777 /tmp/xhprof
7.vi /etc/php.ini,后面加入
[xhprof]
extension=xhprof.so

; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;xhprof.output_dir=<directory_for_storing_xhprof_runs>

xhprof.output_dir=/tmp/xhprof
8.重启apache ,service httpd restart
9.在php文件打点
// cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY
// 如果两个一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

// 要测试的php代码
foo();

$data = xhprof_disable();   //返回运行数据
 
// xhprof_lib在下载的包里存在这个目录,记得将目录包含到运行的php代码中
include_once "xhprof_lib/utils/xhprof_lib.php";  
include_once "xhprof_lib/utils/xhprof_runs.php";  
 
$objXhprofRun = new XHProfRuns_Default();

// 第一个参数j是xhprof_disable()函数返回的运行信息
// 第二个参数是自定义的命名空间字符串(任意字符串),
// 返回运行ID,用这个ID查看相关的运行结果
$run_id = $objXhprofRun->save_run($data, "xhprof");
var_dump($run_id);
echo "\nhttp://192.168.0.99/xxx/xhprof_html/index.php?run={$run_id}&source=xhprof\n";

10、http://192.168.0.99/xhproftest/xhprof_html/index.php?run=54779d94bfa61&source=xhprof
查看统计报告
  calls 调用次数
  incl.wall time
  excl.wall time自身时间
    cpu毫秒
    memuse字节
    peakmemuse 内存峰值
图表中红色为瓶颈、黄色为路径和耗时。

 

 

MYSQL_general_log

mysql> show global variables like "%general%";
+------------------+----------------------------------+
| Variable_name    | Value                            |
+------------------+----------------------------------+
| general_log      | OFF                              |
| general_log_file | /opt/lampp/var/mysql/centos1.log |
+------------------+----------------------------------+
2 rows in set (0.00 sec)

mysql> set global general_log=ON;
Query OK, 0 rows affected (0.04 sec)

mysql> show global variables like "%general%";
+------------------+----------------------------------+
| Variable_name    | Value                            |
+------------------+----------------------------------+
| general_log      | ON                               |
| general_log_file | /opt/lampp/var/mysql/centos1.log |
+------------------+----------------------------------+
2 rows in set (0.04 sec)

用完了记得关掉

mysql> set global general_log=OFF;
Query OK, 0 rows affected (0.01 sec)

mysql> show global variables like ‘general%‘;
+------------------+----------------------------------+
| Variable_name    | Value                            |
+------------------+----------------------------------+
| general_log      | OFF                              |
| general_log_file | /opt/lampp/var/mysql/centos1.log |
+------------------+----------------------------------+
2 rows in set (0.00 sec)

热门排行

今日推荐

热门手游