Skip to content

Commit 167e4bd

Browse files
committed
chore(profiler): remove remaining max_events config stuff
DD_PROFILING_MAX_EVENTS doesn't do anything since #13988. This commit just cleans up some remaining references we missed.
1 parent c5213ff commit 167e4bd

File tree

7 files changed

+26
-53
lines changed

7 files changed

+26
-53
lines changed

ddtrace/profiling/collector/_memalloc.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ typedef struct
1717
PyMemAllocatorEx pymem_allocator_obj;
1818
/* The domain we are tracking */
1919
PyMemAllocatorDomain domain;
20-
/* The maximum number of events for allocation tracking */
21-
uint16_t max_events;
2220
/* The maximum number of frames collected in stack traces */
2321
uint16_t max_nframe;
2422

@@ -93,15 +91,16 @@ memalloc_realloc(void* ctx, void* ptr, size_t new_size)
9391
}
9492

9593
PyDoc_STRVAR(memalloc_start__doc__,
96-
"start($module, max_nframe, max_events, heap_sample_size)\n"
94+
"start($module, max_nframe, heap_sample_interval)\n"
9795
"--\n"
9896
"\n"
9997
"Start tracing Python memory allocations.\n"
10098
"\n"
10199
"Sets the maximum number of frames stored in the traceback of a\n"
102-
"trace to max_nframe and the maximum number of events to max_events.\n"
103-
"Set heap_sample_size to the granularity of the heap profiler, in bytes.\n"
104-
"If heap_sample_size is set to 0, it is disabled entirely.\n");
100+
"trace to max_nframe.\n"
101+
"Sets the average number of bytes allocated between samples to\n"
102+
"heap_sample_interval.\n"
103+
"If heap_sample_interval is set to 0, it is disabled entirely.\n");
105104
static PyObject*
106105
memalloc_start(PyObject* Py_UNUSED(module), PyObject* args)
107106
{
@@ -117,11 +116,11 @@ memalloc_start(PyObject* Py_UNUSED(module), PyObject* args)
117116
srand(atoi(val));
118117
}
119118

120-
long max_nframe, max_events;
119+
long max_nframe;
121120
long long int heap_sample_size;
122121

123122
/* Store short ints in ints so we're sure they fit */
124-
if (!PyArg_ParseTuple(args, "llL", &max_nframe, &max_events, &heap_sample_size))
123+
if (!PyArg_ParseTuple(args, "lL", &max_nframe, &heap_sample_size))
125124
return NULL;
126125

