Skip to content

XHProf + Webgrind + xdebug profiling #149

@nicobot

Description

@nicobot

Currently it's hard to do profiling. I want to summarize it here and then look for a simple solution:

Add the following containers:

  
  xhprof:
    network_mode: traefik_default
    image: wodby/xhprof:$XHPROF_TAG
    container_name: "${PROJECT_NAME}_xhprof"
    restart: always
    volumes:
      - ./files:/mnt/files
    labels:
      - 'traefik.frontend.rule=Host:${PROJECT_NAME}.xhprof.localhost'

  xhprof_viewer:
    network_mode: traefik_default
    image: "jeromebreton/xhprof-simple-viewer:latest"
    container_name: "${PROJECT_NAME}_xhprof_viewer"
    restart: always
    volumes:
      - ./files/private/xhprof:/traces
    labels:
      - 'traefik.frontend.rule=Host:${PROJECT_NAME}.xhprofv.localhost'

In the PHP container:

1- add the following variable:
PHP_XHPROF: 1
2- add the following volume:
- ./files:/mnt/files

In the code where you 'd like to profile, do:


    // Start profiling.
    if (extension_loaded('xhprof')) {
      xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);
    }

// ..... code to profile ..........

    // Store profile.
    if (extension_loaded('xhprof')) {
      $data = xhprof_disable();
      $xhprof_out = '/mnt/files/private/xhprof';

      if (!file_exists($xhprof_out)) {
        mkdir($xhprof_out);
      }

      file_put_contents(sprintf('%s/%s.%s.xhprof', $xhprof_out, uniqid(), 'web'), serialize($data));
    }

After running the code, traces will be generated at /files/private/xhprof and they can be viewed at:
http://PROJECT_NAME.xhprofv.localhost/index.php?run=

For some reason, the "xhprof" container is not rendering the callgraph using correct unicodes:
image

This is why we have the container xhprof_viewer,
image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions