You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zstd_trace.h 4.5KB

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