-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtestDump.c
111 lines (88 loc) · 3.13 KB
/
testDump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Pedro Gonnet ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
/* Config parameters. */
#include <config.h>
#ifdef HAVE_POSIX_FALLOCATE /* Are we on a sensible platform? */
#ifdef WITH_CSDS
/* Some standard headers. */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* Local headers. */
#include "swift.h"
void logfile_mapper(void *map_data, int num_elements, void *extra_data) {
struct csds_logfile_writer *d = (struct csds_logfile_writer *)extra_data;
size_t offset;
char *out_string = (char *)csds_logfile_writer_get(d, 7, &offset);
char out_buff[8];
/* modulo due to bug in gcc, should be removed */
snprintf(out_buff, 8, "%06zi\n", (offset / 7) % 1000000);
memcpy(out_string, out_buff, 7);
}
int main(int argc, char *argv[]) {
/* Some constants. */
const int num_threads = 4;
const int num_runs = 20;
const int chunk_size = 1000;
/* Some constants. */
char filename[256];
const int now = time(NULL);
sprintf(filename, "/tmp/SWIFT_dump_test_%d.out", now);
/* Prepare a threadpool to write to the dump. */
struct threadpool t;
threadpool_init(&t, num_threads);
/* Prepare a dump. */
struct csds_logfile_writer d;
csds_logfile_writer_init(&d, filename, 1024);
/* Print the page size for reference. */
printf("Will dump %i bytes, page size is %zi bytes.\n",
num_runs * chunk_size * 7, sysconf(_SC_PAGE_SIZE));
/* Dump numbers in chunks. */
for (int run = 0; run < num_runs; run++) {
/* Ensure capacity. */
csds_logfile_writer_ensure(&d, 7 * chunk_size, 7 * chunk_size);
/* Dump a few numbers. */
printf("dumping %i chunks...\n", chunk_size);
fflush(stdout);
threadpool_map(&t, logfile_mapper, NULL, chunk_size, 0, 1, &d);
}
/* Sync the file, not necessary before dump_close, but just to test this. */
csds_logfile_writer_sync(&d);
/* Finalize the dump. */
csds_logfile_writer_close(&d);
/* Clean the threads */
threadpool_clean(&t);
/* Be clean */
remove(filename);
/* Return a happy number. */
return 0;
}
#else
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("No posix_fallocate, not testing anything.\n");
return 0;
}
#endif /* WITH_CSDS */
#endif /* HAVE_POSIX_FALLOCATE */