]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/adaptive-compression/datagencli.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / zstd / contrib / adaptive-compression / datagencli.c
1 /*
2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 * All rights reserved.
4 *
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).
8 */
9
10
11 /*-************************************
12 * Dependencies
13 **************************************/
14 #include "util.h" /* Compiler options */
15 #include <stdio.h> /* fprintf, stderr */
16 #include "datagen.h" /* RDG_generate */
17
18
19 /*-************************************
20 * Constants
21 **************************************/
22 #define KB *(1 <<10)
23 #define MB *(1 <<20)
24 #define GB *(1U<<30)
25
26 #define SIZE_DEFAULT ((64 KB) + 1)
27 #define SEED_DEFAULT 0
28 #define COMPRESSIBILITY_DEFAULT 50
29
30
31 /*-************************************
32 * Macros
33 **************************************/
34 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
35 #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
36 static unsigned displayLevel = 2;
37
38
39 /*-*******************************************************
40 * Command line
41 *********************************************************/
42 static int usage(const char* programName)
43 {
44 DISPLAY( "Compressible data generator\n");
45 DISPLAY( "Usage :\n");
46 DISPLAY( " %s [args]\n", programName);
47 DISPLAY( "\n");
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");
54 return 0;
55 }
56
57
58 int main(int argc, const char** argv)
59 {
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];
65
66 int argNb;
67 for(argNb=1; argNb<argc; argNb++) {
68 const char* argument = argv[argNb];
69
70 if(!argument) continue; /* Protection if argument empty */
71
72 /* Handle commands. Aggregated commands are allowed */
73 if (*argument=='-') {
74 argument++;
75 while (*argument!=0) {
76 switch(*argument)
77 {
78 case 'h':
79 return usage(programName);
80 case 'g':
81 argument++;
82 size=0;
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++; }
89 break;
90 case 's':
91 argument++;
92 seed=0;
93 while ((*argument>='0') && (*argument<='9'))
94 seed *= 10, seed += *argument++ - '0';
95 break;
96 case 'P':
97 argument++;
98 probaU32 = 0;
99 while ((*argument>='0') && (*argument<='9'))
100 probaU32 *= 10, probaU32 += *argument++ - '0';
101 if (probaU32>100) probaU32 = 100;
102 break;
103 case 'L': /* hidden argument : Literal distribution probability */
104 argument++;
105 litProba=0.;
106 while ((*argument>='0') && (*argument<='9'))
107 litProba *= 10, litProba += *argument++ - '0';
108 if (litProba>100.) litProba=100.;
109 litProba /= 100.;
110 break;
111 case 'v':
112 displayLevel = 4;
113 argument++;
114 break;
115 default:
116 return usage(programName);
117 }
118 } } } /* for(argNb=1; argNb<argc; argNb++) */
119
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);
124
125 RDG_genStdout(size, (double)probaU32/100, litProba, seed);
126 DISPLAYLEVEL(1, "\n");
127
128 return 0;
129 }