-
Notifications
You must be signed in to change notification settings - Fork 48
/
write_files.cpp
59 lines (47 loc) · 1.58 KB
/
write_files.cpp
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
#include <performance_log/performance_log.hpp>
#include <sstream>
#include <iostream>
#include <fstream>
#include <cassert>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include LOG_INCLUDE
int main()
{
unsigned const LOG_ENTRIES = 2048;
unsigned long const DATA_SIZE = 64*1024*1024*1024L;
unlink("log.txt");
auto const full_access =
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH;
mkdir("data", full_access);
char data[1024*1024];
std::memset(data, 0xcd, sizeof(data));
performance_log::logger<2*2048, performance_log::rdtscp_cpuid_clock> performance_log;
{
LOG_INIT(128);
performance_log::rdtscp_cpuid_clock::bind_cpu(0);
for(unsigned number=0; number!=LOG_ENTRIES; ++number) {
std::ostringstream ostr;
ostr << "data/" << number;
int fd = open(ostr.str().c_str(), O_WRONLY | O_CREAT, full_access);
assert(fd != -1);
auto start = performance_log.start();
LOG_FILE_WRITE(number, 100.0*number/256.0);
performance_log.stop(start);
for(std::size_t i=0; i!=DATA_SIZE/LOG_ENTRIES/sizeof(data); ++i) {
auto res = write(fd, data, sizeof(data));
assert(res == sizeof(data));
}
close(fd);
}
performance_log::rdtscp_cpuid_clock::unbind_cpu();
LOG_CLEANUP();
}
for(auto sample : performance_log) {
std::cout << sample.start << ' ' << sample.stop << std::endl;
}
return 0;
}