This is a debugging tool for tracing malloc that occurs inside a function or class.
Project description
License Build Status PyPI version
malloc_tracer
About
This is a debugging tool for tracing malloc that occurs inside a function or class.
import numpy as np
from malloc_tracer.tracer import *
def func(x, y, z):
dataset1 = np.empty((100, ), dtype=np.float64)
print('x', x)
dataset1 = np.empty((1000, ), dtype=np.float64)
l = [i for i in range(100000)]
if x == 0:
dataset4a = np.empty((100000, ), dtype=np.float64)
return 0
elif x == 1:
dataset4b = np.empty((100000, ), dtype=np.float64)
return 1
dataset3 = np.empty((3000, ), dtype=np.float64)
return 2
tracer = Tracer(func)
This is equivalent to the following code.
import numpy as np
from tracemalloc import start, take_snapshot, stop
SNAPSHOT = None
def func(x, y, z):
try:
start()
dataset1 = np.empty((100,), dtype=np.float64)
print('x', x)
dataset1 = np.empty((1000,), dtype=np.float64)
l = [i for i in range(100000)]
if (x == 0):
dataset4a = np.empty((100000,), dtype=np.float64)
return 0
elif (x == 1):
dataset4b = np.empty((100000,), dtype=np.float64)
return 1
dataset3 = np.empty((3000,), dtype=np.float64)
return 2
finally:
global SNAPSHOT
SNAPSHOT = take_snapshot()
stop()
Feature
Compatibility
malloc_tracer works with Python 3.4 or higher.
Dependencies
Installation
pip install malloc-tracer
Usage
Trace a function.
import numpy as np
from malloc_tracer.tracer import *
def func(x, y, z):
dataset1 = np.empty((100, ), dtype=np.float64)
print('x', x)
dataset1 = np.empty((1000, ), dtype=np.float64)
l = [i for i in range(100000)]
if x == 0:
dataset4a = np.empty((100000, ), dtype=np.float64)
return 0
elif x == 1:
dataset4b = np.empty((100000, ), dtype=np.float64)
return 1
dataset3 = np.empty((3000, ), dtype=np.float64)
return 2
tracer = Tracer(func)
tracer.trace(
target_args=dict(x=1, y=2, z=3)
)
Trace a method.
import numpy as np
from malloc_tracer.tracer import *
class Klass(object):
CONSTANT = 'CONSTANT'
def __init__(self, value):
self._value = value
def method(self, x):
dataset1 = np.empty((100, ), dtype=np.float64)
print('x', x)
dataset1 = np.empty((1000, ), dtype=np.float64)
l = [i for i in range(100000)]
if x == 0:
dataset4a = np.empty((100000, ), dtype=np.float64)
return 0
elif x == 1:
dataset4b = np.empty((100000, ), dtype=np.float64)
return 1
dataset3 = np.empty((3000, ), dtype=np.float64)
return 2
@staticmethod
def smethod():
dataset = np.empty((100, ), dtype=np.float64)
l = [i for i in range(100000)]
print('Hello')
return dataset
@classmethod
def cmethod(cls, var):
return cls.CONSTANT + var
instance = Klass(1)
tracer = Tracer(instance.method)
tracer.trace(
target_args=dict(x=1)
)
Trace a static method.
tracer = Tracer(Klass.smethod)
tracer.trace(
target_args=dict()
)
Trace a class method.
tracer = Tracer(Klass.cmethod)
tracer.trace(
target_args=dict(var='Hello world.')
)
License
This software is released under the MIT License, see LICENSE.
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
malloc_tracer-1.1.0.tar.gz
(91.9 kB
view hashes)
Built Distribution
Close
Hashes for malloc_tracer-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63b3a1b0504f8cc0e769c7248fbcb843373e6a11d15a6502556907af6308bfa7 |
|
MD5 | 927556504949c0702e2b11c05aced54c |
|
BLAKE2b-256 | 6f192079c4faf93242663999a45369541dd72c12c19718cc0ef9f81a2e89c368 |