Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XHProf + Webgrind + xdebug profiling #149

Open
nicobot opened this issue Jan 16, 2023 · 0 comments
Open

XHProf + Webgrind + xdebug profiling #149

nicobot opened this issue Jan 16, 2023 · 0 comments
Assignees

Comments

@nicobot
Copy link
Collaborator

nicobot commented Jan 16, 2023

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

@nicobot nicobot self-assigned this Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant