Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
Expand file tree
/
Copy pathbinary_io.h
More file actions
Latest commit
669 lines (580 loc) · 21.4 KB
/
Copy pathbinary_io.h
File metadata and controls
669 lines (580 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/******************************************************************************
* Python Remote Debugging Module - Binary I/O Header
*
* This header provides declarations for high-performance binary file I/O
* for profiling data with optional zstd streaming compression.
******************************************************************************/
#ifndefPy_BINARY_IO_H
#definePy_BINARY_IO_H
#ifdef__cplusplus
extern"C" {
#endif
#include"Python.h"
#include"pycore_hashtable.h"
#include<stdint.h>
#include<stdio.h>
/* ============================================================================
* BINARY FORMAT CONSTANTS
* ============================================================================ */
#defineBINARY_FORMAT_MAGIC 0x54414348 /* "TACH" (Tachyon) in native byte order */
#defineBINARY_FORMAT_MAGIC_SWAPPED 0x48434154 /* Byte-swapped magic for endianness detection */
#defineBINARY_FORMAT_VERSION 1
/* Sentinel values for optional frame fields */
#defineOPCODE_NONE 255 /* No opcode captured (u8 sentinel) */
#defineLOCATION_NOT_AVAILABLE (-1) /* lineno/column not available (zigzag sentinel) */
/* Conditional byte-swap macros for cross-endian file reading.
* Uses Python's optimized byte-swap functions from pycore_bitutils.h */
#defineSWAP16_IF(swap, x) ((swap) ? _Py_bswap16(x) : (x))
#defineSWAP32_IF(swap, x) ((swap) ? _Py_bswap32(x) : (x))
#defineSWAP64_IF(swap, x) ((swap) ? _Py_bswap64(x) : (x))
/* Header field offsets and sizes */
#defineHDR_OFF_MAGIC 0
#defineHDR_SIZE_MAGIC 4
#defineHDR_OFF_VERSION (HDR_OFF_MAGIC + HDR_SIZE_MAGIC)
#defineHDR_SIZE_VERSION 4
#defineHDR_OFF_PY_VERSION (HDR_OFF_VERSION + HDR_SIZE_VERSION)
#defineHDR_SIZE_PY_VERSION 4 /* 3 bytes: major, minor, micro + 1 reserved */
#defineHDR_OFF_PY_MAJOR HDR_OFF_PY_VERSION
#defineHDR_OFF_PY_MINOR (HDR_OFF_PY_VERSION + 1)
#defineHDR_OFF_PY_MICRO (HDR_OFF_PY_VERSION + 2)
#defineHDR_OFF_START_TIME (HDR_OFF_PY_VERSION + HDR_SIZE_PY_VERSION)
#defineHDR_SIZE_START_TIME 8
#defineHDR_OFF_INTERVAL (HDR_OFF_START_TIME + HDR_SIZE_START_TIME)
#defineHDR_SIZE_INTERVAL 8
#defineHDR_OFF_SAMPLES (HDR_OFF_INTERVAL + HDR_SIZE_INTERVAL)
#defineHDR_SIZE_SAMPLES 8
#defineHDR_OFF_THREADS (HDR_OFF_SAMPLES + HDR_SIZE_SAMPLES)
#defineHDR_SIZE_THREADS 4
#defineHDR_OFF_STR_TABLE (HDR_OFF_THREADS + HDR_SIZE_THREADS)
#defineHDR_SIZE_STR_TABLE 8
#defineHDR_OFF_FRAME_TABLE (HDR_OFF_STR_TABLE + HDR_SIZE_STR_TABLE)
#defineHDR_SIZE_FRAME_TABLE 8
#defineHDR_OFF_COMPRESSION (HDR_OFF_FRAME_TABLE + HDR_SIZE_FRAME_TABLE)
#defineHDR_SIZE_COMPRESSION 4
#defineFILE_HEADER_SIZE (HDR_OFF_COMPRESSION + HDR_SIZE_COMPRESSION)
#defineFILE_HEADER_PLACEHOLDER_SIZE 64
static_assert(FILE_HEADER_SIZE <= FILE_HEADER_PLACEHOLDER_SIZE,
"FILE_HEADER_SIZE exceeds FILE_HEADER_PLACEHOLDER_SIZE");
/* Sample header field offsets and sizes */
#defineSMP_OFF_THREAD_ID 0
#defineSMP_SIZE_THREAD_ID sizeof(uint64_t)
#defineSMP_OFF_INTERPRETER_ID (SMP_OFF_THREAD_ID + SMP_SIZE_THREAD_ID)
#defineSMP_SIZE_INTERPRETER_ID sizeof(uint32_t)
#defineSMP_OFF_ENCODING (SMP_OFF_INTERPRETER_ID + SMP_SIZE_INTERPRETER_ID)
#defineSMP_SIZE_ENCODING sizeof(uint8_t)
#defineSAMPLE_HEADER_FIXED_SIZE (SMP_OFF_ENCODING + SMP_SIZE_ENCODING)
static_assert(SAMPLE_HEADER_FIXED_SIZE==13,
"SAMPLE_HEADER_FIXED_SIZE must remain 13");
/* Footer field offsets and sizes */
#defineFTR_OFF_STRINGS 0
#defineFTR_SIZE_STRINGS sizeof(uint32_t)
#defineFTR_OFF_FRAMES (FTR_OFF_STRINGS + FTR_SIZE_STRINGS)
#defineFTR_SIZE_FRAMES sizeof(uint32_t)
#defineFTR_OFF_FILE_SIZE (FTR_OFF_FRAMES + FTR_SIZE_FRAMES)
#defineFTR_SIZE_FILE_SIZE sizeof(uint64_t)
#defineFTR_OFF_CHECKSUM (FTR_OFF_FILE_SIZE + FTR_SIZE_FILE_SIZE)
#defineFTR_SIZE_CHECKSUM (2 * sizeof(uint64_t))
#defineFILE_FOOTER_SIZE (FTR_OFF_CHECKSUM + FTR_SIZE_CHECKSUM)
static_assert(FILE_FOOTER_SIZE==32,
"FILE_FOOTER_SIZE must remain 32");
/* Minimum on-disk bytes of a string (1) and frame (7) table entry. */
#defineMIN_STRING_ENTRY_SIZE 1
#defineMIN_FRAME_ENTRY_SIZE 7
/* Buffer sizes: 512KB balances syscall amortization against memory use,
* and aligns well with filesystem block sizes and zstd dictionary windows */
#defineWRITE_BUFFER_SIZE (512 * 1024)
#defineCOMPRESSED_BUFFER_SIZE (512 * 1024)
/* Compression types */
#defineCOMPRESSION_NONE 0
#defineCOMPRESSION_ZSTD 1
/* Stack encoding types for delta compression */
#defineSTACK_REPEAT 0x00 /* RLE: identical to previous, with count */
#defineSTACK_FULL 0x01 /* Full stack (first sample or no match) */
#defineSTACK_SUFFIX 0x02 /* Shares N frames from bottom */
#defineSTACK_POP_PUSH 0x03 /* Remove M frames, add N frames */
/* Maximum stack depth we'll buffer for delta encoding */
#defineMAX_STACK_DEPTH 256
/* Initial capacities for dynamic arrays - sized to reduce reallocations */
#defineINITIAL_STRING_CAPACITY 4096
#defineINITIAL_FRAME_CAPACITY 4096
#defineINITIAL_THREAD_CAPACITY 256
/* ============================================================================
* STATISTICS STRUCTURES
* ============================================================================ */
/* Writer statistics - tracks encoding efficiency */
typedefstruct {
uint64_trepeat_records; /* Number of RLE repeat records written */
uint64_trepeat_samples; /* Total samples encoded via RLE */
uint64_tfull_records; /* Number of full stack records */
uint64_tsuffix_records; /* Number of suffix match records */
uint64_tpop_push_records; /* Number of pop-push records */
uint64_ttotal_frames_written;/* Total frame indices written */
uint64_tframes_saved; /* Frames avoided due to delta encoding */
uint64_tbytes_written; /* Total bytes written (before compression) */
} BinaryWriterStats;
/* Reader statistics - tracks reconstruction performance */
typedefstruct {
uint64_trepeat_records; /* RLE records decoded */
uint64_trepeat_samples; /* Samples decoded from RLE */
uint64_tfull_records; /* Full stack records decoded */
uint64_tsuffix_records; /* Suffix match records decoded */
uint64_tpop_push_records; /* Pop-push records decoded */
uint64_ttotal_samples; /* Total samples reconstructed */
uint64_tstack_reconstructions; /* Number of stack array reconstructions */
} BinaryReaderStats;
/* ============================================================================
* PLATFORM ABSTRACTION
* ============================================================================ */
#if defined(__linux__) || defined(__APPLE__)
#include<sys/mman.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#defineUSE_MMAP 1
#else
#defineUSE_MMAP 0
#endif
/* 64-bit file position support for files larger than 2GB.
* On POSIX: use ftello/fseeko with off_t (already 64-bit on 64-bit systems)
* On Windows: use _ftelli64/_fseeki64 with __int64 */
#if defined(_WIN32) || defined(_WIN64)
#include<io.h>
typedef__int64file_offset_t;
#defineFTELL64(fp) _ftelli64(fp)
#defineFSEEK64(fp, offset, whence) _fseeki64(fp, offset, whence)
#else
/* POSIX - off_t is 64-bit on 64-bit systems, ftello/fseeko handle large files */
typedefoff_tfile_offset_t;
#defineFTELL64(fp) ftello(fp)
#defineFSEEK64(fp, offset, whence) fseeko(fp, offset, whence)
#endif
/* Forward declare zstd types if available */
#ifdefHAVE_ZSTD
#include<zstd.h>
#endif
/* Branch prediction hints - same as Objects/obmalloc.c */
#if (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>2))) && defined(__OPTIMIZE__)
# defineUNLIKELY(value) __builtin_expect((value), 0)
# defineLIKELY(value) __builtin_expect((value), 1)
#else
# defineUNLIKELY(value) (value)
# defineLIKELY(value) (value)
#endif
/* ============================================================================
* BINARY WRITER STRUCTURES
* ============================================================================ */
/* zstd compression state (only used if HAVE_ZSTD defined) */
typedefstruct {
#ifdefHAVE_ZSTD
ZSTD_CCtx*cctx; /* Modern API: CCtx and CStream are the same since v1.3.0 */
#else
void*cctx; /* Placeholder */
#endif
uint8_t*compressed_buffer;
size_tcompressed_buffer_size;
} ZstdCompressor;
/* Frame entry - combines all frame data for better cache locality.
* Stores full source position (line, end_line, column, end_column) and opcode.
* Delta values are computed during serialization for efficiency. */
typedefstruct {
uint32_tfilename_idx;
uint32_tfuncname_idx;
int32_tlineno; /* Start line number (-1 for synthetic frames) */
int32_tend_lineno; /* End line number (-1 if not available) */
int32_tcolumn; /* Start column in UTF-8 bytes (-1 if not available) */
int32_tend_column; /* End column in UTF-8 bytes (-1 if not available) */
uint8_topcode; /* Python opcode (0-254) or OPCODE_NONE (255) */
} FrameEntry;
/* Frame key for hash table lookup - includes all fields for proper deduplication */
typedefstruct {
uint32_tfilename_idx;
uint32_tfuncname_idx;
int32_tlineno;
int32_tend_lineno;
int32_tcolumn;
int32_tend_column;
uint8_topcode;
} FrameKey;
/* Thread entry - tracks per-thread state for delta encoding */
typedefstruct {
uint64_tthread_id;
uint64_tprev_timestamp;
uint32_tinterpreter_id;
/* Previous stack for delta encoding (frame indices, innermost first) */
uint32_t*prev_stack;
size_tprev_stack_depth;
size_tprev_stack_capacity;
/* RLE pending buffer - samples waiting to be written as a repeat group */
uint8_t*pending_rle;
size_tpending_rle_bytes;
size_tpending_rle_samples;
} ThreadEntry;
/* Main binary writer structure */
typedefstruct {
FILE*fp;
/* Write buffer for batched I/O */
uint8_t*write_buffer;
size_tbuffer_pos;
size_tbuffer_size;
/* Compression */
intcompression_type;
ZstdCompressorzstd;
/* Metadata */
uint64_tstart_time_us;
uint64_tsample_interval_us;
uint64_ttotal_samples;
/* String hash table: PyObject* -> uint32_t index */
_Py_hashtable_t*string_hash;
/* String storage: array of UTF-8 encoded strings */
char**strings;
size_t*string_lengths;
size_tstring_count;
size_tstring_capacity;
/* Frame hash table: FrameKey* -> uint32_t index */
_Py_hashtable_t*frame_hash;
/* Frame storage: combined struct for better cache locality */
FrameEntry*frame_entries;
size_tframe_count;
size_tframe_capacity;
/* Thread timestamp tracking for delta encoding - combined for cache locality */
ThreadEntry*thread_entries;
size_tthread_count;
size_tthread_capacity;
/* Statistics */
BinaryWriterStatsstats;
} BinaryWriter;
/* ============================================================================
* BINARY READER STRUCTURES
* ============================================================================ */
/* Per-thread state for stack reconstruction during replay */
typedefstruct {
uint64_tthread_id;
uint32_tinterpreter_id;
uint64_tprev_timestamp;
/* Reconstructed stack buffer (frame indices, innermost first) */
uint32_t*current_stack;
size_tcurrent_stack_depth;
size_tcurrent_stack_capacity;
} ReaderThreadState;
/* Main binary reader structure */
typedefstruct {
#ifUSE_MMAP
uint8_t*mapped_data;
size_tmapped_size;
#else
FILE*fp;
uint8_t*file_data;
size_tfile_size;
#endif
/* Decompression state */
intcompression_type;
/* Note: ZSTD_DCtx is not stored - created/freed during decompression */
uint8_t*decompressed_data;
size_tdecompressed_size;
/* Header metadata */
uint8_tpy_major;
uint8_tpy_minor;
uint8_tpy_micro;
intneeds_swap; /* Non-zero if file was written on different-endian system */
uint64_tstart_time_us;
uint64_tsample_interval_us;
uint64_tsample_count;
uint32_tthread_count;
uint64_tstring_table_offset;
uint64_tframe_table_offset;
/* Parsed string table: array of Python string objects */
PyObject**strings;
uint32_tstrings_count;
/* Parsed frame table: array of FrameEntry structures */
FrameEntry*frames;
uint32_tframes_count;
/* Sample data region */
uint8_t*sample_data;
size_tsample_data_size;
/* Per-thread state for stack reconstruction (used during replay) */
ReaderThreadState*thread_states;
size_tthread_state_count;
size_tthread_state_capacity;
/* Statistics */
BinaryReaderStatsstats;
} BinaryReader;
/* ============================================================================
* VARINT ENCODING/DECODING (INLINE FOR PERFORMANCE)
* ============================================================================ */
/* Encode unsigned 64-bit varint (LEB128). Returns bytes written. */
staticinlinesize_t
encode_varint_u64(uint8_t*buf, uint64_tvalue)
{
/* Fast path for single-byte values (0-127) - very common case */
if (value<0x80) {
buf[0] = (uint8_t)value;
return1;
}
size_ti=0;
while (value >= 0x80) {
buf[i++] = (uint8_t)((value&0x7F) | 0x80);
value >>= 7;
}
buf[i++] = (uint8_t)(value&0x7F);
returni;
}
/* Encode unsigned 32-bit varint. Returns bytes written. */
staticinlinesize_t
encode_varint_u32(uint8_t*buf, uint32_tvalue)
{
returnencode_varint_u64(buf, value);
}
/* Encode signed 32-bit varint (zigzag encoding). Returns bytes written. */
staticinlinesize_t
encode_varint_i32(uint8_t*buf, int32_tvalue)
{
/* Zigzag encode: map signed to unsigned */
uint32_tzigzag= ((uint32_t)value << 1) ^ (uint32_t)(value >> 31);
returnencode_varint_u32(buf, zigzag);
}
/* Decode unsigned 64-bit varint (LEB128). Updates offset only on success.
* On error (overflow or incomplete), offset is NOT updated, allowing callers
* to detect errors via (offset == prev_offset) check. Sets PyErr on error. */
staticinlineuint64_t
decode_varint_u64(constuint8_t*data, size_t*offset, size_tmax_size)
{
size_tpos=*offset;
uint64_tresult=0;
intshift=0;
/* Fast path for single-byte varints (0-127) - most common case */
if (LIKELY(pos<max_size&& (data[pos] &0x80) ==0)) {
*offset=pos+1;
returndata[pos];
}
while (pos<max_size) {
uint8_tbyte=data[pos++];
result |= (uint64_t)(byte&0x7F) << shift;
if ((byte&0x80) ==0) {
*offset=pos;
returnresult;
}
shift+=7;
if (UNLIKELY(shift >= 64)) {
PyErr_SetString(PyExc_ValueError, "Invalid or incomplete varint in binary data");
return0;
}
}
PyErr_SetString(PyExc_ValueError, "Invalid or incomplete varint in binary data");
return0;
}
/* Decode unsigned 32-bit varint. If value exceeds UINT32_MAX, treats as error. */
staticinlineuint32_t
decode_varint_u32(constuint8_t*data, size_t*offset, size_tmax_size)
{
size_tsaved_offset=*offset;
uint64_tvalue=decode_varint_u64(data, offset, max_size);
if (*offset==saved_offset) {
return0; /* decode_varint_u64 already set PyErr */
}
if (UNLIKELY(value>UINT32_MAX)) {
*offset=saved_offset;
PyErr_SetString(PyExc_ValueError, "Invalid or incomplete varint in binary data");
return0;
}
return (uint32_t)value;
}
/* Decode signed 32-bit varint (zigzag encoding). */
staticinlineint32_t
decode_varint_i32(constuint8_t*data, size_t*offset, size_tmax_size)
{
size_tsaved_offset=*offset;
uint32_tzigzag=decode_varint_u32(data, offset, max_size);
if (*offset==saved_offset) {
return0; /* decode_varint_u32 already set PyErr */
}
return (int32_t)((zigzag >> 1) ^ -(int32_t)(zigzag&1));
}
/* ============================================================================
* SHARED UTILITY FUNCTIONS
* ============================================================================ */
/* Generic array growth - returns new pointer or NULL (sets PyErr_NoMemory)
* Includes overflow checking for capacity doubling and allocation size. */
staticinlinevoid*
grow_array(void*ptr, size_t*capacity, size_telem_size)
{
size_told_cap=*capacity;
/* Check for overflow when doubling capacity */
if (old_cap>SIZE_MAX / 2) {
PyErr_SetString(PyExc_OverflowError, "Array capacity overflow");
returnNULL;
}
size_tnew_cap=old_cap*2;
/* Check for overflow when calculating allocation size */
if (new_cap>SIZE_MAX / elem_size) {
PyErr_SetString(PyExc_OverflowError, "Array allocation size overflow");
returnNULL;
}
void*new_ptr=PyMem_Realloc(ptr, new_cap*elem_size);
if (new_ptr) {
*capacity=new_cap;
} else {
PyErr_NoMemory();
}
returnnew_ptr;
}
staticinlineint
grow_array_inplace(void**ptr_addr, size_tcount, size_t*capacity, size_telem_size)
{
if (count<*capacity) {
return0;
}
void*tmp=grow_array(*ptr_addr, capacity, elem_size);
if (tmp==NULL) {
return-1;
}
*ptr_addr=tmp;
return0;
}
#defineGROW_ARRAY(ptr, count, cap, type) \
grow_array_inplace((void**)&(ptr), (count), &(cap), sizeof(type))
/* ============================================================================
* BINARY WRITER API
* ============================================================================ */
/*
* Create a new binary writer.
*
* Arguments:
* path: Path to output file
* sample_interval_us: Sampling interval in microseconds
* compression_type: COMPRESSION_NONE or COMPRESSION_ZSTD
* start_time_us: Start timestamp in microseconds (from time.monotonic() * 1e6)
*
* Returns:
* New BinaryWriter* on success, NULL on failure (PyErr set)
*/
BinaryWriter*binary_writer_create(
PyObject*path,
uint64_tsample_interval_us,
intcompression_type,
uint64_tstart_time_us
);
/*
* Write a sample to the binary file.
*
* Arguments:
* writer: Writer from binary_writer_create
* stack_frames: List of InterpreterInfo struct sequences
* timestamp_us: Current timestamp in microseconds (from time.monotonic() * 1e6)
*
* Returns:
* 0 on success, -1 on failure (PyErr set)
*/
intbinary_writer_write_sample(
BinaryWriter*writer,
PyObject*stack_frames,
uint64_ttimestamp_us
);
/*
* Finalize and close the binary file.
* Writes string/frame tables, footer, and updates header.
*
* Arguments:
* writer: Writer to finalize
*
* Returns:
* 0 on success, -1 on failure (PyErr set)
*/
intbinary_writer_finalize(BinaryWriter*writer);
/*
* Destroy a binary writer and free all resources.
* Safe to call even if writer is partially initialized.
*
* Arguments:
* writer: Writer to destroy (may be NULL)
*/
voidbinary_writer_destroy(BinaryWriter*writer);
/* ============================================================================
* BINARY READER API
* ============================================================================ */
/*
* Open a binary file for reading.
*
* Arguments:
* path: Path to input file
*
* Returns:
* New BinaryReader* on success, NULL on failure (PyErr set)
*/
BinaryReader*binary_reader_open(PyObject*path);
/*
* Replay samples from binary file through a collector.
*
* Arguments:
* reader: Reader from binary_reader_open
* collector: Python collector with collect() method
* progress_callback: Optional callable(current, total) or NULL
*
* Returns:
* Number of samples replayed on success, -1 on failure (PyErr set)
*/
Py_ssize_tbinary_reader_replay(
BinaryReader*reader,
PyObject*collector,
PyObject*progress_callback
);
/*
* Get metadata about the binary file.
*
* Arguments:
* reader: Reader from binary_reader_open
*
* Returns:
* Dict with file metadata on success, NULL on failure (PyErr set)
*/
PyObject*binary_reader_get_info(BinaryReader*reader);
/*
* Close a binary reader and free all resources.
*
* Arguments:
* reader: Reader to close (may be NULL)
*/
voidbinary_reader_close(BinaryReader*reader);
/* ============================================================================
* STATISTICS FUNCTIONS
* ============================================================================ */
/*
* Get writer statistics as a Python dict.
*
* Arguments:
* writer: Writer to get stats from
*
* Returns:
* Dict with statistics on success, NULL on failure (PyErr set)
*/
PyObject*binary_writer_get_stats(BinaryWriter*writer);
/*
* Get reader statistics as a Python dict.
*
* Arguments:
* reader: Reader to get stats from
*
* Returns:
* Dict with statistics on success, NULL on failure (PyErr set)
*/
PyObject*binary_reader_get_stats(BinaryReader*reader);
/* ============================================================================
* UTILITY FUNCTIONS
* ============================================================================ */
/*
* Check if zstd compression is available.
*
* Returns:
* 1 if zstd available, 0 otherwise
*/
intbinary_io_zstd_available(void);
/*
* Get the best available compression type.
*
* Returns:
* COMPRESSION_ZSTD if available, COMPRESSION_NONE otherwise
*/
intbinary_io_get_best_compression(void);
#ifdef__cplusplus
}
#endif
#endif/* Py_BINARY_IO_H */