1010)
1111def test_copy_memory_error_count_present ():
1212 """copy_memory_error_count is always emitted (even when 0) and is non-negative."""
13- import glob
1413 import json
1514 import os
1615 import time
1716
1817 from ddtrace .profiling import profiler
1918 from ddtrace .trace import tracer
19+ from tests .profiling .collector import pprof_utils
2020
2121 p = profiler .Profiler (tracer = tracer )
2222 p .start ()
2323 time .sleep (3 )
2424 p .stop ()
2525
2626 output_filename = os .environ ["DD_PROFILING_OUTPUT_PPROF" ] + "." + str (os .getpid ())
27- files = sorted ( glob . glob (output_filename + ".*.internal_metadata.json" ) )
27+ files = pprof_utils . get_internal_metadata_files (output_filename )
2828 assert files , "Expected at least one internal_metadata.json file"
2929
3030 for f in files :
@@ -51,25 +51,21 @@ def test_copy_memory_error_count_present():
5151)
5252def test_fast_copy_memory_disabled ():
5353 """fast_copy_memory_enabled is False when _DD_PROFILING_STACK_FAST_COPY=false."""
54- import glob
5554 import json
5655 import os
5756 import time
5857
5958 from ddtrace .profiling import profiler
6059 from ddtrace .trace import tracer
60+ from tests .profiling .collector import pprof_utils
6161
6262 p = profiler .Profiler (tracer = tracer )
6363 p .start ()
6464 time .sleep (3 )
6565 p .stop ()
6666
67- def upload_seq (path : str ) -> int :
68- # Uploads are numbered without padding, so sort numerically rather than lexicographically.
69- return int (path [: - len (".internal_metadata.json" )].rsplit ("." , 1 )[1 ])
70-
7167 output_filename = os .environ ["DD_PROFILING_OUTPUT_PPROF" ] + "." + str (os .getpid ())
72- files = sorted ( glob . glob (output_filename + ".*.internal_metadata.json" ), key = upload_seq )
68+ files = pprof_utils . get_internal_metadata_files (output_filename )
7369 assert files , "Expected at least one internal_metadata.json file"
7470
7571 for i , f in enumerate (files ):
@@ -95,7 +91,6 @@ def upload_seq(path: str) -> int:
9591)
9692def test_fast_copy_memory_enabled () -> None :
9793 """Sampler runs on the syscall copy during warmup, then upgrades to safe_memcpy (PROF-14568)."""
98- import glob
9994 import json
10095 import os
10196 import time
@@ -104,6 +99,7 @@ def test_fast_copy_memory_enabled() -> None:
10499 from ddtrace .internal .datadog .profiling .stack import _stack
105100 from ddtrace .profiling import profiler
106101 from ddtrace .trace import tracer
102+ from tests .profiling .collector import pprof_utils
107103
108104 _stack ._set_fast_copy_warmup_seconds (1.0 )
109105
@@ -134,12 +130,8 @@ def test_fast_copy_memory_enabled() -> None:
134130 time .sleep (2 )
135131 p .stop ()
136132
137- def upload_seq (path : str ) -> int :
138- # Uploads are numbered without padding, so sort numerically rather than lexicographically.
139- return int (path [: - len (".internal_metadata.json" )].rsplit ("." , 1 )[1 ])
140-
141133 output_filename = os .environ ["DD_PROFILING_OUTPUT_PPROF" ] + "." + str (os .getpid ())
142- files = sorted ( glob . glob (output_filename + ".*.internal_metadata.json" ), key = upload_seq )
134+ files = pprof_utils . get_internal_metadata_files (output_filename )
143135 assert files , "Expected at least one internal_metadata.json file"
144136
145137 # A window with no completed sampling cycle inherits the previous window's fast-copy
0 commit comments