1
by brian
clean slate |
1 |
/* Copyright (C) 2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
16 |
#include <config.h> |
1130.3.28
by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check. |
17 |
|
1
by brian
clean slate |
18 |
#include "azio.h" |
19 |
#include <string.h> |
|
20 |
#include <assert.h> |
|
21 |
#include <stdio.h> |
|
22 |
#include <stdlib.h> |
|
23 |
#include <string.h> |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
24 |
#include <fcntl.h> |
25 |
#include <sys/stat.h> |
|
1929.1.20
by Stewart Smith
fix large stack usage in archive_performance. azio_stream as auto_ptr |
26 |
#include <memory> |
1
by brian
clean slate |
27 |
|
481.1.15
by Monty Taylor
Removed time.h and sys/time.h from global.h. |
28 |
#if TIME_WITH_SYS_TIME
|
29 |
# include <sys/time.h>
|
|
30 |
# include <time.h>
|
|
31 |
#else
|
|
32 |
# if HAVE_SYS_TIME_H
|
|
33 |
# include <sys/time.h>
|
|
34 |
# else
|
|
35 |
# include <time.h>
|
|
36 |
# endif
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
37 |
#endif
|
481.1.15
by Monty Taylor
Removed time.h and sys/time.h from global.h. |
38 |
|
1929.1.40
by Monty Taylor
Replaced auto_ptr with scoped_ptr. |
39 |
#include <boost/scoped_ptr.hpp> |
481.1.15
by Monty Taylor
Removed time.h and sys/time.h from global.h. |
40 |
|
1
by brian
clean slate |
41 |
#define TEST_FILENAME "performance_test.az"
|
42 |
||
43 |
#define BUFFER_LEN 1024
|
|
44 |
||
45 |
char test_string[BUFFER_LEN]; |
|
46 |
||
80.1.1
by Brian Aker
LL() cleanup |
47 |
#define ROWS_TO_TEST 2000000LL
|
1
by brian
clean slate |
48 |
|
49 |
/* prototypes */
|
|
1165.1.53
by Stewart Smith
make timedif static for archive_performance |
50 |
static long int timedif(struct timeval a, struct timeval b); |
1165.1.52
by Stewart Smith
make generate_data static for archive_performance |
51 |
static int generate_data(uint64_t length); |
1165.1.54
by Stewart Smith
make read_test() static for archive_performance |
52 |
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for); |
1
by brian
clean slate |
53 |
|
54 |
int main(int argc, char *argv[]) |
|
55 |
{
|
|
56 |
unsigned int method; |
|
57 |
struct timeval start_time, end_time; |
|
58 |
long int timing; |
|
59 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
60 |
drizzled::internal::my_init(); |
1
by brian
clean slate |
61 |
MY_INIT(argv[0]); |
62 |
||
63 |
if (argc != 1) |
|
64 |
return 1; |
|
65 |
||
66 |
printf("Performing write() test\n"); |
|
67 |
generate_data(ROWS_TO_TEST); |
|
68 |
||
69 |
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++) |
|
70 |
{
|
|
71 |
unsigned int ret; |
|
1929.1.40
by Monty Taylor
Replaced auto_ptr with scoped_ptr. |
72 |
boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream); |
1929.1.20
by Stewart Smith
fix large stack usage in archive_performance. azio_stream as auto_ptr |
73 |
azio_stream &reader_handle= *reader_handle_ap.get(); |
1
by brian
clean slate |
74 |
|
75 |
if (method) |
|
1192.3.44
by Monty Taylor
Removed checks for things that are either defined ISO/POSIX standard, or that |
76 |
printf("Performing azio_read() test\n"); |
1
by brian
clean slate |
77 |
else
|
78 |
printf("Performing read() test\n"); |
|
79 |
||
492.1.14
by Monty Taylor
Removed O_BINARY and FILE_BINARY. |
80 |
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY, |
968.2.14
by Monty Taylor
Removed references to stdbool, since they aren't valid in c++. Added them in C where we need them. Made archive tests c++. |
81 |
(az_method)method))) |
1
by brian
clean slate |
82 |
{
|
83 |
printf("Could not open test file\n"); |
|
84 |
return 0; |
|
85 |
}
|
|
86 |
||
87 |
gettimeofday(&start_time, NULL); |
|
88 |
read_test(&reader_handle, 1044496L); |
|
89 |
gettimeofday(&end_time, NULL); |
|
90 |
timing= timedif(end_time, start_time); |
|
91 |
printf("Time took to read was %ld.%03ld seconds\n", timing / 1000, timing % 1000); |
|
92 |
||
93 |
azclose(&reader_handle); |
|
94 |
}
|
|
95 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
96 |
drizzled::internal::my_end(); |
1
by brian
clean slate |
97 |
|
98 |
return 0; |
|
99 |
}
|
|
100 |
||
1165.1.52
by Stewart Smith
make generate_data static for archive_performance |
101 |
static int generate_data(uint64_t rows_to_test) |
1
by brian
clean slate |
102 |
{
|
1929.1.40
by Monty Taylor
Replaced auto_ptr with scoped_ptr. |
103 |
boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream); |
1929.1.20
by Stewart Smith
fix large stack usage in archive_performance. azio_stream as auto_ptr |
104 |
azio_stream &writer_handle= *writer_handle_ap.get(); |
481.1.2
by Monty Taylor
Replaced all unsigned long long with uint64_t. |
105 |
uint64_t x; |
1
by brian
clean slate |
106 |
unsigned int ret; |
107 |
struct timeval start_time, end_time; |
|
108 |
long int timing; |
|
109 |
struct stat buf; |
|
110 |
||
111 |
if ((stat(TEST_FILENAME, &buf)) == 0) |
|
112 |
{
|
|
113 |
printf("Writer file already available\n"); |
|
114 |
return 0; |
|
115 |
}
|
|
116 |
||
492.1.14
by Monty Taylor
Removed O_BINARY and FILE_BINARY. |
117 |
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC, |
1
by brian
clean slate |
118 |
AZ_METHOD_BLOCK))) |
119 |
{
|
|
120 |
printf("Could not create test file\n"); |
|
121 |
exit(1); |
|
122 |
}
|
|
123 |
||
124 |
gettimeofday(&start_time, NULL); |
|
125 |
for (x= 0; x < rows_to_test; x++) |
|
126 |
{
|
|
127 |
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN); |
|
128 |
if (ret != BUFFER_LEN) |
|
129 |
{
|
|
130 |
printf("Size %u\n", ret); |
|
131 |
assert(ret != BUFFER_LEN); |
|
132 |
}
|
|
133 |
if ((x % 14031) == 0) |
|
134 |
{
|
|
135 |
azflush(&writer_handle, Z_SYNC_FLUSH); |
|
136 |
}
|
|
137 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
138 |
/*
|
139 |
We put the flush in just to be honest with write speed, normally azclose
|
|
1
by brian
clean slate |
140 |
would be fine.
|
141 |
*/
|
|
142 |
azflush(&writer_handle, Z_SYNC_FLUSH); |
|
143 |
gettimeofday(&end_time, NULL); |
|
144 |
timing= timedif(end_time, start_time); |
|
145 |
||
146 |
azclose(&writer_handle); |
|
147 |
||
148 |
printf("Time took to write was %ld.%03ld seconds\n", timing / 1000, timing % 1000); |
|
149 |
||
150 |
return 0; |
|
151 |
}
|
|
152 |
||
1165.1.54
by Stewart Smith
make read_test() static for archive_performance |
153 |
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for) |
1
by brian
clean slate |
154 |
{
|
481.1.2
by Monty Taylor
Replaced all unsigned long long with uint64_t. |
155 |
uint64_t read_length= 0; |
156 |
uint64_t count= 0; |
|
1
by brian
clean slate |
157 |
unsigned int ret; |
158 |
int error; |
|
159 |
||
160 |
azread_init(reader_handle); |
|
161 |
while ((ret= azread_row(reader_handle, &error))) |
|
162 |
{
|
|
163 |
if (error) |
|
164 |
{
|
|
481.1.2
by Monty Taylor
Replaced all unsigned long long with uint64_t. |
165 |
fprintf(stderr, "Got an error while reading at row %"PRIu64"\n", count); |
1
by brian
clean slate |
166 |
exit(1); |
167 |
}
|
|
168 |
||
169 |
read_length+= ret; |
|
170 |
assert(!memcmp(reader_handle->row_ptr, test_string, ret)); |
|
171 |
if (ret != BUFFER_LEN) |
|
172 |
{
|
|
173 |
printf("Size %u\n", ret); |
|
174 |
assert(ret != BUFFER_LEN); |
|
175 |
}
|
|
176 |
count++; |
|
177 |
}
|
|
178 |
assert(rows_to_test_for == rows_to_test_for); |
|
179 |
||
180 |
return 0; |
|
181 |
}
|
|
182 |
||
1165.1.53
by Stewart Smith
make timedif static for archive_performance |
183 |
static long int timedif(struct timeval a, struct timeval b) |
1
by brian
clean slate |
184 |
{
|
185 |
register int us, s; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
186 |
|
1
by brian
clean slate |
187 |
us = a.tv_usec - b.tv_usec; |
188 |
us /= 1000; |
|
189 |
s = a.tv_sec - b.tv_sec; |
|
190 |
s *= 1000; |
|
191 |
return s + us; |
|
192 |
}
|