|
45 | 45 | "process.runtime.cpu.time": ["user", "system"],
|
46 | 46 | "process.runtime.gc_count": None,
|
47 | 47 | "cpython.gc.collections": None,
|
| 48 | + "cpython.gc.collected_objects": None, |
| 49 | + "cpython.gc.uncollectable_objects": None, |
48 | 50 | "process.runtime.thread_count": None,
|
49 | 51 | "process.runtime.cpu.utilization": None,
|
50 | 52 | "process.runtime.context_switches": ["involuntary", "voluntary"],
|
|
138 | 140 | "process.runtime.cpu.time": ["user", "system"],
|
139 | 141 | "process.runtime.gc_count": None,
|
140 | 142 | "cpython.gc.collections": None,
|
| 143 | + "cpython.gc.collected_objects": None, |
| 144 | + "cpython.gc.uncollectable_objects": None, |
141 | 145 | "process.runtime.thread_count": None,
|
142 | 146 | "process.runtime.cpu.utilization": None,
|
143 | 147 | "process.runtime.context_switches": ["involuntary", "voluntary"],
|
@@ -199,6 +203,8 @@ def __init__(
|
199 | 203 | self._runtime_cpu_time_labels = self._labels.copy()
|
200 | 204 | self._runtime_gc_count_labels = self._labels.copy()
|
201 | 205 | self._runtime_gc_collections_labels = self._labels.copy()
|
| 206 | + self._runtime_gc_collected_objects_labels = self._labels.copy() |
| 207 | + self._runtime_gc_uncollectable_objects_labels = self._labels.copy() |
202 | 208 | self._runtime_thread_count_labels = self._labels.copy()
|
203 | 209 | self._runtime_cpu_utilization_labels = self._labels.copy()
|
204 | 210 | self._runtime_context_switches_labels = self._labels.copy()
|
@@ -486,6 +492,32 @@ def _instrument(self, **kwargs: Any):
|
486 | 492 | unit="{collection}",
|
487 | 493 | )
|
488 | 494 |
|
| 495 | + if "cpython.gc.collected_objects" in self._config: |
| 496 | + if self._python_implementation == "pypy": |
| 497 | + _logger.warning( |
| 498 | + "The cpython.gc.collected_objects metric won't be collected because the interpreter is PyPy" |
| 499 | + ) |
| 500 | + else: |
| 501 | + self._meter.create_observable_counter( |
| 502 | + name="cpython.gc.collected_objects", |
| 503 | + callbacks=[self._get_runtime_gc_collected_objects], |
| 504 | + description="The total number of objects collected since interpreter start.", |
| 505 | + unit="{object}", |
| 506 | + ) |
| 507 | + |
| 508 | + if "cpython.gc.uncollectable_objects" in self._config: |
| 509 | + if self._python_implementation == "pypy": |
| 510 | + _logger.warning( |
| 511 | + "The cpython.gc.uncollectable_objects metric won't be collected because the interpreter is PyPy" |
| 512 | + ) |
| 513 | + else: |
| 514 | + self._meter.create_observable_counter( |
| 515 | + name="cpython.gc.uncollectable_objects", |
| 516 | + callbacks=[self._get_runtime_gc_uncollectable_objects], |
| 517 | + description="The total number of uncollectable objects found since interpreter start.", |
| 518 | + unit="{object}", |
| 519 | + ) |
| 520 | + |
489 | 521 | if "process.runtime.thread_count" in self._config:
|
490 | 522 | self._meter.create_observable_up_down_counter(
|
491 | 523 | name=f"process.runtime.{self._python_implementation}.thread_count",
|
@@ -911,6 +943,32 @@ def _get_runtime_gc_collections(
|
911 | 943 | stat["collections"], self._runtime_gc_collections_labels.copy()
|
912 | 944 | )
|
913 | 945 |
|
| 946 | + def _get_runtime_gc_collected_objects( |
| 947 | + self, options: CallbackOptions |
| 948 | + ) -> Iterable[Observation]: |
| 949 | + """Observer callback for garbage collection collected objects""" |
| 950 | + for index, stat in enumerate(gc.get_stats()): |
| 951 | + self._runtime_gc_collected_objects_labels["generation"] = str( |
| 952 | + index |
| 953 | + ) |
| 954 | + yield Observation( |
| 955 | + stat["collected"], |
| 956 | + self._runtime_gc_collected_objects_labels.copy(), |
| 957 | + ) |
| 958 | + |
| 959 | + def _get_runtime_gc_uncollectable_objects( |
| 960 | + self, options: CallbackOptions |
| 961 | + ) -> Iterable[Observation]: |
| 962 | + """Observer callback for garbage collection uncollectable objects""" |
| 963 | + for index, stat in enumerate(gc.get_stats()): |
| 964 | + self._runtime_gc_uncollectable_objects_labels["generation"] = str( |
| 965 | + index |
| 966 | + ) |
| 967 | + yield Observation( |
| 968 | + stat["uncollectable"], |
| 969 | + self._runtime_gc_uncollectable_objects_labels.copy(), |
| 970 | + ) |
| 971 | + |
914 | 972 | def _get_runtime_thread_count(
|
915 | 973 | self, options: CallbackOptions
|
916 | 974 | ) -> Iterable[Observation]:
|
|
0 commit comments