Path: blob/main/sys/contrib/openzfs/module/zstd/lib/common/zstd_trace.h
178701 views
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only1/*2* Copyright (c) Meta Platforms, Inc. and affiliates.3* All rights reserved.4*5* This source code is licensed under both the BSD-style license (found in the6* LICENSE file in the root directory of this source tree) and the GPLv2 (found7* in the COPYING file in the root directory of this source tree).8* You may select, at your option, one of the above-listed licenses.9*/1011#ifndef ZSTD_TRACE_H12#define ZSTD_TRACE_H1314#include <stddef.h>1516/* weak symbol support17* For now, enable conservatively:18* - Only GNUC19* - Only ELF20* - Only x86-64, i386, aarch64 and risc-v.21* Also, explicitly disable on platforms known not to work so they aren't22* forgotten in the future.23*/24#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \25defined(__GNUC__) && defined(__ELF__) && \26(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \27defined(_M_IX86) || defined(__aarch64__) || defined(__riscv)) && \28!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \29!defined(__CYGWIN__) && !defined(_AIX)30# define ZSTD_HAVE_WEAK_SYMBOLS 131#else32# define ZSTD_HAVE_WEAK_SYMBOLS 033#endif34#if ZSTD_HAVE_WEAK_SYMBOLS35# define ZSTD_WEAK_ATTR __attribute__((__weak__))36#else37# define ZSTD_WEAK_ATTR38#endif3940/* Only enable tracing when weak symbols are available. */41#ifndef ZSTD_TRACE42# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS43#endif4445#if ZSTD_TRACE4647struct ZSTD_CCtx_s;48struct ZSTD_DCtx_s;49struct ZSTD_CCtx_params_s;5051typedef struct {52/**53* ZSTD_VERSION_NUMBER54*55* This is guaranteed to be the first member of ZSTD_trace.56* Otherwise, this struct is not stable between versions. If57* the version number does not match your expectation, you58* should not interpret the rest of the struct.59*/60unsigned version;61/**62* Non-zero if streaming (de)compression is used.63*/64int streaming;65/**66* The dictionary ID.67*/68unsigned dictionaryID;69/**70* Is the dictionary cold?71* Only set on decompression.72*/73int dictionaryIsCold;74/**75* The dictionary size or zero if no dictionary.76*/77size_t dictionarySize;78/**79* The uncompressed size of the data.80*/81size_t uncompressedSize;82/**83* The compressed size of the data.84*/85size_t compressedSize;86/**87* The fully resolved CCtx parameters (NULL on decompression).88*/89struct ZSTD_CCtx_params_s const* params;90/**91* The ZSTD_CCtx pointer (NULL on decompression).92*/93struct ZSTD_CCtx_s const* cctx;94/**95* The ZSTD_DCtx pointer (NULL on compression).96*/97struct ZSTD_DCtx_s const* dctx;98} ZSTD_Trace;99100/**101* A tracing context. It must be 0 when tracing is disabled.102* Otherwise, any non-zero value returned by a tracing begin()103* function is presented to any subsequent calls to end().104*105* Any non-zero value is treated as tracing is enabled and not106* interpreted by the library.107*108* Two possible uses are:109* * A timestamp for when the begin() function was called.110* * A unique key identifying the (de)compression, like the111* address of the [dc]ctx pointer if you need to track112* more information than just a timestamp.113*/114typedef unsigned long long ZSTD_TraceCtx;115116/**117* Trace the beginning of a compression call.118* @param cctx The dctx pointer for the compression.119* It can be used as a key to map begin() to end().120* @returns Non-zero if tracing is enabled. The return value is121* passed to ZSTD_trace_compress_end().122*/123ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(124struct ZSTD_CCtx_s const* cctx);125126/**127* Trace the end of a compression call.128* @param ctx The return value of ZSTD_trace_compress_begin().129* @param trace The zstd tracing info.130*/131ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(132ZSTD_TraceCtx ctx,133ZSTD_Trace const* trace);134135/**136* Trace the beginning of a decompression call.137* @param dctx The dctx pointer for the decompression.138* It can be used as a key to map begin() to end().139* @returns Non-zero if tracing is enabled. The return value is140* passed to ZSTD_trace_compress_end().141*/142ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(143struct ZSTD_DCtx_s const* dctx);144145/**146* Trace the end of a decompression call.147* @param ctx The return value of ZSTD_trace_decompress_begin().148* @param trace The zstd tracing info.149*/150ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(151ZSTD_TraceCtx ctx,152ZSTD_Trace const* trace);153154#endif /* ZSTD_TRACE */155156#endif /* ZSTD_TRACE_H */157158159