Skip to content

Commit 36961e5

Browse files
committed
feat: get the number of obj and req
1 parent ec21522 commit 36961e5

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

libCacheSim/include/python/api.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ LIBCACHESIM_C_EXPORT int LCS_ReaderFree(const ReaderHandle reader);
5959
*/
6060
LIBCACHESIM_C_EXPORT int LCS_ReaderGetNextRequest(const ReaderHandle reader, RequestHandle* out);
6161

62+
/*!
63+
* \brief Get the number of requests in the reader.
64+
* \param reader The reader
65+
* \param[out] out The number of requests
66+
* \return 0 when succeed, -1 when failure happens
67+
*/
68+
LIBCACHESIM_C_EXPORT int LCS_ReaderGetReqNum(const ReaderHandle reader, int64_t* out);
69+
70+
/*!
71+
* \brief Get the number of objects in the reader.
72+
* \param reader The reader
73+
* \param[out] out The number of objects
74+
* \return 0 when succeed, -1 when failure happens
75+
*/
76+
LIBCACHESIM_C_EXPORT int LCS_ReaderGetObjNum(const ReaderHandle reader, int64_t* out);
77+
6278
/*!
6379
* \brief Free a request.
6480
* \param request The request

libCacheSim/python/api.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ char* _extract_trace_type_str(const char* trace_path) {
8686
}
8787
}
8888

89-
int LCS_ReaderCreateFromFile(const char* filename, const char* parameters,
90-
ReaderHandle* out) {
89+
int LCS_ReaderCreateFromFile(const char* filename, const char* parameters, ReaderHandle* out) {
9190
API_BEGIN();
9291
// TODO(haocheng): add more parameters
9392
// initialize reader by filename
9493
trace_type_e trace_type = trace_type_str_to_enum(_extract_trace_type_str(filename), filename);
9594
reader_t* reader = setup_reader(filename, trace_type, NULL);
9695
if (reader == NULL) {
97-
printf("Failed to create reader\n");
96+
printf("Failed to create reader\n");
9897
}
9998
*out = (ReaderHandle)reader;
100-
API_END();
99+
API_END();
101100
}
102101

103102
int LCS_ReaderFree(const ReaderHandle reader) {
@@ -121,6 +120,20 @@ int LCS_ReaderGetNextRequest(const ReaderHandle reader, RequestHandle* out) {
121120
API_END();
122121
}
123122

123+
int LCS_ReaderGetObjNum(const ReaderHandle reader, int64_t* out) {
124+
API_BEGIN();
125+
int64_t wss_obj = 0, wss_byte = 0;
126+
cal_working_set_size(static_cast<reader_t*>(reader), &wss_obj, &wss_byte);
127+
*out = wss_obj;
128+
API_END();
129+
}
130+
131+
int LCS_ReaderGetReqNum(const ReaderHandle reader, int64_t* out) {
132+
API_BEGIN();
133+
*out = (int64_t)(static_cast<reader_t*>(reader)->n_total_req);
134+
API_END();
135+
}
136+
124137
int LCS_CacheCreate(const ReaderHandle reader, const char* eviction_algo, float cache_size, bool ignore_obj_size,
125138
const char* eviction_parameters, CacheHandle* out) {
126139
API_BEGIN();

python-package/example_cache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from libcachesim import simulate, FIFO, Reader
22

3-
reader = Reader(b"/proj/cache-PG0/haocheng/libCacheSim/data/cloudPhysicsIO.vscsi")
3+
reader = Reader(b"../data/cloudPhysicsIO.vscsi")
4+
print("req num: ", reader.get_req_num())
5+
print("obj num: ", reader.get_obj_num())
6+
47
cache = FIFO(reader, cache_size=0.1, ignore_obj_size=False)
58

69
hit_cnt = 0

python-package/example_sim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from libcachesim import simulate
22

3-
req, miss = simulate(b"/proj/cache-PG0/haocheng/libCacheSim/data/cloudPhysicsIO.vscsi", b"vscsi", b"fifo", 0.1)
3+
req, miss = simulate(b"../data/cloudPhysicsIO.vscsi", b"vscsi", b"fifo", 0.1)
44
print(req, miss)
55
print(miss / req)

python-package/libcachesim/basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def read(self) -> "Request":
9696
raise StopIteration
9797
return Request(req_handle)
9898

99+
def get_req_num(self) -> int:
100+
req_num = ctypes.c_int64(0)
101+
_safe_call(_LIB.LCS_ReaderGetReqNum(self._handle, ctypes.byref(req_num)))
102+
return req_num.value
103+
104+
def get_obj_num(self) -> int:
105+
obj_num = ctypes.c_int64(0)
106+
_safe_call(_LIB.LCS_ReaderGetObjNum(self._handle, ctypes.byref(obj_num)))
107+
return obj_num.value
108+
99109
def __iter__(self):
100110
while True:
101111
try:

0 commit comments

Comments
 (0)