Skip to content

Commit 85be495

Browse files
committed
Add CI and test
1 parent cf3c7bf commit 85be495

File tree

13 files changed

+540
-165
lines changed

13 files changed

+540
-165
lines changed

.github/workflows/build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and Test libCacheSim-python
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.10"
18+
19+
- name: Init submodules
20+
run: git submodule update --init --recursive
21+
22+
- name: Prepare
23+
run: bash src/libCacheSim/scripts/install_dependency.sh
24+
25+
- name: Build main libCacheSim project
26+
run: |
27+
pushd src/libCacheSim
28+
cmake -G Ninja -B build
29+
ninja -C build
30+
popd
31+
32+
- name: Build libCacheSim-python
33+
run: |
34+
pip install -e .[dev]
35+
36+
- name: Run tests
37+
run: |
38+
python -m pytest tests/

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "libCacheSim"]
2-
path = libCacheSim
3-
url = [email protected]:1a1a11a/libCacheSim.git
41
[submodule "src/libCacheSim"]
52
path = src/libCacheSim
63
url = [email protected]:1a1a11a/libCacheSim.git

README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# libCacheSim Python Binding
22

3-
[![Python Release](https://github.com/1a1a11a/libCacheSim/actions/workflows/pypi-release.yml/badge.svg)](https://github.com/1a1a11a/libCacheSim/actions/workflows/pypi-release.yml)
3+
[![Build](https://github.com/cacheMon/libCacheSim-python/actions/workflows/build.yml/badge.svg)](https://github.com/cacheMon/libCacheSim-python/actions/workflows/build.yml)
44
[![Python Versions](https://img.shields.io/pypi/pyversions/libcachesim.svg?logo=python&logoColor=white)](https://pypi.org/project/libcachesim)
55
[![PyPI Version](https://img.shields.io/pypi/v/libcachesim.svg?)](https://pypi.org/project/libcachesim)
66
[![PyPI - Downloads](https://img.shields.io/pypi/dd/libcachesim)](https://pypistats.org/packages/libcachesim)
77

8-
Python bindings for libCacheSim, a high-performance cache simulator and analysis library.
8+
Python bindings for [libCacheSim](https://github.com/1a1a11a/libCacheSim), a high-performance cache simulator and analysis library.
99

1010
## Installation
1111

@@ -20,25 +20,13 @@ pip install libcachesim
2020
If there are no wheels suitable for your environment, consider building from source.
2121

2222
```bash
23-
git clone https://github.com/1a1a11a/libCacheSim.git
24-
cd libCacheSim
25-
26-
# Build the main libCacheSim library first
27-
cmake -G Ninja -B build
28-
ninja -C build
29-
30-
# Install Python binding
31-
cd libCacheSim-python
32-
pip install -e .
23+
bash scripts/install.sh
3324
```
3425

35-
### Testing
36-
```bash
37-
# Run all tests
38-
python -m pytest .
26+
Run all tests to ensure the package works.
3927

40-
# Test import
41-
python -c "import libcachesim; print('Success!')"
28+
```bash
29+
python -m pytest tests/
4230
```
4331

4432
## Quick Start

benchmark/simulation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
""" Benchmark the simulation performance of the library.
2+
3+
This module contains benchmarks for various components of the library,
4+
including request processing times, memory usage, and overall throughput.
5+
"""

export/CMakeLists.txt

Lines changed: 0 additions & 38 deletions
This file was deleted.

export/README.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

libcachesim/trace_reader.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Wrapper of Reader"""
22

33
import logging
4-
from typing import overload, Union
4+
from typing import overload, Union, Optional
55
from collections.abc import Iterator
66

77
from .protocols import ReaderProtocol
@@ -22,53 +22,19 @@ def __init__(
2222
self,
2323
trace: Union[Reader, str],
2424
trace_type: TraceType = TraceType.UNKNOWN_TRACE,
25-
ignore_obj_size: bool = False,
26-
ignore_size_zero_req: bool = False,
27-
obj_id_is_num: bool = False,
28-
obj_id_is_num_set: bool = False,
29-
cap_at_n_req: int = -1,
30-
block_size: int = 0,
31-
has_header: bool = False,
32-
has_header_set: bool = False,
33-
delimiter: str = ",",
34-
trace_start_offset: int = 0,
35-
binary_fmt_str: str = "",
36-
sampling_ratio: float = 1.0,
37-
sampling_type: SamplerType = SamplerType.INVALID_SAMPLER,
25+
reader_init_params: Optional[ReaderInitParam] = None,
3826
):
27+
3928
if isinstance(trace, Reader):
4029
self._reader = trace
4130
return
4231

43-
# Process sampling_type
44-
if sampling_ratio < 0.0 or sampling_ratio > 1.0:
45-
raise ValueError("Sampling ratio must be between 0.0 and 1.0")
46-
47-
if sampling_ratio == 1.0:
48-
sampler = None
49-
else:
50-
if sampling_type == SamplerType.INVALID_SAMPLER:
51-
logging.warning("Sampling type is invalid, using SPATIAL_SAMPLER instead")
52-
sampling_type = SamplerType.SPATIAL_SAMPLER
53-
logging.info(f"Sampling ratio: {sampling_ratio}, Sampling type: {sampling_type}")
54-
sampler = Sampler(sampling_ratio, sampling_type)
55-
56-
# Construct ReaderInitParam
57-
reader_init_params = ReaderInitParam(
58-
binary_fmt_str=binary_fmt_str,
59-
ignore_obj_size=ignore_obj_size,
60-
ignore_size_zero_req=ignore_size_zero_req,
61-
obj_id_is_num=obj_id_is_num,
62-
obj_id_is_num_set=obj_id_is_num_set,
63-
cap_at_n_req=cap_at_n_req,
64-
block_size=block_size,
65-
has_header=has_header,
66-
has_header_set=has_header_set,
67-
delimiter=delimiter,
68-
trace_start_offset=trace_start_offset,
69-
sampler=sampler,
70-
)
32+
if reader_init_params is None:
33+
reader_init_params = ReaderInitParam()
7134

35+
if not isinstance(reader_init_params, ReaderInitParam):
36+
raise TypeError("reader_init_params must be an instance of ReaderInitParam")
37+
7238
self._reader = Reader(trace, trace_type, reader_init_params)
7339

7440
@property

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
]
2222
dependencies = [
2323
"numpy>=1.20.0",
24+
"boto3", # For S3
2425
]
2526

2627
[project.optional-dependencies]

requirements.txt

Whitespace-only changes.

tests/test_analyzer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ def test_analyzer_common():
1010

1111
reader = TraceReader(file_path)
1212

13-
analyzer = TraceAnalyzer(reader, output_path="./")
13+
analyzer = TraceAnalyzer(reader, "TestAnalyzerResults")
1414

1515
analyzer.run()
16+
17+
# Clean file after test, match all files with the prefix "TestAnalyzerResults"
18+
for file in os.listdir("."):
19+
if file.startswith("TestAnalyzerResults"):
20+
os.remove(file)
21+
# Remove file named "stat"
22+
stat_file = "stat"
23+
if os.path.exists(stat_file):
24+
os.remove(stat_file)

0 commit comments

Comments
 (0)