Skip to content

Instantly share code, notes, and snippets.

@jasonsnider
Last active December 31, 2024 19:40
Show Gist options
  • Save jasonsnider/5761eb16fdf52cbcbed00b9c215f6efa to your computer and use it in GitHub Desktop.
Save jasonsnider/5761eb16fdf52cbcbed00b9c215f6efa to your computer and use it in GitHub Desktop.
# Use an official Ubuntu base image
FROM ubuntu:20.04
# Install necessary packages
RUN apt-get update && apt-get install -y \
kcachegrind \
x11-apps \
dbus-x11 \
git \
nginx \
php-fpm \
php-cli \
php-xml \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Clone Webgrind repository
RUN git clone https://github.com/jokkedk/webgrind.git /var/www/html/webgrind
# Set the working directory
WORKDIR /var/www/html/webgrind
# Copy the Webgrind configuration file
COPY webgrind_config.php /var/www/html/webgrind/config.php
# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/sites-available/default
# Set the display environment variable
ENV DISPLAY=:0
# Set the XDG_RUNTIME_DIR environment variable
ENV XDG_RUNTIME_DIR=/tmp/xdg
# Create the XDG runtime directory with 0755 permissions
RUN mkdir -p /tmp/xdg && chmod 0755 /tmp/xdg
# Expose port 80 for Webgrind
EXPOSE 80
# Command to run KCachegrind with dbus-launch and start Nginx and PHP-FPM
CMD ["sh", "-c", "export $(dbus-launch) && service php7.4-fpm start && nginx -g 'daemon off;' && kcachegrind"]
<?php
// Webgrind configuration file
return array(
'profiler_dir' => '/var/www/html/profiles', // Directory where Xdebug trace files are stored
'storage_dir' => '/tmp/webgrind', // Temporary storage directory
'preprocessed_suffix' => '.webgrind', // Suffix for preprocessed files
'default_timezone' => 'UTC', // Default timezone
'date_format' => 'Y-m-d H:i:s', // Date format
'default_costformat' => 'percent', // Default cost format
'default_function_percentage' => 90, // Default function percentage
'default_hide_internal' => true, // Hide internal functions by default
'graphviz_dot' => '/usr/bin/dot', // Path to Graphviz dot executable
'file_url_format' => 'file://%1$s', // File URL format
'invoke_url' => '', // Invoke URL
'xdebug_output_format' => 'cachegrind', // Xdebug output format
'trace_file' => '', // Trace file
);
version: '3.8'
services:
kcachegrind:
build: .
container_name: kcachegrind
environment:
- DISPLAY=${DISPLAY}
- XDG_RUNTIME_DIR=/tmp/xdg
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ./profiles:/var/www/html/profiles # Mount a local directory to store profile files
- /tmp/xdg:/tmp/xdg # Mount a directory for XDG_RUNTIME_DIR
- /tmp/webgrind:/tmp/webgrind # Temporary storage directory for Webgrind
ports:
- "8080:80" # Expose port 80 for Webgrind
network_mode: host # Use host network mode to share the display
server {
listen 80;
server_name localhost;
root /var/www/html/webgrind;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment