Skip to content

WIP: use a trampoline for FLF functions to intercept timings#3595

Draft
bwoebi wants to merge 18 commits intomasterfrom
bob/prof-flf-test
Draft

WIP: use a trampoline for FLF functions to intercept timings#3595
bwoebi wants to merge 18 commits intomasterfrom
bob/prof-flf-test

Conversation

@bwoebi
Copy link
Collaborator

@bwoebi bwoebi commented Jan 21, 2026

They don't check EG(vm_interrupt) by design, so we manually handle this.

@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from 1976c3c to 222e3a4 Compare January 21, 2026 17:19
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 21, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

❄️ 19 New flaky tests detected

profiling/tests/phpt/allocation_bind_static_01.phpt ([profiling] sampling shouldn't crash on `ZEND_BIND_STATIC` opcode) from php.profiling.tests.phpt (Datadog) (Fix with Cursor)
001- int(1)
002- string(1) "x"
003- int(1)
004- int(5)
001+
profiling/tests/phpt/allocation_func_get_args.phpt ([profiling] sampling shouldn't crash on `ZEND_FUNC_GET_ARGS` opcode) from php.profiling.tests.phpt (Datadog) (Fix with Cursor)
001- int(1)
002- string(1) "x"
003- int(1)
004- array(2) {
005-   [0]=>
006-   string(6) "string"
007-   [1]=>
008-   int(0)
009- }
010- Done.
...
profiling/tests/phpt/allocation_generator_01.phpt ([profiling] profiling should not crash during a `ZEND_GENERATOR_CREATE`) from php.profiling.tests.phpt (Datadog) (Fix with Cursor)
001- Fatal error: Allowed memory size of %d bytes exhausted %s
001+
View all

🧪 1032 Tests failed

    testSearchPhpBinaries from integration.DDTrace\Tests\Integration\PHPInstallerTest (Fix with Cursor)

    testSimplePushAndProcess from laravel-58-test.DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest (Fix with Cursor)

testSimplePushAndProcess from laravel-8x-test.DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest (Datadog) (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 6981d34e0000000061ef575b249f934c
tid: 6981d34e00000000
hexProcessTraceId: 61ef575b249f934c
hexProcessSpanId: b0b6779f5e325f1f
processTraceId: 7056955190080934732
processSpanId: 12733496522800520991
View all
This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ab68993 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.20%. Comparing base (9de150f) to head (ab68993).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3595      +/-   ##
==========================================
- Coverage   62.21%   62.20%   -0.02%     
==========================================
  Files         141      141              
  Lines       13387    13387              
  Branches     1753     1753              
==========================================
- Hits         8329     8327       -2     
- Misses       4260     4263       +3     
+ Partials      798      797       -1     

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9de150f...ab68993. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@morrisonlevi morrisonlevi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this can run afoul of permissions somehow, since we're making executable code at runtime? I'm not well versed here, and yes, if the JIT is enabled you'd have to have that capability anyway, but I'm trying to understand implications of this WIP.

@pr-commenter
Copy link

pr-commenter bot commented Jan 21, 2026

Benchmarks [ profiler ]

Benchmark execution time: 2026-02-03 11:00:07

Comparing candidate commit ab68993 in PR branch bob/prof-flf-test with baseline commit 9de150f in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 28 metrics, 8 unstable metrics.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from 222e3a4 to 0eb96ee Compare January 21, 2026 17:52
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from dc825a7 to c6bdefc Compare January 21, 2026 18:06
@bwoebi
Copy link
Collaborator Author

bwoebi commented Jan 21, 2026

@morrisonlevi dynasmrt takes care of setting RX permissions after compiling the code. As long as you're not running this under a hardened runtime (like app store apps or android (?)), there's no fundamental problem. Also I currently call assembler.finalize().unwrap() (which takes care of settign RX) - proper usage should just handle the potential error here and abort.

@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from 95f422a to 7471599 Compare January 21, 2026 18:17
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from 7471599 to 4358ab8 Compare January 21, 2026 18:24
dynasm!(assembler
; mov rax, QWORD original as i64
; call rax
; mov rax, QWORD interrupt_addr as i64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume original is not returning anything, because you're writing over RAX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

#[cfg(target_arch = "aarch64")]
dynasm!(assembler
; mov x16, original as u64
; blr x16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this overwrites x30/lr, aren't you gonna lose the original return location of the handler? so when br x16 returns, it goes back to calling interrupt_addr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. call on x86_64 pushes %eip to the stack, but blr doesn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up, is it correct now?

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from a3c79dc to 078acef Compare January 21, 2026 19:34
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch 2 times, most recently from e4930fe to 2604b22 Compare January 21, 2026 19:35
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from 2604b22 to 6307860 Compare January 21, 2026 19:38
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from a246940 to bcebfb0 Compare January 21, 2026 20:37
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/prof-flf-test branch from b0995bc to d9d3f43 Compare January 22, 2026 13:45
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

Successfully merging this pull request may close these issues.

5 participants