On-demand system call tracing for Python programs.
Project description
Ptracer is a library providing on-demand system call tracing in Python programs.
Basic Usage
import traceback
import ptracer
def callback(syscall):
print('{}({}) -> {}'.format(
syscall.name,
', '.join(repr(arg.value) for arg in syscall.args),
syscall.result.text))
print('Traceback: ')
print(''.join(traceback.format_list(syscall.traceback)))
with ptracer.context(callback):
open('/dev/null', 'wb')
Filtering
Ptracer allows elaborate syscall filtering via the filter argument:
flt = [
ptracer.SysCallPattern(
name='open',
args=[
re.compile(b'/tmp/.*'),
lambda arg: arg.value & os.O_WRONLY
],
result=lambda res: res.value > 0
)
]
with ptracer.context(callback, filter=flt):
# traced code
...
In the above example, ptracer will invoke the callback only for successful attempts to open files in the “/tmp” directory for writing.
Documentation
The documentation is available on ptracer.readthedocs.io.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ptracer-0.6.tar.gz
(29.6 kB
view details)
File details
Details for the file ptracer-0.6.tar.gz
.
File metadata
- Download URL: ptracer-0.6.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 381a430aa6bb7fdce579a3c26da84162df82c03b59f26f8887e5813ca43ea013 |
|
MD5 | d716c2646a1663a8f4ef33ca080e3dad |
|
BLAKE2b-256 | a138cb7aa774fb85bc9615d936da5878e09238acbf40cea4d04f1748e1a3c180 |