-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
668 additions
and
986 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
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 @@ | ||
[tools] | ||
python = "3.13.0" | ||
shfmt = "latest" |
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 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"/usr/include/python3.10", | ||
"/usr/include/hs" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c17", | ||
"cppStandard": "gnu++17", | ||
"intelliSenseMode": "linux-gcc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[strategy] | ||
inherit_metadata = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import tracemalloc | ||
from typing import Any, Callable, Generator | ||
|
||
import psutil | ||
from rich.progress import track | ||
|
||
import hyperscan | ||
|
||
db = hyperscan.Database(mode=hyperscan.HS_MODE_BLOCK) | ||
|
||
|
||
def profile_mem( | ||
target: Callable[..., Any], | ||
iterations=100_000, | ||
sample_interval=10_000, | ||
) -> Generator[int, None, None]: | ||
for i in range(iterations): | ||
target() | ||
if i % sample_interval == 0: | ||
process = psutil.Process() | ||
yield process.memory_info().rss | ||
|
||
|
||
def main() -> None: | ||
tracemalloc.start() | ||
os.getpid() | ||
|
||
db = hyperscan.Database(mode=hyperscan.HS_MODE_BLOCK) | ||
|
||
def compile(): | ||
db.compile( | ||
expressions=[b'test'], | ||
ids=[1], | ||
flags=[hyperscan.HS_FLAG_ALLOWEMPTY], | ||
) | ||
|
||
def dump(): | ||
compile() | ||
hyperscan.dumpb(db) | ||
|
||
for callback in (dump,): | ||
for i, step in enumerate( | ||
track( | ||
profile_mem(callback), | ||
description=f"📊 Profiling {callback.__name__}...", | ||
total=10, | ||
) | ||
): | ||
... | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,4 @@ | ||
#!/bin/bash | ||
mprof rm 0 2>/dev/null | ||
mprof run python test_memory.py | ||
mprof plot >/dev/null 2>&1 |