Path: blob/master/Utilities/cmzstd/lib/common/zstd_trace.h
5013 views
/*1* Copyright (c) Meta Platforms, Inc. and affiliates.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef ZSTD_TRACE_H11#define ZSTD_TRACE_H1213#include <stddef.h>1415/* weak symbol support16* For now, enable conservatively:17* - Only GNUC18* - Only ELF19* - Only x86-64, i386, aarch64 and risc-v.20* Also, explicitly disable on platforms known not to work so they aren't21* forgotten in the future.22*/23#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \24defined(__GNUC__) && defined(__ELF__) && \25(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \26defined(_M_IX86) || defined(__aarch64__) || defined(__riscv)) && \27!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \28!defined(__CYGWIN__) && !defined(_AIX)29# define ZSTD_HAVE_WEAK_SYMBOLS 130#else31# define ZSTD_HAVE_WEAK_SYMBOLS 032#endif33#if ZSTD_HAVE_WEAK_SYMBOLS34# define ZSTD_WEAK_ATTR __attribute__((__weak__))35#else36# define ZSTD_WEAK_ATTR37#endif3839/* Only enable tracing when weak symbols are available. */40#ifndef ZSTD_TRACE41# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS42#endif4344#if ZSTD_TRACE4546struct ZSTD_CCtx_s;47struct ZSTD_DCtx_s;48struct ZSTD_CCtx_params_s;4950typedef struct {51/**52* ZSTD_VERSION_NUMBER53*54* This is guaranteed to be the first member of ZSTD_trace.55* Otherwise, this struct is not stable between versions. If56* the version number does not match your expectation, you57* should not interpret the rest of the struct.58*/59unsigned version;60/**61* Non-zero if streaming (de)compression is used.62*/63int streaming;64/**65* The dictionary ID.66*/67unsigned dictionaryID;68/**69* Is the dictionary cold?70* Only set on decompression.71*/72int dictionaryIsCold;73/**74* The dictionary size or zero if no dictionary.75*/76size_t dictionarySize;77/**78* The uncompressed size of the data.79*/80size_t uncompressedSize;81/**82* The compressed size of the data.83*/84size_t compressedSize;85/**86* The fully resolved CCtx parameters (NULL on decompression).87*/88struct ZSTD_CCtx_params_s const* params;89/**90* The ZSTD_CCtx pointer (NULL on decompression).91*/92struct ZSTD_CCtx_s const* cctx;93/**94* The ZSTD_DCtx pointer (NULL on compression).95*/96struct ZSTD_DCtx_s const* dctx;97} ZSTD_Trace;9899/**100* A tracing context. It must be 0 when tracing is disabled.101* Otherwise, any non-zero value returned by a tracing begin()102* function is presented to any subsequent calls to end().103*104* Any non-zero value is treated as tracing is enabled and not105* interpreted by the library.106*107* Two possible uses are:108* * A timestamp for when the begin() function was called.109* * A unique key identifying the (de)compression, like the110* address of the [dc]ctx pointer if you need to track111* more information than just a timestamp.112*/113typedef unsigned long long ZSTD_TraceCtx;114115/**116* Trace the beginning of a compression call.117* @param cctx The dctx pointer for the compression.118* It can be used as a key to map begin() to end().119* @returns Non-zero if tracing is enabled. The return value is120* passed to ZSTD_trace_compress_end().121*/122ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(123struct ZSTD_CCtx_s const* cctx);124125/**126* Trace the end of a compression call.127* @param ctx The return value of ZSTD_trace_compress_begin().128* @param trace The zstd tracing info.129*/130ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(131ZSTD_TraceCtx ctx,132ZSTD_Trace const* trace);133134/**135* Trace the beginning of a decompression call.136* @param dctx The dctx pointer for the decompression.137* It can be used as a key to map begin() to end().138* @returns Non-zero if tracing is enabled. The return value is139* passed to ZSTD_trace_compress_end().140*/141ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(142struct ZSTD_DCtx_s const* dctx);143144/**145* Trace the end of a decompression call.146* @param ctx The return value of ZSTD_trace_decompress_begin().147* @param trace The zstd tracing info.148*/149ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(150ZSTD_TraceCtx ctx,151ZSTD_Trace const* trace);152153#endif /* ZSTD_TRACE */154155#endif /* ZSTD_TRACE_H */156157158