From a3a5ca891e909fdabee651e787f2e36c7e21f3d8 Mon Sep 17 00:00:00 2001 From: juncheng Date: Fri, 13 Dec 2024 23:03:36 -0500 Subject: [PATCH] [not relevant to libCacheSim] add debug related binary --- libCacheSim/bin/debug/CMakeLists.txt | 3 ++ libCacheSim/bin/debug/aligned.c | 2 +- libCacheSim/bin/debug/fileOp.cpp | 63 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 libCacheSim/bin/debug/fileOp.cpp diff --git a/libCacheSim/bin/debug/CMakeLists.txt b/libCacheSim/bin/debug/CMakeLists.txt index 36879c80..59a31ab2 100644 --- a/libCacheSim/bin/debug/CMakeLists.txt +++ b/libCacheSim/bin/debug/CMakeLists.txt @@ -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) diff --git a/libCacheSim/bin/debug/aligned.c b/libCacheSim/bin/debug/aligned.c index 931153c4..a169971b 100644 --- a/libCacheSim/bin/debug/aligned.c +++ b/libCacheSim/bin/debug/aligned.c @@ -10,7 +10,7 @@ #include #include "../../include/libCacheSim/reader.h" -#include "../../traceReader/generalReader/lcs.h" +#include "../../traceReader/customizedReader/lcs.h" #define N_OP 200000000llu diff --git a/libCacheSim/bin/debug/fileOp.cpp b/libCacheSim/bin/debug/fileOp.cpp new file mode 100644 index 00000000..d2a53574 --- /dev/null +++ b/libCacheSim/bin/debug/fileOp.cpp @@ -0,0 +1,63 @@ + +#include +#include +#include +#include +#include + +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(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(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; +}