-
Notifications
You must be signed in to change notification settings - Fork 70
refactor(agent): optimize user function instrumentation lookup for PHPs 8.0+ #1042
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The op_array extension slot for function is not available until function's first call. Check if op_array extension slot is initialized before using it to store wraprec.
Implement wraprec lookup by scope and function name. The implementation uses two specialized hashmaps: one for global functions and another one for scopes. The scopes hashmap's values are hashmaps for scoped methods. The hashmaps use keys composed of not only the string and its length but also zend string's hash. This hash is used to find the bucket index. The decision to include zend string's hash was deliberate because the agent gets it for free when it needs to lookup the wraprec based on scope and function name that are available in execute_data's op array as zend_strings.
|
When function is wrapped before its first use, its runtime cache is not yet initialized - it gets initialized on first function execution. However, the agent sometimes wraps functions before their execution. This type of use case requires the agent to initialize function's runtime cache.
New method of storing named wraprecs requires the name of the method to be wrapped to be in the case matching the code, i.e. wraprec name matching is case sensitive.
Take advantage of observer API and new method of storing wraprecs and don't install fcall_begin/fcall_end handlers for file execution - detect library/ framework and install wraprecs right in fcall_init!
Fix build for PHPs <= 7.4 - the name of variable pointing to linked list of wraprecs for PHPs <= 7.4 is `nr_wrapped_user_functions`.
With new way of storing named wraprecs, agent's instrumentation no longer depends on classes being loaded.
6223b1a
to
1ee6486
Compare
bf28488
to
998970b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1042 +/- ##
==========================================
+ Coverage 77.14% 77.26% +0.11%
==========================================
Files 198 199 +1
Lines 27991 28285 +294
==========================================
+ Hits 21593 21853 +260
- Misses 6398 6432 +34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Make it possible for wraprecs to be created when INI is processed. For that to be possible, two things are necessary: - the wraprec hashmap needs to be created before INI processing starts - the pid stored in wraprec needs to be set using the value returned by nr_getpid because per request global pid (NRPRG(pid)) is not initialized until rinit.
lavarou
commented
Apr 2, 2025
lavarou
commented
Apr 2, 2025
`doRun` method is not defined in `Illuminate\Console\Application` scope. It is defined in `Symfony\Component\Console\Application` scope.
zsistla
reviewed
Apr 15, 2025
zsistla
reviewed
Apr 15, 2025
zsistla
reviewed
Apr 15, 2025
zsistla
reviewed
Apr 15, 2025
This is not supported for PHPs < 7.4
Force non-zero duration for the segment not to be dropped (applied 3b30afd).
mfulb
reviewed
May 5, 2025
mfulb
reviewed
May 5, 2025
mfulb
reviewed
May 5, 2025
mfulb
reviewed
May 5, 2025
The only way nr_php_user_instrument_wraprec_hashmap_init can fail is when memory cannot be allocated, which is already considered a fatal error and causes php process to exit so there's no point in returning failure status in such case. Additionally, nrl_* (logging) does not work until INI has been processed so the error message wouldn't get logged anyway.
26ed257
to
8abf1eb
Compare
zsistla
reviewed
May 8, 2025
zsistla
reviewed
May 8, 2025
zsistla
reviewed
May 8, 2025
zsistla
previously approved these changes
May 8, 2025
mfulb
previously approved these changes
May 8, 2025
zsistla
previously approved these changes
May 8, 2025
zsistla
approved these changes
May 8, 2025
mfulb
approved these changes
May 8, 2025
hahuja2
pushed a commit
that referenced
this pull request
Jul 9, 2025
…Ps 8.0+ (#1042) Reduce agent’s CPU overhead when observer API is used to hook into Zend Engine. This is achieved by: * Simplifying the checks the agent needs to perform to determine if special instrumentation for user function is provided. Before this change, on every function execution the agent used a hashmap to check if special instrumentation for user function is provided. However, when the observer API is used to hook into Zend Engine, this can be done only once per user function execution at the time when the user function is executed for the first time. * Reducing the number of times the name of the file is compared with the list of ‘magic files’ to detect package and/or framework used. Before this change on every file execution the agent scanned the list of magic files twice. However, when the observer API is used to hook into Zend Engine, this can be done only once per file execution. --------- Co-authored-by: Amber Sistla <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reduce agent’s CPU overhead when observer API is used to hook into Zend Engine. This is achieved by: