-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from bozhodimitrov/main
Examples for episode 566 & 567
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
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,29 @@ | ||
# [ONE TERABYTE of RAM saved with a single line of code (advanced)](https://youtu.be/Hgw_RlCaIds) | ||
|
||
Today I show off a small change I made at work with huge impact and explain how it works! | ||
|
||
## Setup commands | ||
|
||
```bash | ||
git clone [email protected]:python/cpython | ||
# git clone https://github.com/python/cpython | ||
|
||
cd cpython | ||
``` | ||
|
||
## Interactive examples | ||
|
||
### Python | ||
|
||
```python | ||
import gc | ||
gc.freeze() | ||
``` | ||
|
||
### Bash | ||
|
||
```bash | ||
git grep 'typedef .* PyObject;' | ||
git grep 'struct _object' | ||
nano Include/object.h | ||
``` |
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,62 @@ | ||
# [using memray to debug (and fix) a memory leak in krb5! (advanced)](https://youtu.be/bw5AHdZA7e4) | ||
|
||
Today I show how I utilized memray to both find, debug, and ultimately fix a memory leak in krb5 -- sadly this was not the leak I was looking for though! | ||
|
||
## Setup commands | ||
|
||
```bash | ||
git clone [email protected]:getsentry/sentry | ||
# git clone https://github.com/getsentry/sentry | ||
cd sentry | ||
``` | ||
|
||
## Interactive examples | ||
|
||
### Bash | ||
|
||
Session 1: | ||
|
||
```bash | ||
python -m sentry run worker --queues counters-0 --concurrency 1 --max-tasks-per-child 1000000000 | ||
timeout --signal=SIGINT 10s memray run --quiet -m sentry run worker --queues counters-0 --concurrency 1 --max-tasks-per-child 1000000000 | ||
|
||
memray flamegraph --help | ||
memray flamegraph --leaks <memray_bin_filename> | ||
open <memray_flamegraph_html_filename> | ||
|
||
PYTHONMALLOC=malloc timeout --signal=SIGINT 10s memray run --follow-fork --quiet -m sentry run worker --queues counters-0 --concurrency 1 --max-tasks-per-child 1000000000 | ||
memray flamegraph --leaks <memray_bin_filename> | ||
open <memray_flamegraph_html_filename> | ||
|
||
PYTHONMALLOC=malloc timeout --signal=SIGINT 20s memray run --follow-fork --quiet -m sentry run worker --queues counters-0 --concurrency 1 --max-tasks-per-child 1000000000 | ||
memray flamegraph --leaks <memray_bin_filename> | ||
open <memray_flamegraph_html_filename> | ||
|
||
PYTHONMALLOC=malloc memray run -m t | ||
memray flamegraph --leaks <memray_bin_filename> | ||
open <memray_flamegraph_html_filename> | ||
|
||
PYTHONMALLOC=malloc memray run --native -m t | ||
memray flamegraph <memray_bin_filename> | ||
xdg-open <memray_flamegraph_html_filename> | ||
|
||
gcc $(PKG_CONFIG_PATH=<broken_version> pkg-config kbr5-gssapi --cflags --libs) t.c | ||
./a.out | ||
leaks --atExit -- ./a.out | ||
|
||
gcc $(PKG_CONFIG_PATH=<fixed_version> pkg-config kbr5-gssapi --cflags --libs) t.c | ||
./a.out | ||
leaks --atExit -- ./a.out | ||
``` | ||
|
||
Session 2: | ||
|
||
```bash | ||
sentry exec t.py | ||
``` | ||
|
||
Session 3: | ||
|
||
```bash | ||
htop --filter ' worker ' | ||
``` |
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,18 @@ | ||
#include <gssapi.h> | ||
|
||
int main(void) { | ||
for (int i = 0; i < 10; i += 1) { | ||
gss_cred_id_t cred = 0; | ||
OM_uint32 minor = 0; | ||
OM_uint32 ret = gss_acquire_cred( | ||
&minor, GSS_C_NO_NAME, 0, GSS_C_NO_OID_SET, | ||
GSS_C_INITIATE, &cred, NULL, NULL | ||
); | ||
if (ret == GSS_S_COMPLETE) { | ||
printf("no error\n"); | ||
gss_release_cred(&minor, &cred) | ||
} else { | ||
printf("got error: %d\n", ret) | ||
} | ||
} | ||
} |
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,21 @@ | ||
from sentry.buffer import backend | ||
from sentry.models.group import Group | ||
from sentry.models.organization import Organization | ||
from sentry.models.project import Project | ||
from sentry.models.release import Release | ||
from sentry.models.releases.release_project import ReleaseProject | ||
from sentry.models.team import Team | ||
|
||
|
||
group = Group.objects.create(project=Project(id=1)) | ||
org = Organization.objects.create(slug="test-org") | ||
team = Team.objects.create(organization=org, slug="test-team") | ||
project = Project.objects.create(organization=org, slug="test-project") | ||
project.add_team(team) | ||
release = Release.objects.create(organization=org, version="abcdefg") | ||
release_project = ReleaseProject.objects.create(project, release=release) | ||
|
||
while True: | ||
columns = {"times_seen": 1} | ||
filters = {"id": group.id, "project_id": 1} | ||
backend.incr(Group, columns, filters) |
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,9 @@ | ||
import psycopg2 | ||
|
||
|
||
def main(): | ||
for _ in range(10000): | ||
psycopg2.connect("user=postgres host=127.0.0.1 dbname=sentry").close() | ||
|
||
|
||
main() |