Giter Club home page Giter Club logo

php-8-tracing-hooks's Introduction

php-8-tracing-hooks

Low-overhead tracing hooks for PHP 8

php-8-tracing-hooks's People

Contributors

sammyk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

php-8-tracing-hooks's Issues

Declaring instrumented functions runtime

Hello,

Apologies if me dropping in and drafting this issue seems weird. I am a big fan of how tracing can help with managing an application in production and would like to help out with adding first-class tracing hooks to PHP.

In the past I've used the OpenCensus extension to export tracing data to a managed service. This extension leaves a lot to be desired, but one thing it got right in my opinion - ability to declare instrumented function at runtime.

For example, one can declare a traced function and add attributes to it in PHP:

opencensus_trace_function('curl_exec', fn ($resource) => ['attributes' => ['url' => curl_getinfo($resource, CURLINFO_EFFECTIVE_URL)]]);

This is very powerful, in my opinion. If this functionality was available in PHP core, many open source frameworks and libraries could provide automatic instrumentation of their code. Think Symfony automatically instrumenting cache calls or Doctrine - DB calls.

I've researched php-src to find an appropriate place to call code which would instrument selected functions - both internal and user-land.

Since I am very new to php-src and have no C coding experience, so far I haven't gotten anywhere.

I've looked into zend_execute_ex and zend_execute_internal and tried to find where they are called. I've also stumbled upon ZEND_VM_HOT_HANDLER(130, ZEND_DO_UCALL, ANY, ANY, SPEC(RETVAL)).

Could you point me in the right direction: where would it make sense to call code that instruments a function? Or is the only way to override function pointers? Is declaring instrumented function runtime even a viable feature?

Thanks for your time and everything you do for the PHP community!

Notes from phpbnl discussion with Nikita

split up engine improvements in two parts

  • additional functionality besides zend_execute_ex for instrumenting ALL function calls

    • before/after userland function call chain
    • extensions should allocate own stack, use array of frames and increment/decrement
    • support for zend vm stack? complicated
  • instrument specific function calls

    • internal: keep overwriting handlers like we do now, already the most optimal solution
    • userland:
      - add hook into engine when "function is emitted" from parsing that allows set flag on zend_function. This flag could be checked to prevent JIT-ing the function.
      • on method call with instrumentation flag set: iterate over list of extension handlers (or use chain?)
      • again, could we let extensions manage their stack (simpler from engine pov)
      • downside: your hook gets called even when only other extension registers on it.
int should_instrument(zend_function *function) {
	funciton->flags |= ZEND_INSTURMENTED;
}

Own Stack vs VM Stack:

  • problem with allocating space on VM stack, its actually not so easy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.