zstd_trace.h 4.2 KB

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