Skip to content

Commit 567dbd1

Browse files
authored
Merge pull request #99 from pycompression/alwaysprofile
Enable profile hooks in python-isal
2 parents ea563a6 + 438e46e commit 567dbd1

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
1010
version 1.0.0-dev
1111
------------------
12+
+ Python-isal shows up in Python profiler reports.
1213
+ Support and tests for Python 3.10 were added.
1314
+ Due to a change in the deployment process wheels should work for older
1415
versions of pip.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
def cythonize_modules():
5050
extension_args = dict()
51-
compiler_directives = dict(binding=True, language_level="3")
51+
compiler_directives = dict(binding=True, language_level="3", profile=True)
5252
if os.getenv("CYTHON_COVERAGE") is not None:
5353
compiler_directives['linetrace'] = True
5454
extension_args["define_macros"] = [("CYTHON_TRACE_NOGIL", "1")]

src/isal/igzip_lib.pxd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,7 @@ ctypedef fused stream_or_state:
461461
isal_zstream
462462
inflate_state
463463

464-
cdef inline Py_ssize_t py_ssize_t_min(Py_ssize_t a, Py_ssize_t b):
465-
if a <= b:
466-
return a
467-
else:
468-
return b
464+
cdef inline Py_ssize_t py_ssize_t_min(Py_ssize_t a, Py_ssize_t b)
469465

