[PATCH v2 06/10] perf jevents: Add --compress=lzma block compression backend
From: Ian Rogers
Date: Mon Nov 16 2026 - 02:01:34 EST
Add an 'lzma' block-indexed string compression backend to jevents.py
using Python's standard-library lzma module (imported lazily) to
compress each ~8 KiB string block independently as a raw LZMA2 stream
(FORMAT_RAW + FILTER_LZMA2, dict_size=64 KiB) decoded on demand via
liblzma's lzma_raw_buffer_decode() in pmu-events-string.c.
This provides random-access per-block string decompression indexed by
(block_id << 16) | sub_offset on builds where liblzma is enabled without
libzstd or zlib. On x86, --compress=lzma shrinks pmu-events-string.o
from ~6.90 MB to ~819 KB.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/pmu-events/jevents.py | 44 ++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 51d44550b0b0..293c6ee10e60 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -238,10 +238,54 @@ def _compress_blocks_zlib(blocks: Sequence[bytes]) -> Optional[CompressedStringO
)
+def _compress_blocks_lzma(blocks: Sequence[bytes]) -> Optional[CompressedStringOutput]:
+ """Compress blocks using stdlib lzma raw LZMA2 streams."""
+ try:
+ lzma_mod = importlib.import_module('lzma')
+ except ImportError:
+ return None
+
+ dict_size = 1 << _BIG_C_STRING_BLOCK_SHIFT
+ filters = [{'id': lzma_mod.FILTER_LZMA2, 'preset': 6, 'dict_size': dict_size}]
+ compressed_blocks = [
+ lzma_mod.compress(block, format=lzma_mod.FORMAT_RAW, filters=filters)
+ for block in blocks
+ ]
+
+ decompress_fn = f"""static bool decompress_block(const unsigned char *src, uint32_t src_len,
+\t\t\t char *dst, uint32_t dst_len)
+{{
+\tlzma_options_lzma opt = {{
+\t\t.dict_size = {dict_size}U,
+\t\t.preset_dict = NULL,
+\t\t.preset_dict_size = 0,
+\t}};
+\tconst lzma_filter filters[] = {{
+\t\t{{ .id = LZMA_FILTER_LZMA2, .options = &opt }},
+\t\t{{ .id = LZMA_VLI_UNKNOWN, .options = NULL }},
+\t}};
+\tsize_t in_pos = 0, out_pos = 0;
+\tlzma_ret ret;
+
+\tret = lzma_raw_buffer_decode(filters, NULL, src, &in_pos, src_len,
+\t\t\t\t (uint8_t *)dst, &out_pos, dst_len);
+\treturn ret == LZMA_OK && in_pos == src_len && out_pos == dst_len;
+}}
+"""
+ return CompressedStringOutput(
+ name='lzma',
+ c_headers=['<lzma.h>'],
+ compressed_blocks=compressed_blocks,
+ extra_c_decls='',
+ decompress_c_fn=decompress_fn,
+ )
+
+
_COMPRESS_BACKENDS: Dict[
str, Optional[Callable[[Sequence[bytes]], Optional[CompressedStringOutput]]]
] = {
'none': None,
+ 'lzma': _compress_blocks_lzma,
'zlib': _compress_blocks_zlib,
}
--
2.56.1.703.gf848ed807c-goog