From cec205c8421413e90dd052237a1a18fbe09852b1 Mon Sep 17 00:00:00 2001 From: George Lu Date: Thu, 31 May 2018 17:39:36 -0700 Subject: [PATCH 1/7] copy paste --- tests/paramgrill.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 3172ab06..2cd41e83 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -177,6 +177,35 @@ BMK_benchParam(BMK_result_t* resultPtr, resultPtr->cSpeed = 0.; resultPtr->dSpeed = 0.; + /* parse arg, wip */ + if (longCommandWArg(&argument, "--zstd=")) { if (!parseCompressionParameters(argument, &compressionParams)) CLEAN_RETURN(badusage(programName)); continue; } + +/* +static unsigned parseCompressionParameters(const char* stringPtr, ZSTD_compressionParameters* params) +{ + for ( ; ;) { + if (longCommandWArg(&stringPtr, "windowLog=") || longCommandWArg(&stringPtr, "wlog=")) { params->windowLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "chainLog=") || longCommandWArg(&stringPtr, "clog=")) { params->chainLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "hashLog=") || longCommandWArg(&stringPtr, "hlog=")) { params->hashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "searchLog=") || longCommandWArg(&stringPtr, "slog=")) { params->searchLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "searchLength=") || longCommandWArg(&stringPtr, "slen=")) { params->searchLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "targetLength=") || longCommandWArg(&stringPtr, "tlen=")) { params->targetLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "strategy=") || longCommandWArg(&stringPtr, "strat=")) { params->strategy = (ZSTD_strategy)(readU32FromChar(&stringPtr)); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "overlapLog=") || longCommandWArg(&stringPtr, "ovlog=")) { g_overlapLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "ldmHashLog=") || longCommandWArg(&stringPtr, "ldmhlog=")) { g_ldmHashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "ldmSearchLength=") || longCommandWArg(&stringPtr, "ldmslen=")) { g_ldmMinMatch = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "ldmBucketSizeLog=") || longCommandWArg(&stringPtr, "ldmblog=")) { g_ldmBucketSizeLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + if (longCommandWArg(&stringPtr, "ldmHashEveryLog=") || longCommandWArg(&stringPtr, "ldmhevery=")) { g_ldmHashEveryLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } + DISPLAYLEVEL(4, "invalid compression parameter \n"); + return 0; + } + + DISPLAYLEVEL(4, "windowLog=%d, chainLog=%d, hashLog=%d, searchLog=%d \n", params->windowLog, params->chainLog, params->hashLog, params->searchLog); + DISPLAYLEVEL(4, "searchLength=%d, targetLength=%d, strategy=%d \n", params->searchLength, params->targetLength, params->strategy); + if (stringPtr[0] != 0) return 0; /* check the end of string */ + return 1; +} +*/ /* Memory allocation & restrictions */ snprintf(name, 30, "Sw%02uc%02uh%02us%02ul%1ut%03uS%1u", Wlog, Clog, Hlog, Slog, Slength, Tlength, strat); if (!compressedBuffer || !resultBuffer || !blockTable) { From c9b4d20f02eb50d156aaae6cf2d3787c36dd71d5 Mon Sep 17 00:00:00 2001 From: George Lu Date: Fri, 1 Jun 2018 12:39:39 -0700 Subject: [PATCH 2/7] Added new --zstd= format --- tests/paramgrill.c | 63 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 2cd41e83..68c573f8 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -127,6 +127,19 @@ U32 FUZ_rand(U32* src) return rand32 >> 5; } +/** longCommandWArg() : + * check if *stringPtr is the same as longCommand. + * If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand. + * @return 0 and doesn't modify *stringPtr otherwise. + * from zstdcli.c + */ +static unsigned longCommandWArg(const char** stringPtr, const char* longCommand) +{ + size_t const comSize = strlen(longCommand); + int const result = !strncmp(*stringPtr, longCommand, comSize); + if (result) *stringPtr += comSize; + return result; +} /*-******************************************************* * Bench functions @@ -177,35 +190,6 @@ BMK_benchParam(BMK_result_t* resultPtr, resultPtr->cSpeed = 0.; resultPtr->dSpeed = 0.; - /* parse arg, wip */ - if (longCommandWArg(&argument, "--zstd=")) { if (!parseCompressionParameters(argument, &compressionParams)) CLEAN_RETURN(badusage(programName)); continue; } - -/* -static unsigned parseCompressionParameters(const char* stringPtr, ZSTD_compressionParameters* params) -{ - for ( ; ;) { - if (longCommandWArg(&stringPtr, "windowLog=") || longCommandWArg(&stringPtr, "wlog=")) { params->windowLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "chainLog=") || longCommandWArg(&stringPtr, "clog=")) { params->chainLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "hashLog=") || longCommandWArg(&stringPtr, "hlog=")) { params->hashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "searchLog=") || longCommandWArg(&stringPtr, "slog=")) { params->searchLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "searchLength=") || longCommandWArg(&stringPtr, "slen=")) { params->searchLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "targetLength=") || longCommandWArg(&stringPtr, "tlen=")) { params->targetLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "strategy=") || longCommandWArg(&stringPtr, "strat=")) { params->strategy = (ZSTD_strategy)(readU32FromChar(&stringPtr)); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "overlapLog=") || longCommandWArg(&stringPtr, "ovlog=")) { g_overlapLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "ldmHashLog=") || longCommandWArg(&stringPtr, "ldmhlog=")) { g_ldmHashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "ldmSearchLength=") || longCommandWArg(&stringPtr, "ldmslen=")) { g_ldmMinMatch = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "ldmBucketSizeLog=") || longCommandWArg(&stringPtr, "ldmblog=")) { g_ldmBucketSizeLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - if (longCommandWArg(&stringPtr, "ldmHashEveryLog=") || longCommandWArg(&stringPtr, "ldmhevery=")) { g_ldmHashEveryLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } - DISPLAYLEVEL(4, "invalid compression parameter \n"); - return 0; - } - - DISPLAYLEVEL(4, "windowLog=%d, chainLog=%d, hashLog=%d, searchLog=%d \n", params->windowLog, params->chainLog, params->hashLog, params->searchLog); - DISPLAYLEVEL(4, "searchLength=%d, targetLength=%d, strategy=%d \n", params->searchLength, params->targetLength, params->strategy); - if (stringPtr[0] != 0) return 0; /* check the end of string */ - return 1; -} -*/ /* Memory allocation & restrictions */ snprintf(name, 30, "Sw%02uc%02uh%02us%02ul%1ut%03uS%1u", Wlog, Clog, Hlog, Slog, Slength, Tlength, strat); if (!compressedBuffer || !resultBuffer || !blockTable) { @@ -1001,7 +985,25 @@ int main(int argc, const char** argv) if(!strcmp(argument,"--no-seed")) { g_noSeed = 1; continue; } /* Decode command (note : aggregated commands are allowed) */ - if (argument[0]=='-') { + if (longCommandWArg(&argument, "--zstd=")) { + g_singleRun = 1; + g_params = ZSTD_getCParams(2, g_blockSize, 0); + for ( ; ;) { + if (longCommandWArg(&argument, "windowLog=") || longCommandWArg(&argument, "wlog=")) { g_params.windowLog = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "chainLog=") || longCommandWArg(&argument, "clog=")) { g_params.chainLog = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "hashLog=") || longCommandWArg(&argument, "hlog=")) { g_params.hashLog = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "searchLog=") || longCommandWArg(&argument, "slog=")) { g_params.searchLog = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "searchLength=") || longCommandWArg(&argument, "slen=")) { g_params.searchLength = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "targetLength=") || longCommandWArg(&argument, "tlen=")) { g_params.targetLength = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "strategy=") || longCommandWArg(&argument, "strat=")) { g_params.strategy = (ZSTD_strategy)(readU32FromChar(&argument)); if (argument[0]==',') { argument++; continue; } else break; } + DISPLAY("invalid compression parameter \n"); + return 1; + } + + if (argument[0] != 0) return 1; /* check the end of string */ + break; + //if not return, success + } else if (argument[0]=='-') { argument++; while (argument[0]!=0) { @@ -1080,6 +1082,7 @@ int main(int argc, const char** argv) } break; } + break; /* target level1 speed objective, in MB/s */ From ae6d1fd3fac9972700f3d68b68a19f558b459a05 Mon Sep 17 00:00:00 2001 From: George Lu Date: Fri, 1 Jun 2018 13:54:08 -0700 Subject: [PATCH 3/7] Add Error Print --- tests/paramgrill.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 68c573f8..58be12c5 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -1000,7 +1000,10 @@ int main(int argc, const char** argv) return 1; } - if (argument[0] != 0) return 1; /* check the end of string */ + if (argument[0] != 0) { + DISPLAY("invvalid --zstd= format\n"); + return 1; /* check the end of string */ + } break; //if not return, success } else if (argument[0]=='-') { From e355f0a5801f44544ae0871696b332de7865d42a Mon Sep 17 00:00:00 2001 From: George Lu Date: Fri, 1 Jun 2018 14:27:53 -0700 Subject: [PATCH 4/7] Added Level Option --- tests/paramgrill.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 58be12c5..ab1c45d5 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -996,12 +996,13 @@ int main(int argc, const char** argv) if (longCommandWArg(&argument, "searchLength=") || longCommandWArg(&argument, "slen=")) { g_params.searchLength = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } if (longCommandWArg(&argument, "targetLength=") || longCommandWArg(&argument, "tlen=")) { g_params.targetLength = readU32FromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; } if (longCommandWArg(&argument, "strategy=") || longCommandWArg(&argument, "strat=")) { g_params.strategy = (ZSTD_strategy)(readU32FromChar(&argument)); if (argument[0]==',') { argument++; continue; } else break; } + if (longCommandWArg(&argument, "level=") || longCommandWArg(&argument, "lvl=")) { g_params = ZSTD_getCParams(readU32FromChar(&argument), g_blockSize, 0); if (argument[0]==',') { argument++; continue; } else break; } DISPLAY("invalid compression parameter \n"); return 1; } if (argument[0] != 0) { - DISPLAY("invvalid --zstd= format\n"); + DISPLAY("invalid --zstd= format\n"); return 1; /* check the end of string */ } break; From 5e586aa0253fd2b0096cf1c3e3f3457540339bfe Mon Sep 17 00:00:00 2001 From: George Lu Date: Fri, 1 Jun 2018 18:02:56 -0700 Subject: [PATCH 5/7] -O# with no file fails --- tests/paramgrill.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index ab1c45d5..580e84ab 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -889,6 +889,7 @@ int optimizeForSize(const char* inFileName, U32 targetSpeed) /* end summary */ BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize); + BMK_translateAdvancedParams(winner.params); DISPLAY("grillParams size - optimizer completed \n"); /* clean up*/ @@ -1005,7 +1006,6 @@ int main(int argc, const char** argv) DISPLAY("invalid --zstd= format\n"); return 1; /* check the end of string */ } - break; //if not return, success } else if (argument[0]=='-') { argument++; @@ -1114,7 +1114,12 @@ int main(int argc, const char** argv) } if (filenamesStart==0) { - result = benchSample(); + if (optimizer) { + DISPLAY("Optimizer Expects File") + return 1; + } else { + result = benchSample(); + } } else { if (optimizer) { result = optimizeForSize(input_filename, targetSpeed); From ddf143ba6a387356789c2e64d5ac4a6f57c4709a Mon Sep 17 00:00:00 2001 From: George Lu Date: Mon, 4 Jun 2018 10:16:05 -0700 Subject: [PATCH 6/7] Update usage_advanced --- tests/paramgrill.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 580e84ab..c4b6932d 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -952,6 +952,7 @@ static int usage_advanced(void) DISPLAY( " -i# : iteration loops [1-9](default : %i) \n", NBLOOPS); DISPLAY( " -O# : find Optimized parameters for # MB/s compression speed (default : 0) \n"); DISPLAY( " -S : Single run \n"); + DISPLAY( " --zstd : Single run, parameter selection same as zstdcli \n"); DISPLAY( " -P# : generated sample compressibility (default : %.1f%%) \n", COMPRESSIBILITY_DEFAULT * 100); return 0; } From 3f054dceb4d33bf7555d559100c14de8f0d672d3 Mon Sep 17 00:00:00 2001 From: George Lu Date: Mon, 4 Jun 2018 13:38:37 -0700 Subject: [PATCH 7/7] forgot \n, ; --- tests/paramgrill.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index c4b6932d..44e3cb37 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -1116,7 +1116,7 @@ int main(int argc, const char** argv) if (filenamesStart==0) { if (optimizer) { - DISPLAY("Optimizer Expects File") + DISPLAY("Optimizer Expects File\n"); return 1; } else { result = benchSample();