127126
if (max_nframe < 1 || max_nframe > TRACEBACK_MAX_NFRAME) {
@@ -131,13 +130,6 @@ memalloc_start(PyObject* Py_UNUSED(module), PyObject* args)
131130

132131
global_memalloc_ctx.max_nframe = (uint16_t)max_nframe;
133132

134-
if (max_events < 1 || max_events > TRACEBACK_ARRAY_MAX_COUNT) {
135-
PyErr_Format(PyExc_ValueError, "the number of events must be in range [1; %u]", TRACEBACK_ARRAY_MAX_COUNT);
136-
return NULL;
137-
}
138-
139-
global_memalloc_ctx.max_events = (uint16_t)max_events;
140-
141133
if (heap_sample_size < 0 || heap_sample_size > MAX_HEAP_SAMPLE_SIZE) {
142134
PyErr_Format(PyExc_ValueError, "the heap sample size must be in range [0; %u]", MAX_HEAP_SAMPLE_SIZE);
143135
return NULL;

ddtrace/profiling/collector/_memalloc.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ StackType = event.StackTraceType
99
# (stack, thread_id)
1010
TracebackType = typing.Tuple[StackType, int]
1111

12-
def start(max_nframe: int, max_events: int, heap_sample_size: int) -> None: ...
12+
def start(max_nframe: int, heap_sample_interval: int) -> None: ...
1313
def stop() -> None: ...
1414
def heap() -> typing.List[typing.Tuple[TracebackType, int, int, int]]: ...

ddtrace/profiling/collector/memalloc.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,14 @@
3030
class MemoryCollector(collector.PeriodicCollector):
3131
"""Memory allocation collector."""
3232

33-
_DEFAULT_MAX_EVENTS = 16
34-
_DEFAULT_INTERVAL = 0.5
35-
3633
def __init__(
3734
self,
38-
_interval: float = _DEFAULT_INTERVAL,
39-
_max_events: Optional[int] = None,
4035
max_nframe: Optional[int] = None,
4136
heap_sample_size: Optional[int] = None,
4237
ignore_profiler: Optional[bool] = None,
4338
):
4439
super().__init__()
45-
self._interval: float = _interval
4640
# TODO make this dynamic based on the 1. interval and 2. the max number of events allowed in the Recorder
47-
self._max_events: int = _max_events if _max_events is not None else config.memory.events_buffer
4841
self.max_nframe: int = max_nframe if max_nframe is not None else config.max_frames
4942
self.heap_sample_size: int = heap_sample_size if heap_sample_size is not None else config.heap.sample_size
5043
self.ignore_profiler: bool = ignore_profiler if ignore_profiler is not None else config.ignore_profiler
@@ -56,13 +49,13 @@ def _start_service(self):
5649
raise collector.CollectorUnavailable
5750

5851
try:
59-
_memalloc.start(self.max_nframe, self._max_events, self.heap_sample_size)
52+
_memalloc.start(self.max_nframe, self.heap_sample_size)
6053
except RuntimeError:
6154
# This happens on fork because we don't call the shutdown hook since
6255
# the thread responsible for doing so is not running in the child
6356
# process. Therefore we stop and restart the collector instead.
6457
_memalloc.stop()
65-
_memalloc.start(self.max_nframe, self._max_events, self.heap_sample_size)
58+
_memalloc.start(self.max_nframe, self.heap_sample_size)
6659

6760
super(MemoryCollector, self)._start_service()
6861

ddtrace/settings/profiling.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ class ProfilingConfig(DDConfig):
155155
help="",
156156
)
157157

158-
max_events = DDConfig.v(
159-
int,
160-
"max_events",
161-
default=16384,
162-
help_type="Integer",
163-
help="",
164-
)
165-
166158
upload_interval = DDConfig.v(
167159
float,
168160
"upload_interval",
@@ -339,7 +331,7 @@ class ProfilingConfigHeap(DDConfig):
339331
"sample_size",
340332
default=None,
341333
help_type="Integer",
342-
help="",
334+
help="Average number of bytes allocated between memory profiler samples",
343335
)
344336
sample_size = DDConfig.d(int, _derive_default_heap_sample_size)
345337

tests/profiling/collector/test_memalloc.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,37 @@
1919

2020

2121
def test_start_twice():
22-
_memalloc.start(64, 1000, 512)
22+
_memalloc.start(64, 512)
2323
with pytest.raises(RuntimeError):
24-
_memalloc.start(64, 1000, 512)
24+
_memalloc.start(64, 512)
2525
_memalloc.stop()
2626

2727

2828
def test_start_wrong_arg():
29-
with pytest.raises(TypeError, match="function takes exactly 3 arguments \\(1 given\\)"):
29+
with pytest.raises(TypeError, match="function takes exactly 2 arguments \\(1 given\\)"):
3030
_memalloc.start(2)
3131

3232
with pytest.raises(ValueError, match="the number of frames must be in range \\[1; 65535\\]"):
33-
_memalloc.start(429496, 1000, 1)
33+
_memalloc.start(429496, 1)
3434

3535
with pytest.raises(ValueError, match="the number of frames must be in range \\[1; 65535\\]"):
36-
_memalloc.start(-1, 1000, 1)
37-
38-
with pytest.raises(ValueError, match="the number of events must be in range \\[1; 65535\\]"):
39-
_memalloc.start(64, -1, 1)
36+
_memalloc.start(-1, 1)
4037

4138
with pytest.raises(
4239
ValueError,
4340
match="the heap sample size must be in range \\[0; 4294967295\\]",
4441
):
45-
_memalloc.start(64, 1000, -1)
42+
_memalloc.start(64, -1)
4643

4744
with pytest.raises(
4845
ValueError,
4946
match="the heap sample size must be in range \\[0; 4294967295\\]",
5047
):
51-
_memalloc.start(64, 1000, 345678909876)
48+
_memalloc.start(64, 345678909876)
5249

5350

5451
def test_start_stop():
55-
_memalloc.start(1, 1, 1)
52+
_memalloc.start(1, 1)
5653
_memalloc.stop()
5754

5855

@@ -69,7 +66,7 @@ def _pre_allocate_1k():
6966

7067
def test_iter_events():
7168
max_nframe = 32
72-
collector = memalloc.MemoryCollector(max_nframe=max_nframe, _max_events=10000, heap_sample_size=64)
69+
collector = memalloc.MemoryCollector(max_nframe=max_nframe, heap_sample_size=64)
7370
with collector:
7471
_allocate_1k()
7572
samples = collector.test_snapshot()
@@ -105,7 +102,7 @@ def test_iter_events():
105102

106103
def test_iter_events_dropped():
107104
max_nframe = 32
108-
collector = memalloc.MemoryCollector(max_nframe=max_nframe, _max_events=100, heap_sample_size=64)
105+
collector = memalloc.MemoryCollector(max_nframe=max_nframe, heap_sample_size=64)
109106
with collector:
110107
_allocate_1k()
111108
samples = collector.test_snapshot()
@@ -130,7 +127,7 @@ def test_iter_events_not_started():
130127
def test_iter_events_multi_thread():
131128
max_nframe = 32
132129
t = threading.Thread(target=_allocate_1k)
133-
collector = memalloc.MemoryCollector(max_nframe=max_nframe, _max_events=10000, heap_sample_size=64)
130+
collector = memalloc.MemoryCollector(max_nframe=max_nframe, heap_sample_size=64)
134131
with collector:
135132
_allocate_1k()
136133
t.start()
@@ -179,7 +176,7 @@ def test_iter_events_multi_thread():
179176

180177
def test_heap():
181178
max_nframe = 32
182-
collector = memalloc.MemoryCollector(max_nframe=max_nframe, _max_events=10000, heap_sample_size=1024)
179+
collector = memalloc.MemoryCollector(max_nframe=max_nframe, heap_sample_size=1024)
183180
with collector:
184181
_test_heap_impl(collector, max_nframe)
185182

@@ -298,7 +295,7 @@ def _test_heap_impl(collector, max_nframe):
298295

299296
def test_heap_stress():
300297
# This should run for a few seconds, and is enough to spot potential segfaults.
301-
_memalloc.start(64, 64, 1024)
298+
_memalloc.start(64, 1024)
302299
try:
303300
x = []
304301

tests/profiling_v2/collector/test_memalloc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_heap_profiler_sampling_accuracy(sample_interval):
254254
# pass for an arbitrary seed.
255255
old = os.environ.get("_DD_MEMALLOC_DEBUG_RNG_SEED")
256256
os.environ["_DD_MEMALLOC_DEBUG_RNG_SEED"] = "42"
257-
_memalloc.start(32, 1000, sample_interval)
257+
_memalloc.start(32, sample_interval)
258258
# Put the env var back in the state we found it
259259
if old is not None:
260260
os.environ["_DD_MEMALLOC_DEBUG_RNG_SEED"] = old
@@ -679,7 +679,7 @@ def test_memory_collector_allocation_during_shutdown():
679679

680680
from ddtrace.profiling.collector import _memalloc
681681

682-
_memalloc.start(32, 1000, 512)
682+
_memalloc.start(32, 512)
683683

684684
shutdown_event = threading.Event()
685685
allocation_thread = None

tests/telemetry/test_writer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ def test_app_started_event_configuration_override(test_agent_session, run_python
436436
{"name": "DD_PROFILING_IGNORE_PROFILER", "origin": "default", "value": False},
437437
{"name": "DD_PROFILING_LOCK_ENABLED", "origin": "env_var", "value": False},
438438
{"name": "DD_PROFILING_LOCK_NAME_INSPECT_DIR", "origin": "default", "value": True},
439-
{"name": "DD_PROFILING_MAX_EVENTS", "origin": "default", "value": 16384},
440439
{"name": "DD_PROFILING_MAX_FRAMES", "origin": "env_var", "value": 512},
441440
{"name": "DD_PROFILING_MAX_TIME_USAGE_PCT", "origin": "default", "value": 1.0},
442441
{"name": "DD_PROFILING_MEMORY_ENABLED", "origin": "env_var", "value": False},

0 commit comments

Comments
 (0)