浏览代码

adding graph

vpoturaev 8 年之前
父节点
当前提交
3b553a2714
共有 4 个文件被更改,包括 26 次插入0 次删除
  1. 3 0
      .gitmodules
  2. 4 0
      Dockerfile
  3. 18 0
      prepend_v4.php
  4. 1 0
      xhprof

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "xhprof"]
+	path = xhprof
+	url = https://github.com/phacility/xhprof.git

+ 4 - 0
Dockerfile

@@ -11,8 +11,12 @@ RUN curl "https://github.com/tideways/php-profiler-extension/archive/v4.1.4.tar.
      cd .. && rm -rf ./a.tar.gz ./php-profiler-extension-4.1.4 && \
      cd .. && rm -rf ./a.tar.gz ./php-profiler-extension-4.1.4 && \
      docker-php-ext-enable tideways
      docker-php-ext-enable tideways
 
 
+RUN apt-get update && apt-get install -y graphviz
+
 COPY ./prepend_v4.php /prepend.php
 COPY ./prepend_v4.php /prepend.php
 
 
 COPY ./php.ini /usr/local/etc/php/
 COPY ./php.ini /usr/local/etc/php/
 
 
+COPY ./xhprof/xhprof_lib/utils /utils
+
 WORKDIR /code
 WORKDIR /code

+ 18 - 0
prepend_v4.php

@@ -6,10 +6,28 @@ register_shutdown_function(
     function () {
     function () {
         register_shutdown_function(function () {
         register_shutdown_function(function () {
             $data = tideways_disable();
             $data = tideways_disable();
+            echo 'Nodes in report: ' . count($data) . "\n";
             $name = 'xhprof_report.' . microtime(1) . '.serialized';
             $name = 'xhprof_report.' . microtime(1) . '.serialized';
             echo 'Saving report to ' . $name, "\n";
             echo 'Saving report to ' . $name, "\n";
             file_put_contents('/code/' . $name,
             file_put_contents('/code/' . $name,
                 serialize($data));
                 serialize($data));
+
+            include_once "/utils/callgraph_utils.php";
+            include_once "/utils/xhprof_lib.php";
+            include_once "/utils/xhprof_runs.php";
+
+            echo "Generating dot script\n";
+            $threshold = 0;
+            if (count($data) > 1000) {
+                $threshold = 0.001;
+            }
+            $script = xhprof_generate_dot_script($data, $threshold, null, null, null, null);
+            echo "Generating dot image\n";
+            $content = xhprof_generate_image_by_dot($script, 'svg');
+            echo 'Saving graph to ' . $name . '.svg', "\n";
+            file_put_contents('/code/' . $name . '.svg',
+                $content);
+
         });
         });
     }
     }
 );
 );

+ 1 - 0
xhprof

@@ -0,0 +1 @@
+Subproject commit 0bbf2a2ac34f495e42aa852293fe0ed821659047