470466
cdef Py_ssize_t arrange_output_buffer_with_maximum(stream_or_state *stream,
471467
unsigned char **buffer,

src/isal/igzip_lib.pyx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ from libc.string cimport memmove, memcpy
6969
from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
7070
from cpython.buffer cimport PyBUF_C_CONTIGUOUS, PyObject_GetBuffer, PyBuffer_Release
7171
from cpython.bytes cimport PyBytes_FromStringAndSize
72+
cimport cython
7273

7374
cdef extern from "<Python.h>":
7475
const Py_ssize_t PY_SSIZE_T_MAX
@@ -118,7 +119,15 @@ class IsalError(OSError):
118119
pass
119120

120121

122+
@cython.profile(False)
123+
cdef inline Py_ssize_t py_ssize_t_min(Py_ssize_t a, Py_ssize_t b):
124+
if a <= b:
125+
return a
126+
else:
127+
return b
128+
121129

130+
@cython.profile(False)
122131
cdef Py_ssize_t arrange_output_buffer_with_maximum(stream_or_state *stream,
123132
unsigned char **buffer,
124133
Py_ssize_t length,
@@ -152,6 +161,8 @@ cdef Py_ssize_t arrange_output_buffer_with_maximum(stream_or_state *stream,
152161
stream.next_out = buffer[0] + occupied
153162
return length
154163

164+
165+
@cython.profile(False)
155166
cdef Py_ssize_t arrange_output_buffer(stream_or_state *stream,
156167
unsigned char **buffer,
157168
Py_ssize_t length):
@@ -161,6 +172,8 @@ cdef Py_ssize_t arrange_output_buffer(stream_or_state *stream,
161172
return -1
162173
return ret
163174

175+
176+
@cython.profile(False)
164177
cdef void arrange_input_buffer(stream_or_state *stream, Py_ssize_t *remains):
165178
stream.avail_in = <unsigned int>py_ssize_t_min(remains[0], UINT32_MAX)
166179
remains[0] -= stream.avail_in
@@ -196,6 +209,8 @@ def compress(data,
196209
return _compress(data, level, flag, mem_level, hist_bits)
197210

198211

212+
213+
@cython.profile(False)
199214
cdef _compress(data,
200215
int level,
201216
int flag,
@@ -283,6 +298,7 @@ def decompress(data,
283298
return _decompress(data, flag, hist_bits, bufsize)
284299

285300

301+
@cython.profile(False)
286302
cdef _decompress(data,
287303
int flag,
288304
int hist_bits,
@@ -330,6 +346,7 @@ cdef _decompress(data,
330346
PyMem_Free(obuf)
331347

332348

349+
@cython.profile(False)
333350
cdef bytes view_bitbuffer(inflate_state * stream):
334351

335352
cdef int bits_in_buffer = stream.read_in_length
@@ -354,10 +371,13 @@ cdef class IgzipDecompressor:
354371
cdef Py_ssize_t input_buffer_size
355372
cdef Py_ssize_t avail_in_real
356373

374+
@cython.profile(False)
357375
def __dealloc__(self):
358376
if self.input_buffer != NULL:
359377
PyMem_Free(self.input_buffer)
360378

379+
380+
@cython.profile(False)
361381
def __cinit__(self,
362382
flag=ISAL_DEFLATE,
363383
hist_bits=ISAL_DEF_MAX_HIST_BITS,
@@ -380,7 +400,9 @@ cdef class IgzipDecompressor:
380400
self.input_buffer_size = 0
381401
self.avail_in_real = 0
382402
self.needs_input = True
383-
403+
404+
405+
@cython.profile(False)
384406
def _view_bitbuffer(self):
385407
"""Shows the 64-bitbuffer of the internal inflate_state. It contains
386408
a maximum of 8 bytes. This data is already read-in so is not part
@@ -394,6 +416,8 @@ cdef class IgzipDecompressor:
394416
flag."""
395417
return self.stream.crc
396418

419+
420+
@cython.profile(False)
397421
cdef decompress_buf(self, Py_ssize_t max_length, unsigned char ** obuf):
398422
obuf[0] = NULL
399423
cdef Py_ssize_t obuflen = DEF_BUF_SIZE_I
@@ -540,6 +564,7 @@ def decompressobj(flag=ISAL_DEFLATE,
540564
return IgzipDecompressor.__new__(IgzipDecompressor, flag, hist_bits, zdict)
541565

542566

567+
@cython.profile(False)
543568
cdef int mem_level_to_bufsize(int compression_level, int mem_level, unsigned int *bufsize):
544569
"""
545570
Convert zlib memory levels to isal equivalents
@@ -607,6 +632,8 @@ cdef int mem_level_to_bufsize(int compression_level, int mem_level, unsigned int
607632
bufsize[0] = ISAL_DEF_LVL3_EXTRA_LARGE
608633
return 0
609634

635+
636+
@cython.profile(False)
610637
cdef check_isal_deflate_rc(int rc):
611638
if rc == COMP_OK:
612639
return
@@ -627,6 +654,8 @@ cdef check_isal_deflate_rc(int rc):
627654
else:
628655
raise IsalError("Unknown Error")
629656

657+
658+
@cython.profile(False)
630659
cdef check_isal_inflate_rc(int rc):
631660
if rc >= ISAL_DECOMP_OK:
632661
return

src/isal/isal_zlib.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
9191
from cpython.buffer cimport PyBUF_C_CONTIGUOUS, PyObject_GetBuffer, PyBuffer_Release
9292
from cpython.bytes cimport PyBytes_FromStringAndSize
9393
from cpython.long cimport PyLong_AsUnsignedLongMask
94+
cimport cython
9495

9596
cdef extern from "<Python.h>":
9697
const Py_ssize_t PY_SSIZE_T_MAX
@@ -286,6 +287,7 @@ cdef class Compress:
286287
cdef isal_zstream stream
287288
cdef unsigned char * level_buf
288289

290+
@cython.profile(False)
289291
def __cinit__(self,
290292
int level = ISAL_DEFAULT_COMPRESSION_I,
291293
int method = DEFLATED,
@@ -315,6 +317,7 @@ cdef class Compress:
315317
self.level_buf = <unsigned char *>PyMem_Malloc(self.stream.level_buf_size * sizeof(char))
316318
self.stream.level_buf = self.level_buf
317319

320+
@cython.profile(False)
318321
def __dealloc__(self):
319322
if self.level_buf is not NULL:
320323
PyMem_Free(self.level_buf)
@@ -413,6 +416,7 @@ cdef class Decompress:
413416
cdef bint method_set
414417
cdef bint is_gzip
415418

419+
@cython.profile(False)
416420
def __cinit__(self, int wbits=ISAL_DEF_MAX_HIST_BITS, zdict = None):
417421
isal_inflate_init(&self.stream)
418422

@@ -436,12 +440,14 @@ cdef class Decompress:
436440
self.unconsumed_tail = b""
437441
self.eof = False
438442

443+
@cython.profile(False)
439444
def _view_bitbuffer(self):
440445
"""Shows the 64-bitbuffer of the internal inflate_state. It contains
441446
a maximum of 8 bytes. This data is already read-in so is not part
442447
of the unconsumed tail."""
443448
return view_bitbuffer(&self.stream)
444449

450+
@cython.profile(False)
445451
cdef save_unconsumed_input(self, Py_buffer *data):
446452
cdef Py_ssize_t old_size, new_size, left_size
447453
cdef bytes new_data
@@ -573,6 +579,7 @@ cdef class Decompress:
573579
PyBuffer_Release(buffer)
574580
PyMem_Free(obuf)
575581

582+
@cython.profile(False)
576583
cdef data_is_gzip(object data, bint *is_gzip):
577584
cdef Py_buffer buffer_data
578585
cdef Py_buffer* buffer = &buffer_data
@@ -592,6 +599,7 @@ cdef data_is_gzip(object data, bint *is_gzip):
592599
return
593600

594601

602+
@cython.profile(False)
595603
cdef wbits_to_flag_and_hist_bits_deflate(int wbits,
596604
unsigned short * hist_bits,
597605
unsigned short * gzip_flag):
@@ -608,6 +616,7 @@ cdef wbits_to_flag_and_hist_bits_deflate(int wbits,
608616
raise ValueError("Invalid wbits value")
609617

610618

619+
@cython.profile(False)
611620
cdef wbits_to_flag_and_hist_bits_inflate(int wbits,
612621
unsigned int * hist_bits,
613622
unsigned int * crc_flag,
@@ -630,6 +639,8 @@ cdef wbits_to_flag_and_hist_bits_inflate(int wbits,
630639
else:
631640
raise ValueError("Invalid wbits value")
632641

642+
643+
@cython.profile(False)
633644
cdef int zlib_mem_level_to_isal_bufsize(int compression_level, int mem_level, unsigned int *bufsize):
634645
"""
635646
Convert zlib memory levels to isal equivalents

0 commit comments

Comments
 (0)