Path: blob/master/Utilities/cmzstd/lib/common/zstd_trace.h
3158 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#if defined (__cplusplus)14extern "C" {15#endif1617#include <stddef.h>1819/* weak symbol support20* For now, enable conservatively:21* - Only GNUC22* - Only ELF23* - Only x86-64, i386 and aarch6424* Also, explicitly disable on platforms known not to work so they aren't25* forgotten in the future.26*/27#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \28defined(__GNUC__) && defined(__ELF__) && \29(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__aarch64__)) && \30!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \31!defined(__CYGWIN__) && !defined(_AIX)32# define ZSTD_HAVE_WEAK_SYMBOLS 133#else34# define ZSTD_HAVE_WEAK_SYMBOLS 035#endif36#if ZSTD_HAVE_WEAK_SYMBOLS37# define ZSTD_WEAK_ATTR __attribute__((__weak__))38#else39# define ZSTD_WEAK_ATTR40#endif4142/* Only enable tracing when weak symbols are available. */43#ifndef ZSTD_TRACE44# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS45#endif4647#if ZSTD_TRACE4849struct ZSTD_CCtx_s;50struct ZSTD_DCtx_s;51struct ZSTD_CCtx_params_s;5253typedef struct {54/**55* ZSTD_VERSION_NUMBER56*57* This is guaranteed to be the first member of ZSTD_trace.58* Otherwise, this struct is not stable between versions. If59* the version number does not match your expectation, you60* should not interpret the rest of the struct.61*/62unsigned version;63/**64* Non-zero if streaming (de)compression is used.65*/66unsigned streaming;67/**68* The dictionary ID.69*/70unsigned dictionaryID;71/**72* Is the dictionary cold?73* Only set on decompression.74*/75unsigned dictionaryIsCold;76/**77* The dictionary size or zero if no dictionary.78*/79size_t dictionarySize;80/**81* The uncompressed size of the data.82*/83size_t uncompressedSize;84/**85* The compressed size of the data.86*/87size_t compressedSize;88/**89* The fully resolved CCtx parameters (NULL on decompression).90*/91struct ZSTD_CCtx_params_s const* params;92/**93* The ZSTD_CCtx pointer (NULL on decompression).94*/95struct ZSTD_CCtx_s const* cctx;96/**97* The ZSTD_DCtx pointer (NULL on compression).98*/99struct ZSTD_DCtx_s const* dctx;100} ZSTD_Trace;101102/**103* A tracing context. It must be 0 when tracing is disabled.104* Otherwise, any non-zero value returned by a tracing begin()105* function is presented to any subsequent calls to end().106*107* Any non-zero value is treated as tracing is enabled and not108* interpreted by the library.109*110* Two possible uses are:111* * A timestamp for when the begin() function was called.112* * A unique key identifying the (de)compression, like the113* address of the [dc]ctx pointer if you need to track114* more information than just a timestamp.115*/116typedef unsigned long long ZSTD_TraceCtx;117118/**119* Trace the beginning of a compression call.120* @param cctx The dctx pointer for the compression.121* It can be used as a key to map begin() to end().122* @returns Non-zero if tracing is enabled. The return value is123* passed to ZSTD_trace_compress_end().124*/125ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(126struct ZSTD_CCtx_s const* cctx);127128/**129* Trace the end of a compression call.130* @param ctx The return value of ZSTD_trace_compress_begin().131* @param trace The zstd tracing info.132*/133ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(134ZSTD_TraceCtx ctx,135ZSTD_Trace const* trace);136137/**138* Trace the beginning of a decompression call.139* @param dctx The dctx pointer for the decompression.140* It can be used as a key to map begin() to end().141* @returns Non-zero if tracing is enabled. The return value is142* passed to ZSTD_trace_compress_end().143*/144ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(145struct ZSTD_DCtx_s const* dctx);146147/**148* Trace the end of a decompression call.149* @param ctx The return value of ZSTD_trace_decompress_begin().150* @param trace The zstd tracing info.151*/152ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(153ZSTD_TraceCtx ctx,154ZSTD_Trace const* trace);155156#endif /* ZSTD_TRACE */157158#if defined (__cplusplus)159}160#endif161162#endif /* ZSTD_TRACE_H */163164165