|
7 | 7 | import uuid |
8 | 8 |
|
9 | 9 | import pytest |
10 | | -from tests.profiling_v2.collector import test_collector |
11 | 10 |
|
12 | 11 | from ddtrace import ext |
13 | 12 | from ddtrace.internal.datadog.profiling import ddup |
14 | 13 | from ddtrace.profiling.collector import stack |
15 | 14 | from tests.conftest import get_original_test_name |
16 | 15 | from tests.profiling_v2.collector import pprof_utils |
| 16 | +from tests.profiling_v2.collector import test_collector |
17 | 17 |
|
18 | 18 |
|
19 | 19 | # Python 3.11.9 is not compatible with gevent, https://github.com/gevent/gevent/issues/2040 |
|
25 | 25 | ) |
26 | 26 |
|
27 | 27 |
|
| 28 | +def func1(): |
| 29 | + return func2() |
| 30 | + |
| 31 | + |
| 32 | +def func2(): |
| 33 | + return func3() |
| 34 | + |
| 35 | + |
| 36 | +def func3(): |
| 37 | + return func4() |
| 38 | + |
| 39 | + |
| 40 | +def func4(): |
| 41 | + return func5() |
| 42 | + |
| 43 | + |
| 44 | +def func5(): |
| 45 | + return time.sleep(1) |
| 46 | + |
| 47 | + |
28 | 48 | # Use subprocess as ddup config persists across tests. |
29 | 49 | @pytest.mark.subprocess( |
30 | 50 | env=dict( |
|
35 | 55 | def test_collect_truncate(): |
36 | 56 | import os |
37 | 57 |
|
38 | | - from tests.profiling_v2.collector.test_stack import func1 |
39 | | - |
40 | 58 | from ddtrace.profiling import profiler |
41 | 59 | from tests.profiling_v2.collector import pprof_utils |
| 60 | + from tests.profiling_v2.collector.test_stack import func1 |
42 | 61 |
|
43 | 62 | pprof_prefix = os.environ["DD_PROFILING_OUTPUT_PPROF"] |
44 | 63 | output_filename = pprof_prefix + "." + str(os.getpid()) |
@@ -830,79 +849,3 @@ def _trace(): |
830 | 849 |
|
831 | 850 | for t in threads: |
832 | 851 | t.join() |
833 | | - |
834 | | - |
835 | | -@pytest.mark.skipif(not TESTING_GEVENT or sys.version_info < (3, 9), reason="Not testing gevent") |
836 | | -@pytest.mark.subprocess(ddtrace_run=True) |
837 | | -def test_collect_gevent_threads(): |
838 | | - import gevent.monkey |
839 | | - |
840 | | - gevent.monkey.patch_all() |
841 | | - |
842 | | - import os |
843 | | - import threading |
844 | | - import time |
845 | | - |
846 | | - from ddtrace.internal.datadog.profiling import ddup |
847 | | - from ddtrace.profiling.collector import stack |
848 | | - from tests.profiling_v2.collector import pprof_utils |
849 | | - |
850 | | - iteration = 100 |
851 | | - sleep_time = 0.01 |
852 | | - nb_threads = 15 |
853 | | - |
854 | | - # Start some greenthreads: they do nothing we just keep switching between them. |
855 | | - def _nothing(): |
856 | | - for _ in range(iteration): |
857 | | - # Do nothing and just switch to another greenlet |
858 | | - time.sleep(sleep_time) |
859 | | - |
860 | | - test_name = "test_collect_gevent_threads" |
861 | | - pprof_prefix = "/tmp/" + test_name |
862 | | - output_filename = pprof_prefix + "." + str(os.getpid()) |
863 | | - |
864 | | - assert ddup.is_available |
865 | | - ddup.config(env="test", service="test_collect_gevent_threads", version="my_version", output_filename=pprof_prefix) |
866 | | - ddup.start() |
867 | | - |
868 | | - with stack.StackCollector(): |
869 | | - threads = [] |
870 | | - i_to_tid = {} |
871 | | - for i in range(nb_threads): |
872 | | - t = threading.Thread(target=_nothing, name="TestThread %d" % i) |
873 | | - i_to_tid[i] = t.ident |
874 | | - t.start() |
875 | | - threads.append(t) |
876 | | - for t in threads: |
877 | | - t.join() |
878 | | - |
879 | | - ddup.upload() |
880 | | - |
881 | | - profile = pprof_utils.parse_newest_profile(output_filename) |
882 | | - samples = pprof_utils.get_samples_with_label_key(profile, "task name") |
883 | | - assert len(samples) > 0 |
884 | | - |
885 | | - for task_id in range(nb_threads): |
886 | | - pprof_utils.assert_profile_has_sample( |
887 | | - profile, |
888 | | - samples, |
889 | | - expected_sample=pprof_utils.StackEvent( |
890 | | - task_name="TestThread %d" % task_id, |
891 | | - task_id=i_to_tid[task_id], |
892 | | - thread_id=i_to_tid[task_id], |
893 | | - locations=[ |
894 | | - pprof_utils.StackLocation( |
895 | | - filename="test_stack.py", |
896 | | - function_name="_nothing", |
897 | | - line_no=_nothing.__code__.co_firstlineno + 3, |
898 | | - ) |
899 | | - ], |
900 | | - ), |
901 | | - ) |
902 | | - pprof_utils.assert_profile_has_sample( |
903 | | - profile, |
904 | | - samples, |
905 | | - expected_sample=pprof_utils.StackEvent( |
906 | | - task_name="MainThread", |
907 | | - ), |
908 | | - ) |
0 commit comments