Skip to content

Commit 13a180a

Browse files
committed
[Doc] Add reader docs
1 parent 39edefb commit 13a180a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

docs/mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ nav:
1212
- Getting Started:
1313
- getting_started/quickstart.md
1414
- getting_started/installation.md
15-
- Examples:
15+
- Examples:
16+
- examples/reader.md
1617
- examples/simulation.md
1718
- examples/analysis.md
1819
- examples/plugins.md

docs/src/en/examples/reader.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Trace Reader
2+
3+
We support a unified trace reader to open trace files in different format and read the requests.
4+
5+
## Basic usage
6+
7+
`TraceReader` class is the core of this functionality. When we create an instance of `TraceReader`, we open a trace file for read requests.
8+
9+
`TraceReader` accepts three arguments:
10+
- `trace: str | TraceReader`: A trace path or other trace instance. The trace path can be a file path on your local machine (e.g., ~/data/trace.oracleGeneral.zst) or an S3 URI (e.g., s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst).
11+
- `trace_type: TraceType` (optional): If not given, it will be infered according to the file name.
12+
- `reader_init_params: ReaderInitParam` (optional): If not given, will use default params for reader initialization.
13+
14+
Here is an example to load one trace via an S3 URI.
15+
16+
```python
17+
import libcachesim as lcs
18+
19+
# Open a trace hosted on S3 (find more via https://github.com/cacheMon/cache_dataset)
20+
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
21+
reader = lcs.TraceReader(
22+
trace = URI,
23+
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
24+
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
25+
)
26+
```
27+
28+
Then we can walk through the trace.
29+
30+
```python
31+
for req in reader:
32+
print(req.obj_id, req.obj_size)
33+
```
34+
35+
## Reader slicing
36+
37+
`TraceReader` support slicing and index access.
38+
39+
```python
40+
# Read the first 100 reqs
41+
for req in reader[:100]:
42+
print(req.obj_id, req.obj_size)
43+
```
44+
45+
```python
46+
# Read 100 reqs after the first 100 reqs
47+
for req in reader[100:200]:
48+
print(req.obj_id, req.obj_size)
49+
```
50+
51+
```python
52+
# Read last 100 reqs
53+
for req in reader[-100:]:
54+
print(req.obj_id, req.obj_size)
55+
```

0 commit comments

Comments
 (0)