-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(profiling): more tests for libdd and stack_v2 (#11679)
First copied files from tests/profiling folder, and then modified them as needed. Tests checking for agent export urls are dropped. libdd exporter is created with agent url passed from tracer state whenever we try to upload, see [feat(profiling): support dynamic agent url](#11319) These tests will be run under libdd_enabled and some of them had been edited to also run under stack_v2 enabled ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
- Loading branch information
1 parent
42f69dc
commit 4beaa01
Showing
10 changed files
with
850 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import time | ||
|
||
from ddtrace.internal import service | ||
from ddtrace.profiling import bootstrap | ||
from ddtrace.profiling.collector import stack | ||
|
||
|
||
for running_collector in bootstrap.profiler._profiler._collectors: | ||
if isinstance(running_collector, stack.StackCollector): | ||
break | ||
else: | ||
raise AssertionError("Unable to find stack collector") | ||
|
||
|
||
print("hello world") | ||
assert running_collector.status == service.ServiceStatus.RUNNING | ||
print(running_collector.interval) | ||
|
||
t0 = time.time() | ||
while time.time() - t0 < (running_collector.interval * 10): | ||
pass | ||
|
||
# Do some serious memory allocations! | ||
for _ in range(5000000): | ||
object() | ||
|
||
print(os.getpid()) | ||
print(bootstrap.profiler._profiler._stack_v2_enabled) | ||
sys.exit(42) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import sys | ||
import threading | ||
|
||
from ddtrace.internal import service | ||
import ddtrace.profiling.auto | ||
import ddtrace.profiling.bootstrap | ||
import ddtrace.profiling.profiler | ||
|
||
|
||
lock = threading.Lock() | ||
lock.acquire() | ||
|
||
|
||
assert ddtrace.profiling.bootstrap.profiler.status == service.ServiceStatus.RUNNING | ||
|
||
|
||
child_pid = os.fork() | ||
if child_pid == 0: | ||
# Release it | ||
lock.release() | ||
|
||
# We track this one though | ||
lock = threading.Lock() | ||
lock.acquire() | ||
lock.release() | ||
else: | ||
lock.release() | ||
assert ddtrace.profiling.bootstrap.profiler.status == service.ServiceStatus.RUNNING | ||
print(child_pid) | ||
pid, status = os.waitpid(child_pid, 0) | ||
sys.exit(os.WEXITSTATUS(status)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Import from ddtrace before monkey patching to ensure that we grab all the | ||
# necessary references to the unpatched modules. | ||
import ddtrace.auto # noqa: F401, I001 | ||
import ddtrace.profiling.auto # noqa:F401 | ||
|
||
|
||
import gevent.monkey # noqa:F402 | ||
|
||
gevent.monkey.patch_all() | ||
|
||
import threading # noqa: E402, F402, I001 | ||
import time # noqa: E402, F402 | ||
|
||
|
||
def fibonacci(n): | ||
if n == 0: | ||
return 0 | ||
elif n == 1: | ||
return 1 | ||
else: | ||
return fibonacci(n - 1) + fibonacci(n - 2) | ||
|
||
|
||
i = 1 | ||
for _ in range(20): | ||
threads = [] | ||
for _ in range(10): | ||
t = threading.Thread(target=fibonacci, args=(i,)) | ||
t.start() | ||
threads.append(t) | ||
i += 1 | ||
for t in threads: | ||
t.join() | ||
time.sleep(0.1) |
Oops, something went wrong.