3
#include <valgrind/callgrind.h>
6
#include "kis_tile_data_store.h"
7
#include "kis_tile_data.h"
8
#include "kis_tiled_data_manager.h"
11
quint8 pixel[PIXEL_SIZE];
14
#define NUM_CYCLES_SMALL 2
17
void testPlanarRW(KisTiledDataManager &dm);
18
void testRW(KisTiledDataManager &dm);
23
#include <sys/times.h>
25
#define prop(fst, snd) ((fst-snd)/snd*100.)
27
#define startMeasure(msg, tv, tms) \
29
printf("%s:\t", msg); \
30
gettimeofday(&tv, NULL); \
34
#define endMeasure(tv, tms, rtime, utime, cutime) \
36
struct timeval new_tv; \
38
gettimeofday(&new_tv, NULL); \
40
double rsec = double(new_tv.tv_sec - tv.tv_sec) + \
41
double(new_tv.tv_usec - tv.tv_usec)/1000000; \
42
double usec = (double)(new_tms.tms_utime - tms.tms_utime) \
43
/ sysconf(_SC_CLK_TCK); \
44
double cusec = (double)(new_tms.tms_cutime - tms.tms_cutime) \
45
/ sysconf(_SC_CLK_TCK); \
49
printf("\treal: %5.3f\tuser: %5.3f\tcuser: %5.3f\n", \
52
#define meanValues(num, rstime, ustime, custime) \
58
printf("Mean value:\t\t\treal: %5.3f\tuser: %5.3f" \
60
double(rstime), double(ustime), double(custime)); \
63
#define zeroValues(rstime, ustime, custime) (rstime=ustime=custime=0)
67
memset(pixel, 8, PIXEL_SIZE);
68
KisTiledDataManager dm(PIXEL_SIZE, pixel);
76
void testRW(KisTiledDataManager &dm)
85
dataRect.setCoords(60, 60, 7110, 7110);
87
const qint32 dataSize = dataRect.width() * dataRect.height() * PIXEL_SIZE;
89
quint8 *data = new quint8[dataSize];
90
for (qint32 i = 0; i < dataRect.height(); i++) {
91
memset(data, i % 256, dataRect.width()*PIXEL_SIZE);
97
/*BLOCK1**************************************************/
98
printf("-----------------------------------\n");
99
printf("One loop to warm up COW\n");
100
for (int i = 0; i < NUM_CYCLES_SMALL; i++) {
101
printf("\tcycle %d", i);
102
startMeasure("", tv, tms);
104
dm.writeBytes(data, dataRect.left(), dataRect.top(),
105
dataRect.width(), dataRect.height());
107
endMeasure(tv, tms, rstime, ustime, custime);
109
meanValues(NUM_CYCLES_SMALL, rstime, ustime, custime);
112
/*BLOCK2**************************************************/
113
/* printf("-----------------------------------\n");
114
printf("Test writing with heavy COW'ing\n");
115
zeroValues(rstime, ustime, custime);
116
for(int i=0; i<NUM_CYCLES_SMALL; i++) {
117
printf("\tcycle %d", i);
118
startMeasure("", tv, tms);
121
KisTiledDataManager dm1(PIXEL_SIZE, pixel);
122
dm1.writeBytes(data, dataRect.left(), dataRect.top(),
123
dataRect.width(), dataRect.height());
126
endMeasure(tv,tms, rstime, ustime, custime);
128
meanValues(NUM_CYCLES_SMALL, rstime, ustime, custime);
131
/*BLOCK3**************************************************/
132
printf("-----------------------------------\n");
133
printf("Now COW is done. Test actual writing\n");
134
printf("KisTileProcessor subsystem (threading is OFF)\n");
135
zeroValues(rstime, ustime, custime);
136
for (int i = 0; i < NUM_CYCLES; i++) {
137
printf("\tcycle %d", i);
138
startMeasure("", tv, tms);
140
dm.writeBytes(data, dataRect.left(), dataRect.top(),
141
dataRect.width(), dataRect.height());
143
endMeasure(tv, tms, rstime, ustime, custime);
145
meanValues(NUM_CYCLES, rstime, ustime, custime);
147
quint8 *read_data = new quint8[dataSize];
148
memset(read_data, 255, dataSize);
150
/*BLOCK4**************************************************/
151
printf("-----------------------------------\n");
152
printf("Read and consistency test\n");
153
zeroValues(rstime, ustime, custime);
154
for (int i = 0; i < NUM_CYCLES; i++) {
155
printf("\tcycle %d", i);
156
startMeasure("", tv, tms);
158
dm.readBytes(read_data, dataRect.left(), dataRect.top(),
159
dataRect.width(), dataRect.height());
161
endMeasure(tv, tms, rstime, ustime, custime);
163
meanValues(NUM_CYCLES, rstime, ustime, custime);
165
printf("Consistency: ");
166
int err = memcmp(data, read_data, dataSize);
171
printf("data and read_data are not the same! (%d)\n", err);
178
void testPlanarRW(KisTiledDataManager &dm)
188
dataRect.setCoords(60, 60, 7110, 7110);
189
const qint32 numPixels = dataRect.width() * dataRect.height();
191
QVector<quint8*> planes;
192
QVector<quint8*> read_planes;
193
QVector<qint32> channelSizes;
195
for (qint32 i = 0; i < 3; i++) {
196
channelSizes.append(i);
197
quint8 *data = new quint8[i*numPixels];
198
memset(data, i + 10, i*numPixels);
202
printf("Strarting test planar write\n");
203
zeroValues(rstime, ustime, custime);
204
for (int i = 0; i < NUM_CYCLES; i++) {
205
printf("\tcycle %d", i);
206
startMeasure("", tv, tms);
208
dm.writePlanarBytes(planes, channelSizes,
209
dataRect.left(), dataRect.top(),
210
dataRect.width(), dataRect.height());
212
endMeasure(tv, tms, rstime, ustime, custime);
214
meanValues(NUM_CYCLES, rstime, ustime, custime);
218
printf("---\nStrarting test planar read\n");
219
zeroValues(rstime, ustime, custime);
220
for (int i = 0; i < NUM_CYCLES; i++) {
221
printf("\tcycle %d", i);
222
startMeasure("", tv, tms);
224
read_planes = dm.readPlanarBytes(channelSizes,
225
dataRect.left(), dataRect.top(),
226
dataRect.width(), dataRect.height());
228
endMeasure(tv, tms, rstime, ustime, custime);
230
meanValues(NUM_CYCLES, rstime, ustime, custime);
234
for (qint32 i = 0; i < 3; i++) {
235
err = memcmp(planes[i], read_planes[i], i * numPixels);
239
delete[] read_planes[i];
243
printf("Planar consistency: ");
248
printf("planar and read_planar are not the same! (%d)\n", errSum);