1*5ff13fbcSAllan Jude /* 2*5ff13fbcSAllan Jude * Copyright (c) Facebook, Inc. 3*5ff13fbcSAllan Jude * All rights reserved. 4*5ff13fbcSAllan Jude * 5*5ff13fbcSAllan Jude * This source code is licensed under both the BSD-style license (found in the 6*5ff13fbcSAllan Jude * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*5ff13fbcSAllan Jude * in the COPYING file in the root directory of this source tree). 8*5ff13fbcSAllan Jude * You may select, at your option, one of the above-listed licenses. 9*5ff13fbcSAllan Jude */ 10*5ff13fbcSAllan Jude 11*5ff13fbcSAllan Jude #ifndef ZSTD_TRACE_H 12*5ff13fbcSAllan Jude #define ZSTD_TRACE_H 13*5ff13fbcSAllan Jude 14*5ff13fbcSAllan Jude #if defined (__cplusplus) 15*5ff13fbcSAllan Jude extern "C" { 16*5ff13fbcSAllan Jude #endif 17*5ff13fbcSAllan Jude 18*5ff13fbcSAllan Jude #include <stddef.h> 19*5ff13fbcSAllan Jude 20*5ff13fbcSAllan Jude /* weak symbol support 21*5ff13fbcSAllan Jude * For now, enable conservatively: 22*5ff13fbcSAllan Jude * - Only GNUC 23*5ff13fbcSAllan Jude * - Only ELF 24*5ff13fbcSAllan Jude * - Only x86-64 and i386 25*5ff13fbcSAllan Jude * Also, explicitly disable on platforms known not to work so they aren't 26*5ff13fbcSAllan Jude * forgotten in the future. 27*5ff13fbcSAllan Jude */ 28*5ff13fbcSAllan Jude #if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \ 29*5ff13fbcSAllan Jude defined(__GNUC__) && defined(__ELF__) && \ 30*5ff13fbcSAllan Jude (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)) && \ 31*5ff13fbcSAllan Jude !defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \ 32*5ff13fbcSAllan Jude !defined(__CYGWIN__) && !defined(_AIX) 33*5ff13fbcSAllan Jude # define ZSTD_HAVE_WEAK_SYMBOLS 1 34*5ff13fbcSAllan Jude #else 35*5ff13fbcSAllan Jude # define ZSTD_HAVE_WEAK_SYMBOLS 0 36*5ff13fbcSAllan Jude #endif 37*5ff13fbcSAllan Jude #if ZSTD_HAVE_WEAK_SYMBOLS 38*5ff13fbcSAllan Jude # define ZSTD_WEAK_ATTR __attribute__((__weak__)) 39*5ff13fbcSAllan Jude #else 40*5ff13fbcSAllan Jude # define ZSTD_WEAK_ATTR 41*5ff13fbcSAllan Jude #endif 42*5ff13fbcSAllan Jude 43*5ff13fbcSAllan Jude /* Only enable tracing when weak symbols are available. */ 44*5ff13fbcSAllan Jude #ifndef ZSTD_TRACE 45*5ff13fbcSAllan Jude # define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS 46*5ff13fbcSAllan Jude #endif 47*5ff13fbcSAllan Jude 48*5ff13fbcSAllan Jude #if ZSTD_TRACE 49*5ff13fbcSAllan Jude 50*5ff13fbcSAllan Jude struct ZSTD_CCtx_s; 51*5ff13fbcSAllan Jude struct ZSTD_DCtx_s; 52*5ff13fbcSAllan Jude struct ZSTD_CCtx_params_s; 53*5ff13fbcSAllan Jude 54*5ff13fbcSAllan Jude typedef struct { 55*5ff13fbcSAllan Jude /** 56*5ff13fbcSAllan Jude * ZSTD_VERSION_NUMBER 57*5ff13fbcSAllan Jude * 58*5ff13fbcSAllan Jude * This is guaranteed to be the first member of ZSTD_trace. 59*5ff13fbcSAllan Jude * Otherwise, this struct is not stable between versions. If 60*5ff13fbcSAllan Jude * the version number does not match your expectation, you 61*5ff13fbcSAllan Jude * should not interpret the rest of the struct. 62*5ff13fbcSAllan Jude */ 63*5ff13fbcSAllan Jude unsigned version; 64*5ff13fbcSAllan Jude /** 65*5ff13fbcSAllan Jude * Non-zero if streaming (de)compression is used. 66*5ff13fbcSAllan Jude */ 67*5ff13fbcSAllan Jude unsigned streaming; 68*5ff13fbcSAllan Jude /** 69*5ff13fbcSAllan Jude * The dictionary ID. 70*5ff13fbcSAllan Jude */ 71*5ff13fbcSAllan Jude unsigned dictionaryID; 72*5ff13fbcSAllan Jude /** 73*5ff13fbcSAllan Jude * Is the dictionary cold? 74*5ff13fbcSAllan Jude * Only set on decompression. 75*5ff13fbcSAllan Jude */ 76*5ff13fbcSAllan Jude unsigned dictionaryIsCold; 77*5ff13fbcSAllan Jude /** 78*5ff13fbcSAllan Jude * The dictionary size or zero if no dictionary. 79*5ff13fbcSAllan Jude */ 80*5ff13fbcSAllan Jude size_t dictionarySize; 81*5ff13fbcSAllan Jude /** 82*5ff13fbcSAllan Jude * The uncompressed size of the data. 83*5ff13fbcSAllan Jude */ 84*5ff13fbcSAllan Jude size_t uncompressedSize; 85*5ff13fbcSAllan Jude /** 86*5ff13fbcSAllan Jude * The compressed size of the data. 87*5ff13fbcSAllan Jude */ 88*5ff13fbcSAllan Jude size_t compressedSize; 89*5ff13fbcSAllan Jude /** 90*5ff13fbcSAllan Jude * The fully resolved CCtx parameters (NULL on decompression). 91*5ff13fbcSAllan Jude */ 92*5ff13fbcSAllan Jude struct ZSTD_CCtx_params_s const* params; 93*5ff13fbcSAllan Jude /** 94*5ff13fbcSAllan Jude * The ZSTD_CCtx pointer (NULL on decompression). 95*5ff13fbcSAllan Jude */ 96*5ff13fbcSAllan Jude struct ZSTD_CCtx_s const* cctx; 97*5ff13fbcSAllan Jude /** 98*5ff13fbcSAllan Jude * The ZSTD_DCtx pointer (NULL on compression). 99*5ff13fbcSAllan Jude */ 100*5ff13fbcSAllan Jude struct ZSTD_DCtx_s const* dctx; 101*5ff13fbcSAllan Jude } ZSTD_Trace; 102*5ff13fbcSAllan Jude 103*5ff13fbcSAllan Jude /** 104*5ff13fbcSAllan Jude * A tracing context. It must be 0 when tracing is disabled. 105*5ff13fbcSAllan Jude * Otherwise, any non-zero value returned by a tracing begin() 106*5ff13fbcSAllan Jude * function is presented to any subsequent calls to end(). 107*5ff13fbcSAllan Jude * 108*5ff13fbcSAllan Jude * Any non-zero value is treated as tracing is enabled and not 109*5ff13fbcSAllan Jude * interpreted by the library. 110*5ff13fbcSAllan Jude * 111*5ff13fbcSAllan Jude * Two possible uses are: 112*5ff13fbcSAllan Jude * * A timestamp for when the begin() function was called. 113*5ff13fbcSAllan Jude * * A unique key identifying the (de)compression, like the 114*5ff13fbcSAllan Jude * address of the [dc]ctx pointer if you need to track 115*5ff13fbcSAllan Jude * more information than just a timestamp. 116*5ff13fbcSAllan Jude */ 117*5ff13fbcSAllan Jude typedef unsigned long long ZSTD_TraceCtx; 118*5ff13fbcSAllan Jude 119*5ff13fbcSAllan Jude /** 120*5ff13fbcSAllan Jude * Trace the beginning of a compression call. 121*5ff13fbcSAllan Jude * @param cctx The dctx pointer for the compression. 122*5ff13fbcSAllan Jude * It can be used as a key to map begin() to end(). 123*5ff13fbcSAllan Jude * @returns Non-zero if tracing is enabled. The return value is 124*5ff13fbcSAllan Jude * passed to ZSTD_trace_compress_end(). 125*5ff13fbcSAllan Jude */ 126*5ff13fbcSAllan Jude ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin( 127*5ff13fbcSAllan Jude struct ZSTD_CCtx_s const* cctx); 128*5ff13fbcSAllan Jude 129*5ff13fbcSAllan Jude /** 130*5ff13fbcSAllan Jude * Trace the end of a compression call. 131*5ff13fbcSAllan Jude * @param ctx The return value of ZSTD_trace_compress_begin(). 132*5ff13fbcSAllan Jude * @param trace The zstd tracing info. 133*5ff13fbcSAllan Jude */ 134*5ff13fbcSAllan Jude ZSTD_WEAK_ATTR void ZSTD_trace_compress_end( 135*5ff13fbcSAllan Jude ZSTD_TraceCtx ctx, 136*5ff13fbcSAllan Jude ZSTD_Trace const* trace); 137*5ff13fbcSAllan Jude 138*5ff13fbcSAllan Jude /** 139*5ff13fbcSAllan Jude * Trace the beginning of a decompression call. 140*5ff13fbcSAllan Jude * @param dctx The dctx pointer for the decompression. 141*5ff13fbcSAllan Jude * It can be used as a key to map begin() to end(). 142*5ff13fbcSAllan Jude * @returns Non-zero if tracing is enabled. The return value is 143*5ff13fbcSAllan Jude * passed to ZSTD_trace_compress_end(). 144*5ff13fbcSAllan Jude */ 145*5ff13fbcSAllan Jude ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin( 146*5ff13fbcSAllan Jude struct ZSTD_DCtx_s const* dctx); 147*5ff13fbcSAllan Jude 148*5ff13fbcSAllan Jude /** 149*5ff13fbcSAllan Jude * Trace the end of a decompression call. 150*5ff13fbcSAllan Jude * @param ctx The return value of ZSTD_trace_decompress_begin(). 151*5ff13fbcSAllan Jude * @param trace The zstd tracing info. 152*5ff13fbcSAllan Jude */ 153*5ff13fbcSAllan Jude ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end( 154*5ff13fbcSAllan Jude ZSTD_TraceCtx ctx, 155*5ff13fbcSAllan Jude ZSTD_Trace const* trace); 156*5ff13fbcSAllan Jude 157*5ff13fbcSAllan Jude #endif /* ZSTD_TRACE */ 158*5ff13fbcSAllan Jude 159*5ff13fbcSAllan Jude #if defined (__cplusplus) 160*5ff13fbcSAllan Jude } 161*5ff13fbcSAllan Jude #endif 162*5ff13fbcSAllan Jude 163*5ff13fbcSAllan Jude #endif /* ZSTD_TRACE_H */ 164