-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscall_lseek.cpp
62 lines (51 loc) · 1.44 KB
/
syscall_lseek.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
60
61
62
#include <iostream>
#include <fstream>
#include <chrono>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
using namespace chrono;
double measureLseek_block_count(const char *fileName)
{
int fd = open(fileName, O_RDONLY);
if (fd == -1)
{
cerr << "Error opening file for reading." << endl;
return -1.0;
}
long long counter = 0;
auto start = high_resolution_clock::now();
while (true)
{
lseek(fd, 1, SEEK_SET);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
if (duration.count() == 10)
{
break;
}
counter += 1;
}
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<seconds>(stop - start);
close(fd);
return counter;
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
cerr << "Usage: ./syscall_lseek <filename>" << endl;
return 1;
}
const char *fileName = argv[1];
// long long block_size = stoi(argv[2]);
// long long block_count = stoll(argv[3]);
// As small block will take forever, we will find the performance for 10 seconds of read operation
double blocks = measureLseek_block_count(fileName);
// cout << "Lseek duration: " << durationLseek << " seconds" << endl;
double performance = (double)(blocks) * (1) / (10) / (1024 * 1024); // MiB/s
cout << "Lseek Performance: " << performance << " MiB/s" << endl;
cout << "Number of equivalent system calls: " << performance * (1024 * 1024) << " syscall/s" << endl;
return 0;
}