Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libcachesim/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def skip_n_req(self, n: int) -> int: ...
def reset(self) -> None: ...
def close(self) -> None: ...
def clone(self) -> "ReaderProtocol": ...
def get_working_set_size(self) -> tuple[int, int]: ...
def __iter__(self) -> Iterator[Request]: ...
def __next__(self) -> Request: ...
def __len__(self) -> int: ...
9 changes: 9 additions & 0 deletions libcachesim/synthetic_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ def set_read_pos(self, pos: float) -> None:
def get_read_pos(self) -> float:
"""Get current read position"""
return float(self.current_pos)

def get_working_set_size(self) -> tuple[int, int]:
Comment thread
haochengxia marked this conversation as resolved.
Outdated
"""Calculate working set size"""
wss_obj, wss_byte = 0, 0
if self._obj_ids is not None:
unique_ids = np.unique(self._obj_ids[:self.current_pos])
Comment thread
haochengxia marked this conversation as resolved.
Outdated
wss_obj = len(unique_ids)
wss_byte = wss_obj * self.obj_size
return wss_obj, wss_byte

def __iter__(self) -> Iterator[Request]:
"""Iterator implementation"""
Expand Down
7 changes: 5 additions & 2 deletions libcachesim/trace_reader.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Wrapper of Reader with S3 support."""

import logging
from typing import overload, Union, Optional
from typing import Tuple, overload, Union, Optional
Comment thread
haochengxia marked this conversation as resolved.
Outdated
from collections.abc import Iterator
from urllib.parse import urlparse

from .protocols import ReaderProtocol
from .libcachesim_python import TraceType, SamplerType, Request, ReaderInitParam, Reader, Sampler, ReadDirection
from .libcachesim_python import TraceType, SamplerType, Request, ReaderInitParam, Reader, Sampler, ReadDirection, cal_working_set_size
from ._s3_cache import get_data_loader

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -276,6 +276,9 @@ def go_back_one_req(self) -> None:
def set_read_pos(self, pos: float) -> None:
self._reader.set_read_pos(pos)

def get_working_set_size(self) -> Tuple[int, int]:
Comment thread
haochengxia marked this conversation as resolved.
Outdated
return cal_working_set_size(self._reader)

def __iter__(self) -> Iterator[Request]:
self._reader.reset()
return self
Expand Down
8 changes: 8 additions & 0 deletions src/export_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ struct SamplerDeleter {
}
};


void export_reader(py::module& m) {
/* Helper function(s) */
m.def("cal_working_set_size", [](reader_t& reader) {
int64_t wss_obj = 0, wss_byte = 0;
cal_working_set_size(&reader, &wss_obj, &wss_byte);
return std::make_tuple(wss_obj, wss_byte);
}, "reader"_a);

// Sampler type enumeration
py::enum_<sampler_type>(m, "SamplerType")
.value("SPATIAL_SAMPLER", sampler_type::SPATIAL_SAMPLER)
Expand Down
Loading