]>
git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/adaptive-compression/datagencli.c
2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
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).
11 /*-************************************
13 **************************************/
14 #include "util.h" /* Compiler options */
15 #include <stdio.h> /* fprintf, stderr */
16 #include "datagen.h" /* RDG_generate */
19 /*-************************************
21 **************************************/
26 #define SIZE_DEFAULT ((64 KB) + 1)
27 #define SEED_DEFAULT 0
28 #define COMPRESSIBILITY_DEFAULT 50
31 /*-************************************
33 **************************************/
34 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
35 #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
36 static unsigned displayLevel
= 2;
39 /*-*******************************************************
41 *********************************************************/
42 static int usage(const char* programName
)
44 DISPLAY( "Compressible data generator\n");
45 DISPLAY( "Usage :\n");
46 DISPLAY( " %s [args]\n", programName
);
48 DISPLAY( "Arguments :\n");
49 DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT
);
50 DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT
);
51 DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n",
52 COMPRESSIBILITY_DEFAULT
);
53 DISPLAY( " -h : display help and exit\n");
58 int main(int argc
, const char** argv
)
60 unsigned probaU32
= COMPRESSIBILITY_DEFAULT
;
61 double litProba
= 0.0;
62 U64 size
= SIZE_DEFAULT
;
63 U32 seed
= SEED_DEFAULT
;
64 const char* const programName
= argv
[0];
67 for(argNb
=1; argNb
<argc
; argNb
++) {
68 const char* argument
= argv
[argNb
];
70 if(!argument
) continue; /* Protection if argument empty */
72 /* Handle commands. Aggregated commands are allowed */
75 while (*argument
!=0) {
79 return usage(programName
);
83 while ((*argument
>='0') && (*argument
<='9'))
84 size
*= 10, size
+= *argument
++ - '0';
85 if (*argument
=='K') { size
<<= 10; argument
++; }
86 if (*argument
=='M') { size
<<= 20; argument
++; }
87 if (*argument
=='G') { size
<<= 30; argument
++; }
88 if (*argument
=='B') { argument
++; }
93 while ((*argument
>='0') && (*argument
<='9'))
94 seed
*= 10, seed
+= *argument
++ - '0';
99 while ((*argument
>='0') && (*argument
<='9'))
100 probaU32
*= 10, probaU32
+= *argument
++ - '0';
101 if (probaU32
>100) probaU32
= 100;
103 case 'L': /* hidden argument : Literal distribution probability */
106 while ((*argument
>='0') && (*argument
<='9'))
107 litProba
*= 10, litProba
+= *argument
++ - '0';
108 if (litProba
>100.) litProba
=100.;
116 return usage(programName
);
118 } } } /* for(argNb=1; argNb<argc; argNb++) */
120 DISPLAYLEVEL(4, "Compressible data Generator \n");
121 if (probaU32
!=COMPRESSIBILITY_DEFAULT
)
122 DISPLAYLEVEL(3, "Compressibility : %i%%\n", probaU32
);
123 DISPLAYLEVEL(3, "Seed = %u \n", (unsigned)seed
);
125 RDG_genStdout(size
, (double)probaU32
/100, litProba
, seed
);
126 DISPLAYLEVEL(1, "\n");