add support for environment variable LZ4_CLEVEL
This commit is contained in:
@@ -27,6 +27,7 @@ The makefile offer several targets for various use cases:
|
||||
These variables are read by the preprocessor at compilation time. They influence executable behavior, such as default starting values, and are exposed from `programs/lz4conf.h`. These variables can manipulated by any build system.
|
||||
Assignment methods vary depending on environments.
|
||||
On a typical `posix` + `gcc` + `make` setup, they can be defined with `CPPFLAGS=-DVARIABLE=value` assignment.
|
||||
- `LZ4_CLEVEL_DEFAULT`: default compression level when none provided. Default is `1`.
|
||||
- `LZ4IO_MULTITHREAD`: enable multithreading support. Default is disabled.
|
||||
- `LZ4_NBWORKERS_DEFAULT`: default nb of worker threads used in multithreading mode (can be overridden with command `-T#`).
|
||||
Default is `0`, which means "auto-determine" based on local cpu.
|
||||
@@ -37,11 +38,13 @@ On a typical `posix` + `gcc` + `make` setup, they can be defined with `CPPFLAGS=
|
||||
|
||||
#### Environment Variables
|
||||
It's possible to pass some parameters to `lz4` via environment variables.
|
||||
This can be useful in situations where `lz4` is known to be invoked (from a script for example) but there is no way to pass `lz4` parameters to influence the compression session.
|
||||
This can be useful in situations where `lz4` is known to be invoked (from within a script for example) but there is no way to pass `lz4` parameters to influence the compression session.
|
||||
The environment variable has higher priority than binary default, but lower priority than corresponding runtime command.
|
||||
When set as global environment variables, it can be a way to enforce personalized defaults different from the binary set ones.
|
||||
When set as global environment variables, it can enforce personalized defaults different from the binary set ones.
|
||||
|
||||
`LZ4_NBWORKERS` can be used to specify a default number of threads that `lz4` will use for compression (binary default is generally `0`, which means auto-determined based on local cpu). This functionality is only relevant when `lz4` is compiled with multithreading support. The maximum number of workers is capped at `LZ4_NBWORKERS_MAX` (`200` by default).
|
||||
`LZ4_CLEVEL` can be used to specify a default compression level that `lz4` employs for compression when no other compression level is specified on command line. Executable default is generally `1`.
|
||||
|
||||
`LZ4_NBWORKERS` can be used to specify a default number of threads that `lz4` will employ for compression. Executable default is generally `0`, which means auto-determined based on local cpu. This functionality is only relevant when `lz4` is compiled with multithreading support. The maximum number of workers is capped at `LZ4_NBWORKERS_MAX` (`200` by default).
|
||||
|
||||
### Aggregation of parameters
|
||||
The `lz4` CLI supports aggregation for short commands. For example, `-d`, `-q`, and `-f` can be joined into `-dqf`.
|
||||
|
@@ -250,11 +250,14 @@ only the latest one will be applied.
|
||||
|
||||
It's possible to pass some parameters to `lz4` via environment variables.
|
||||
This can be useful in situations where `lz4` is known to be invoked (from a script for example) but there is no way to pass `lz4` parameters to influence the compression session.
|
||||
The environment variable has higher priority than binary default, but lower priority than corresponding runtime command.
|
||||
When set as global environment variables, it can be a way to enforce personalized defaults different from the binary set ones.
|
||||
The environment variable has higher priority than executable default, but lower priority than corresponding runtime command.
|
||||
When set as global environment variables, it can be a way to enforce personalized defaults different from the executable set ones.
|
||||
|
||||
* `LZ4_CLEVEL`:
|
||||
specify a default compression level that `lz4` employs for compression when no other compression level is specified on command line. Executable default is generally `1`.
|
||||
|
||||
* `LZ4_NBWORKERS`:
|
||||
specify a default number of threads that `lz4` will employ for compression (binary default is generally `0`, which means auto-determined based on local cpu). This functionality is only relevant when `lz4` is compiled with multithreading support. The maximum number of workers is capped at `LZ4_NBWORKERS_MAX` (`200` by default).
|
||||
specify a default number of threads that `lz4` will employ for compression. Executable default is generally `0`, which means auto-determined based on local cpu. This functionality is only relevant when `lz4` is compiled with multithreading support. The maximum number of workers is capped at `LZ4_NBWORKERS_MAX` (`200` by default).
|
||||
|
||||
|
||||
BUGS
|
||||
|
@@ -370,10 +370,25 @@ static unsigned init_nbWorkers(void)
|
||||
return LZ4_NBWORKERS_DEFAULT;
|
||||
}
|
||||
|
||||
#define ENV_CLEVEL "LZ4_CLEVEL"
|
||||
|
||||
static int init_cLevel(void)
|
||||
{
|
||||
const char* const env = getenv(ENV_CLEVEL);
|
||||
if (env != NULL) {
|
||||
const char* ptr = env;
|
||||
if ((*ptr>='0') && (*ptr<='9')) {
|
||||
return (int)readU32FromChar(&ptr);
|
||||
}
|
||||
DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: not a valid unsigned value \n", ENV_CLEVEL, env);
|
||||
}
|
||||
return LZ4_CLEVEL_DEFAULT;
|
||||
}
|
||||
|
||||
int main(int argCount, const char** argv)
|
||||
{
|
||||
int argNb,
|
||||
cLevel=1,
|
||||
cLevel=init_cLevel(),
|
||||
cLevelLast=-10000,
|
||||
legacy_format=0,
|
||||
forceStdout=0,
|
||||
|
@@ -26,7 +26,15 @@
|
||||
#define LZ4CONF_H_32432
|
||||
|
||||
|
||||
/* Determines if multithreading is enabled or not */
|
||||
/* Default compression level.
|
||||
* Can be overridden by environment variable LZ4_CLEVEL.
|
||||
* Can be overridden at runtime using -# command */
|
||||
#ifndef LZ4_CLEVEL_DEFAULT
|
||||
# define LZ4_CLEVEL_DEFAULT 1
|
||||
#endif
|
||||
|
||||
/* Determines if multithreading is enabled or not
|
||||
* Default: disabled */
|
||||
#ifndef LZ4IO_MULTITHREAD
|
||||
# ifdef _WIN32
|
||||
/* Windows support Completion Ports */
|
||||
|
Reference in New Issue
Block a user