-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci_visibility): introduce experimental internal coverage collec…
…tor (#8727) Introduces the `ModuleCodeCollector` which collects coverage and executable lines for imported modules. The collector has two modes, one that stores executed lines on the singleton instance, and one that uses context variables and a context manager. This also introduces changes to the `pytest` integration as well as the `CIVisibility` service's use of coverage to feature-flag using the new module collector. The features are gated behind `_DD_USE_INTERNAL_COVERAGE` and `_DD_COVER_SESSION` (which introduces a new `coverage run` like behavior). There are no unit tests though the overall use of the feature flags has been tested quite extensively in the process of collecting performance data. There are no release notes since this is an entirely undocumented feature for the moment. ## Checklist - [x] Change(s) are motivated and described in the PR description - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. - [x] If change touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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) --------- Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]>
- Loading branch information
1 parent
f53484d
commit 66b96e9
Showing
14 changed files
with
716 additions
and
4 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Empty file.
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,61 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
|
||
#if PY_VERSION_HEX < 0x030c0000 | ||
#if defined __GNUC__ && defined HAVE_STD_ATOMIC | ||
#undef HAVE_STD_ATOMIC | ||
#endif | ||
#endif | ||
|
||
// ---------------------------------------------------------------------------- | ||
static PyObject* | ||
replace_in_tuple(PyObject* m, PyObject* args) | ||
{ | ||
PyObject* tuple = NULL; | ||
PyObject* item = NULL; | ||
PyObject* replacement = NULL; | ||
|
||
if (!PyArg_ParseTuple(args, "O!OO", &PyTuple_Type, &tuple, &item, &replacement)) | ||
return NULL; | ||
|
||
for (Py_ssize_t i = 0; i < PyTuple_Size(tuple); i++) { | ||
PyObject* current = PyTuple_GetItem(tuple, i); | ||
if (current == item) { | ||
Py_DECREF(current); | ||
// !!! DANGER !!! | ||
PyTuple_SET_ITEM(tuple, i, replacement); | ||
Py_INCREF(replacement); | ||
} | ||
} | ||
|
||
Py_RETURN_NONE; | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
static PyMethodDef native_methods[] = { | ||
{ "replace_in_tuple", replace_in_tuple, METH_VARARGS, "Replace an item in a tuple." }, | ||
{ NULL, NULL, 0, NULL } /* Sentinel */ | ||
}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
static struct PyModuleDef nativemodule = { | ||
PyModuleDef_HEAD_INIT, | ||
"_native", /* name of module */ | ||
NULL, /* module documentation, may be NULL */ | ||
-1, /* size of per-interpreter state of the module, | ||
or -1 if the module keeps state in global variables. */ | ||
native_methods, | ||
}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
PyMODINIT_FUNC | ||
PyInit__native(void) | ||
{ | ||
PyObject* m; | ||
|
||
m = PyModule_Create(&nativemodule); | ||
if (m == NULL) | ||
return NULL; | ||
|
||
return m; | ||
} |
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,3 @@ | ||
import typing as t | ||
|
||
def replace_in_tuple(tup: tuple, item: t.Any, replacement: t.Any) -> None: ... |
Oops, something went wrong.