-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add (de)compression tracing functionality #2482
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2016-2021, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under both the BSD-style license (found in the | ||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found | ||
* in the COPYING file in the root directory of this source tree). | ||
* You may select, at your option, one of the above-listed licenses. | ||
*/ | ||
|
||
#include "zstd_trace.h" | ||
#include "../zstd.h" | ||
|
||
#include "compiler.h" | ||
|
||
#if ZSTD_TRACE && ZSTD_HAVE_WEAK_SYMBOLS | ||
|
||
ZSTD_WEAK_ATTR int ZSTD_trace_compress_begin(ZSTD_CCtx const* cctx) | ||
{ | ||
(void)cctx; | ||
return 0; | ||
} | ||
|
||
ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(ZSTD_CCtx const* cctx, ZSTD_trace const* trace) | ||
{ | ||
(void)cctx; | ||
(void)trace; | ||
} | ||
|
||
ZSTD_WEAK_ATTR int ZSTD_trace_decompress_begin(ZSTD_DCtx const* dctx) | ||
{ | ||
(void)dctx; | ||
return 0; | ||
} | ||
|
||
ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(ZSTD_DCtx const* dctx, ZSTD_trace const* trace) | ||
{ | ||
(void)dctx; | ||
(void)trace; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (c) 2016-2021, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under both the BSD-style license (found in the | ||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found | ||
* in the COPYING file in the root directory of this source tree). | ||
* You may select, at your option, one of the above-listed licenses. | ||
*/ | ||
|
||
#ifndef ZSTD_TRACE_H | ||
#define ZSTD_TRACE_H | ||
|
||
#include <stddef.h> | ||
|
||
/* weak symbol support */ | ||
#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && defined(__GNUC__) && \ | ||
!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \ | ||
!defined(__CYGWIN__) | ||
# define ZSTD_HAVE_WEAK_SYMBOLS 1 | ||
#else | ||
# define ZSTD_HAVE_WEAK_SYMBOLS 0 | ||
#endif | ||
#if ZSTD_HAVE_WEAK_SYMBOLS | ||
# define ZSTD_WEAK_ATTR __attribute__((__weak__)) | ||
#else | ||
# define ZSTD_WEAK_ATTR | ||
#endif | ||
|
||
/* Only enable tracing when weak symbols are available. */ | ||
#ifndef ZSTD_TRACE | ||
# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS | ||
#endif | ||
|
||
#if ZSTD_TRACE | ||
|
||
struct ZSTD_CCtx_s; | ||
struct ZSTD_DCtx_s; | ||
struct ZSTD_CCtx_params_s; | ||
|
||
typedef struct { | ||
/** | ||
* ZSTD_VERSION_NUMBER | ||
* | ||
* This is guaranteed to be the first member of ZSTD_trace. | ||
* Otherwise, this struct is not stable between versions. If | ||
* the version number does not match your expectation, you | ||
* should not interpret the rest of the struct. | ||
*/ | ||
unsigned version; | ||
/** | ||
* Non-zero if streaming (de)compression is used. | ||
*/ | ||
unsigned streaming; | ||
/** | ||
* The dictionary ID. | ||
*/ | ||
unsigned dictionaryID; | ||
/** | ||
* Is the dictionary cold? | ||
* Only set on decompression. | ||
*/ | ||
unsigned dictionaryIsCold; | ||
/** | ||
* The dictionary size or zero if no dictionary. | ||
*/ | ||
size_t dictionarySize; | ||
/** | ||
* The uncompressed size of the data. | ||
*/ | ||
size_t uncompressedSize; | ||
/** | ||
* The compressed size of the data. | ||
*/ | ||
size_t compressedSize; | ||
/** | ||
* The fully resolved CCtx parameters (NULL on decompression). | ||
*/ | ||
struct ZSTD_CCtx_params_s const* params; | ||
} ZSTD_trace; | ||
|
||
/** | ||
* Trace the beginning of a compression call. | ||
* @param cctx The dctx pointer for the compression. | ||
* It can be used as a key to map begin() to end(). | ||
* @returns Non-zero if tracing is enabled. | ||
*/ | ||
int ZSTD_trace_compress_begin(struct ZSTD_CCtx_s const* cctx); | ||
|
||
/** | ||
* Trace the end of a compression call. | ||
* @param cctx The dctx pointer for the decompression. | ||
* @param trace The zstd tracing info. | ||
*/ | ||
void ZSTD_trace_compress_end( | ||
struct ZSTD_CCtx_s const* cctx, | ||
ZSTD_trace const* trace); | ||
|
||
/** | ||
* Trace the beginning of a decompression call. | ||
* @param dctx The dctx pointer for the decompression. | ||
* It can be used as a key to map begin() to end(). | ||
* @returns Non-zero if tracing is enabled. | ||
*/ | ||
int ZSTD_trace_decompress_begin(struct ZSTD_DCtx_s const* dctx); | ||
|
||
/** | ||
* Trace the end of a decompression call. | ||
* @param dctx The dctx pointer for the decompression. | ||
* @param trace The zstd tracing info. | ||
*/ | ||
void ZSTD_trace_decompress_end( | ||
struct ZSTD_DCtx_s const* dctx, | ||
ZSTD_trace const* trace); | ||
|
||
#endif /* ZSTD_TRACE */ | ||
|
||
#endif /* ZSTD_TRACE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, by default, these functions exist but don't do anything,
they need to be replaced in target binary by real functions that are actually doing something
which is possible thanks to weak linking.
I wonder if there is a (future) opportunity here to have some "good enough" default functions, instead of empty ones,
although to be fair I don't know the topic nearly enough to tell if it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We (zstd) don't really know what to do with the data that is provided. So by default we just disable the tracing, so the cost is only one function call + one branch per (de)compression.
We could also introduce other methods of tracing in the future, like attaching the tracing functions to the cctx/dctx itself.