[trace] Keep track of a uint64_t tracing context
The most common information that you want to track between begin() and end() is the timestamp of the begin function, so you can measure the duration of the (de)compression call. Allow the tracing library to put this information inside the `ZSTD_TraceCtx`, so it doesn't need to keep a global map in this case. If a single uint64_t is not enough, the tracing library can return a unique identifier (like the context pointer) instead, and use it as a key in a map. This keeps the simple case simple.
This commit is contained in:
@@ -3386,7 +3386,7 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
|
||||
ZSTD_buffered_policy_e zbuff)
|
||||
{
|
||||
#if ZSTD_TRACE
|
||||
cctx->tracingEnabled = ZSTD_trace_compress_begin(cctx);
|
||||
cctx->traceCtx = ZSTD_trace_compress_begin(cctx);
|
||||
#endif
|
||||
DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog);
|
||||
/* params are supposed to be fully validated at this point */
|
||||
@@ -3512,12 +3512,12 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
||||
return op-ostart;
|
||||
}
|
||||
|
||||
static void ZSTD_CCtx_trace(ZSTD_CCtx const* cctx, size_t extraCSize)
|
||||
void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize)
|
||||
{
|
||||
#if ZSTD_TRACE
|
||||
if (cctx->tracingEnabled) {
|
||||
if (cctx->traceCtx) {
|
||||
int const streaming = cctx->inBuffSize > 0 || cctx->outBuffSize > 0 || cctx->appliedParams.nbWorkers > 0;
|
||||
ZSTD_trace trace;
|
||||
ZSTD_Trace trace;
|
||||
ZSTD_memset(&trace, 0, sizeof(trace));
|
||||
trace.version = ZSTD_VERSION_NUMBER;
|
||||
trace.streaming = streaming;
|
||||
@@ -3526,8 +3526,10 @@ static void ZSTD_CCtx_trace(ZSTD_CCtx const* cctx, size_t extraCSize)
|
||||
trace.uncompressedSize = cctx->consumedSrcSize;
|
||||
trace.compressedSize = cctx->producedCSize + extraCSize;
|
||||
trace.params = &cctx->appliedParams;
|
||||
ZSTD_trace_compress_end(cctx, &trace);
|
||||
trace.cctx = cctx;
|
||||
ZSTD_trace_compress_end(cctx->traceCtx, &trace);
|
||||
}
|
||||
cctx->traceCtx = 0;
|
||||
#else
|
||||
(void)cctx;
|
||||
(void)extraCSize;
|
||||
@@ -4441,7 +4443,7 @@ static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx,
|
||||
}
|
||||
if (params.nbWorkers > 0) {
|
||||
#if ZSTD_TRACE
|
||||
cctx->tracingEnabled = ZSTD_trace_compress_begin(cctx);
|
||||
cctx->traceCtx = ZSTD_trace_compress_begin(cctx);
|
||||
#endif
|
||||
/* mt context creation */
|
||||
if (cctx->mtctx == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user