Skip to content

Commit

Permalink
[not relevant to libCacheSim] add debug related binary
Browse files Browse the repository at this point in the history
  • Loading branch information
1a1a11a committed Dec 14, 2024
1 parent c561fa7 commit a3a5ca8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libCacheSim/bin/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ target_link_libraries(debug ${ALL_MODULES} ${LIBS} ${CMAKE_THREAD_LIBS_INIT} uti

add_executable(debug_aligned aligned.c)
target_link_libraries(debug_aligned ${ALL_MODULES} ${LIBS} ${CMAKE_THREAD_LIBS_INIT} utils)

add_executable(debug_fileOp fileOp.cpp)
target_link_libraries(debug_fileOp ${ALL_MODULES} ${LIBS} ${CMAKE_THREAD_LIBS_INIT} utils)
2 changes: 1 addition & 1 deletion libCacheSim/bin/debug/aligned.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <unistd.h>

#include "../../include/libCacheSim/reader.h"
#include "../../traceReader/generalReader/lcs.h"
#include "../../traceReader/customizedReader/lcs.h"

#define N_OP 200000000llu

Expand Down
63 changes: 63 additions & 0 deletions libCacheSim/bin/debug/fileOp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>

typedef struct __attribute__((packed)) req1 {
int64_t clock_time;
uint64_t obj_id;
int64_t obj_size;
uint32_t op : 8;
uint32_t tenant : 24;
int64_t next_access_vtime;
} req1_t;

typedef struct __attribute__((packed)) req2 {
int64_t clock_time;
uint64_t obj_id;
int64_t obj_size;
int8_t op;
uint16_t tenant;
int64_t next_access_vtime;
} req2_t;

typedef req2_t req_t;

void write_req(const char *file_path, req_t *req) {
std::ofstream file(file_path, std::ios::out | std::ios::binary | std::ios::trunc);
file.write(reinterpret_cast<char *>(req), sizeof(req_t));
}

void read_req(const char *file_path, req_t *req) {
std::ifstream file(file_path, std::ios::in | std::ios::binary);
file.read(reinterpret_cast<char *>(req), sizeof(req_t));
}

void print_req(req_t *req) {
std::cout << "clock_time: " << req->clock_time << std::endl;
std::cout << "obj_id: " << req->obj_id << std::endl;
std::cout << "obj_size: " << req->obj_size << std::endl;
std::cout << "op: " << (int)(req->op) << std::endl;
std::cout << "tenant: " << req->tenant << std::endl;
std::cout << "next_access_vtime: " << req->next_access_vtime << std::endl;
}

int main() {
req_t req, req2;
req.clock_time = 123456789;
req.obj_id = 987654321;
req.obj_size = 123456789;
req.op = 1;
req.tenant = 2;
req.next_access_vtime = 987654321;

print_req(&req);
write_req("req.bin", &req);

read_req("req.bin", &req2);
print_req(&req2);

return 0;
}

0 comments on commit a3a5ca8

Please sign in to comment.