-
Notifications
You must be signed in to change notification settings - Fork 0
/
lttng-read-buffer.cpp
38 lines (35 loc) · 1.24 KB
/
lttng-read-buffer.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
/*
* Copyright (c) 2019 Erez Zadok
* Copyright (c) 2019-2020 Ibrahim Umit Akgun
* Copyright (c) 2020 Lukas Velikov */
// Copyright FSL Lab Stony Brook University
#include <fstream>
#include <iostream>
int main() {
std::ifstream file("/tmp/buffer-capture.dat",
std::ios::in | std::ios::binary);
uint64_t offset = 0, record_id = 0, sizeOfBuffer = 0, numberOfRecords = 0;
if (file.is_open()) {
auto begin_pos = file.tellg();
file.seekg(0, std::ios::end);
auto end_pos = file.tellg();
file.seekg(0, std::ios::beg);
while (offset < (end_pos - begin_pos)) {
file.read((char*)&record_id, sizeof(record_id));
file.read((char*)&sizeOfBuffer, sizeof(sizeOfBuffer));
std::cout << std::dec << "record id " << record_id << " size "
<< sizeOfBuffer << " offset " << offset << "\n";
auto buffer = new char[sizeOfBuffer];
file.read(buffer, sizeof(buffer));
delete[] buffer;
offset += (sizeof(record_id) + sizeof(offset) + sizeOfBuffer);
file.seekg(offset, std::ios::beg);
numberOfRecords++;
}
file.close();
} else {
std::cout << "Unable to open file\n";
}
std::cout << std::dec << "Number of records: " << numberOfRecords << "\n";
return 0;
}