SkillAgentSearch skills...

Pyrospy

Adapter from phpspy to pyroscope

Install / Use

/learn @zoonru/Pyrospy
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PyroSpy

Adapter from phpspy to pyroscope.io

About Us

<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <a href="https://company.zoon.ru"> <img src="https://company.zoon.ru/images/logo.svg" width="140" alt="zoon logo"/> </a> </td> <td> <b><a href="https://zoon.ru/" target="_blank">Zoon</a></b> - it's international service, that helps local businesses grow. <ul> <li>We tell the audience about the services and products of companies</li> <li>We promote on dozens of sites: in the catalog on zoon.ru, on partner sites, on Yandex and Google maps</li> <li>We help business owners manage marketing from a single personal account</li> </ul> </td> </tr> </table>

Phpspy requirements

  • apt install binutils for Ubuntu/Debian
  • To use in docker container it must be privileged or with capability SYS_PTRACE

Parameters:

Usage:
  php pyrospy.php run [options]

Options:
  -s, --pyroscope=STRING     Url of the pyroscope server. 
                             Example: https://your-pyroscope-sever.com
                             
  -auth, --pyroscopeAuthToken=STRING     
                             Pyroscope Auth Token. 
                             Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI
                             
  -m, --memory               Enable memory traces mode
                             Get memory usage from 'mem' tag and send average memory usage for trace group
                             Do not provide this option for CPU mode
                             
  -a, --app=STRING           Name of app. 
                             All samples will be saved under given app name.
                             Example: app
                             
  -r, --rateHz=INT           Sample rate in Hz. 
                             Used to convert number of samples to CPU time 
                             [default: 100]
                             
  -i, --interval=INT         Maximum time between requests to pyroscope server 
                             [default: 10]
                             
  -b, --batch=INT            Maximum number of traces in request to pyroscope server 
                             [default: 250]
                             
  -t, --tags=STRING=STRING   Add tags to samples. Use to filter data inside one app.
                             Example: host=server1; role=cli 
                             (multiple values allowed)
                             
  -p, --plugins=STRING       Load custom class to modify trace and phpspy comments/tags. Can be class or folder with classes.
                             Example: /zoon/pyrospy/app/Plugins/ClearEmptyTags.php
                             (multiple values allowed)
                             
  -h, --help                 Display help for the given command. 
                             When no command is given display help for the list command

Usage:

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=1024 --rate-hz=4 --buffer-size=65536 -J m -P '-x "php|php[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=4 --app=testApp --tags=host=server39 --tags=role=cli

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=100 --rate-hz=25 --buffer-size=65536 -J m -P '-x "php-fpm|php-fpm[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=25 --app=testApp --tags=host=server39 --tags=role=web

Memory profiling

  • add --memory-usage option to phpspy command to add current and maximum memory usage to tags
  • add --memory option to pyrospy command to send average memory usage for traces instead of sum count
phpspy --max-depth=-1 --time-limit-ms=59000 --threads=1024 --memory-usage --rate-hz=4 --buffer-size=65536 -J m -P '-x "php|php[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=4 --app=testAppMemory --tags=host=server39 --tags=role=cli --memory

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=100 --memory-usage --rate-hz=25 --buffer-size=65536 -J m -P '-x "php-fpm|php-fpm[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=25 --app=testAppMemory --tags=host=server39 --tags=role=web --memory

Tee can be used to get memory usage and cpu samples from same phpspy stdout

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=1024 --memory-usage --rate-hz=4 --buffer-size=65536 -J m -P '-x "php|php[0-9]\.[0-9]" | shuf' 2> error_log.log | tee >(php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=4 --app=testAppMemory --tags=host=server39 --tags=role=cli --memory) >(php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=4 --app=testApp --tags=host=server39 --tags=role=cli) >/dev/null

Plugins

  1. Create .php plugin class. Put it in any place. Make sure it has namespace Zoon\PyroSpy\Plugins; and classname match filename.
<?php

namespace Zoon\PyroSpy\Plugins;

class MyAwesomePlugin implements PluginInterface {

    public function process(array $tags, array $trace): array {
        //Modify tags and/or trace

        return [$tags, $trace];
    }
}

Multiple plugins can be provided. Each plugin will get tags and trace from results of the previous.

  1. Add --request-info=QCuP to phpspy args, to add uri string to tags.
  2. Provide full path to it in pyrospy arguments.
  3. To ignore a trace, return an empty trace.

Example:

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=100 --rate-hz=25 --buffer-size=65536 -J m -P '-x "php-fpm|php-fpm[0-9]\.[0-9]" | shuf' --request-info=QCuP 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=25 --app=testApp --tags=host=server39 --tags=role=web --plugins=/zoon/pyrospy/app/Plugins/ClearEmptyTags.php
View on GitHub
GitHub Stars25
CategoryDevelopment
Updated3mo ago
Forks3

Languages

PHP

Security Score

92/100

Audited on Dec 19, 2025

No findings