Browse Source

adding uprofiler image with php 5.6

vpoturaev 7 years ago
parent
commit
94dada4f2e
6 changed files with 84 additions and 4 deletions
  1. 3 0
      .gitmodules
  2. 25 0
      Dockerfile.uprofiler_php56
  3. 8 2
      Makefile
  4. 8 2
      README.md
  5. 39 0
      prepend_uprofiler.php
  6. 1 0
      uprofiler

+ 3 - 0
.gitmodules

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

+ 25 - 0
Dockerfile.uprofiler_php56

@@ -0,0 +1,25 @@
+FROM php:5.6-cli
+
+RUN apt-get update && apt-get install -y graphviz && apt-get clean
+
+COPY ./uprofiler/extension /extension
+
+RUN cd /extension && \
+     phpize && \
+     ./configure && \
+     make && \
+     make install && \
+     rm -rf /extension && \
+     docker-php-ext-enable uprofiler
+
+COPY ./prepend_uprofiler.php /prepend.php
+
+COPY ./php.ini /usr/local/etc/php/
+
+COPY ./xhprof/xhprof_lib/utils /utils
+
+ENV SVG=$SVG
+
+ENV REPORT=$REPORT
+
+WORKDIR /code

+ 8 - 2
Makefile

@@ -4,8 +4,14 @@ build:
 push:
 	docker push phperf/php-profiler:latest
 
-build56:
+build-xhprof:
 	docker build -t phperf/php-profiler:5.6-xhprof -f Dockerfile.xhprof_php56 .
 
-push56:
+build-uprofiler:
+	docker build -t phperf/php-profiler:5.6-uprofiler -f Dockerfile.uprofiler_php56 .
+
+push-xhprof:
 	docker push phperf/php-profiler:5.6-xhprof
+
+push-uprofiler:
+	docker push phperf/php-profiler:5.6-uprofiler

+ 8 - 2
README.md

@@ -1,4 +1,4 @@
-# Dockerized command-line PHP 7 profiler (tideways)
+# Dockerized command-line PHP 7 profiler (XHPROF-compatible)
 
 Portable docker image with PHP 7.2 and `tideways` extension installed.
 
@@ -65,4 +65,10 @@ If you want to save profile data to a particular file, you can provide it with `
 docker run --rm -e REPORT=rep.json -v $(pwd):/code phperf/php-profiler php t2.php
 Nodes in report: 12
 Saving report to rep.json
-```
+```
+
+## Tags
+
+* `phperf/php-profiler:latest` PHP 7.2, tideways 4.1.5, [Dockerfile](https://github.com/phperf/profiler-docker/blob/master/Dockerfile)
+* `phperf/php-profiler:5.6-xhprof` PHP 5.6, xhprof 0.9.4, [Dockerfile](https://github.com/phperf/profiler-docker/blob/master/Dockerfile.xhprof_php56)
+* `phperf/php-profiler:5.6-uprofiler` PHP 5.6, uprofiler, [Dockerfile](https://github.com/phperf/profiler-docker/blob/master/Dockerfile.uprofiler_php56)

+ 39 - 0
prepend_uprofiler.php

@@ -0,0 +1,39 @@
+<?php
+
+register_shutdown_function(
+    function () {
+        register_shutdown_function(function () {
+            $data = uprofiler_disable();
+            echo 'Nodes in report: ' . count($data) . "\n";
+            $name = getenv('REPORT');
+            if (empty($name)) {
+                $name = 'xhprof_report.' . microtime(1) . '.serialized';
+            }
+            echo 'Saving report to ' . $name, "\n";
+
+            file_put_contents('/code/' . $name,
+                '.json' === substr($name, -5) ? json_encode($data) : serialize($data));
+
+            if (getenv('SVG')) {
+                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);
+            }
+        });
+    }
+);
+
+uprofiler_enable(UPROFILER_FLAGS_MEMORY | UPROFILER_FLAGS_CPU);
+

+ 1 - 0
uprofiler

@@ -0,0 +1 @@
+Subproject commit 32ea09312c0905bfb3a98bb5ec53e685d101d4fd