]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/isa-l/igzip/igzip_hist_perf.c
da37d3eb3fa212f705f5a17a8fce4af9d35dfe50
[ceph.git] / ceph / src / spdk / isa-l / igzip / igzip_hist_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29
30 #define _FILE_OFFSET_BITS 64
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <string.h>
35 #include "igzip_lib.h"
36 #include "test.h"
37
38 #define BUF_SIZE 1024
39 #define MIN_TEST_LOOPS 8
40 #ifndef RUN_MEM_SIZE
41 # define RUN_MEM_SIZE 2000000000
42 #endif
43
44 void print_histogram(struct isal_huff_histogram *histogram)
45 {
46 int i;
47 printf("Lit Len histogram");
48 for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
49 if (i % 16 == 0)
50 printf("\n");
51 else
52 printf(", ");
53 printf("%4lu", histogram->lit_len_histogram[i]);
54 }
55 printf("\n");
56
57 printf("Dist histogram");
58 for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
59 if (i % 16 == 0)
60 printf("\n");
61 else
62 printf(", ");
63 printf("%4lu", histogram->dist_histogram[i]);
64 }
65 printf("\n");
66 }
67
68 int main(int argc, char *argv[])
69 {
70 FILE *in;
71 unsigned char *inbuf, *outbuf;
72 int i, iterations, avail_in;
73 uint64_t infile_size, outbuf_size;
74 struct isal_huff_histogram histogram1, histogram2;
75
76 memset(&histogram1, 0, sizeof(histogram1));
77 memset(&histogram2, 0, sizeof(histogram2));
78
79 if (argc > 3 || argc < 2) {
80 fprintf(stderr, "Usage: igzip_file_perf infile [outfile]\n"
81 "\t - Runs multiple iterations of igzip on a file to "
82 "get more accurate time results.\n");
83 exit(0);
84 }
85 in = fopen(argv[1], "rb");
86 if (!in) {
87 fprintf(stderr, "Can't open %s for reading\n", argv[1]);
88 exit(0);
89 }
90
91 /* Allocate space for entire input file and output
92 * (assuming some possible expansion on output size)
93 */
94 infile_size = get_filesize(in);
95 outbuf_size = 2 * infile_size;
96
97 if (infile_size != 0)
98 iterations = RUN_MEM_SIZE / infile_size;
99 else
100 iterations = MIN_TEST_LOOPS;
101
102 if (iterations < MIN_TEST_LOOPS)
103 iterations = MIN_TEST_LOOPS;
104
105 inbuf = malloc(infile_size);
106 outbuf = malloc(outbuf_size);
107 if (inbuf == NULL) {
108 fprintf(stderr, "Can't allocate input buffer memory\n");
109 exit(0);
110 }
111
112 if (outbuf == NULL) {
113 fprintf(stderr, "Can't allocate output buffer memory\n");
114 exit(0);
115 }
116
117 avail_in = fread(inbuf, 1, infile_size, in);
118 if (avail_in != infile_size) {
119 fprintf(stderr, "Couldn't fit all of input file into buffer\n");
120 exit(0);
121 }
122
123 struct perf start, stop;
124 perf_start(&start);
125
126 for (i = 0; i < iterations; i++)
127 isal_update_histogram(inbuf, infile_size, &histogram1);
128 perf_stop(&stop);
129
130 printf(" file %s - in_size=%lu iter=%d\n", argv[1], infile_size, i);
131 printf("igzip_file: ");
132 perf_print(stop, start, (long long)infile_size * i);
133
134 fclose(in);
135 fflush(0);
136 return 0;
137 }