Skip to main content

On-demand system call tracing for Python programs.

Project description

https://travis-ci.org/pinterest/ptracer.svg?branch=master

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


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.5.tar.gz (28.6 kB view details)

Uploaded Source

File details

Details for the file ptracer-0.5.tar.gz.

File metadata

  • Download URL: ptracer-0.5.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ptracer-0.5.tar.gz
Algorithm Hash digest
SHA256 002524cfb34043c6d6c89ca563cfdeb8ab6db3ebd300b509f6e46dc52d657334
MD5 db92e7790b2177492d9feed16a1ee2b4
BLAKE2b-256 d885193489f6d10aeb240f3ce656a85c9d9b8645ab6b602d68a190cb1f282598

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page