Skip to content

Commit 15e8979

Browse files
committed
Combine translator
1 parent aa7e27a commit 15e8979

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

docs/src/en/getting_started/quickstart.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Here is an example demonstrating how to use `TraceAnalyzer`.
109109
# Step 1: Get one trace from S3 bucket
110110
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
111111
reader = lcs.TraceReader(
112-
trace = dl.get_cache_path(URI),
112+
trace = URI,
113113
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
114114
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
115115
)
@@ -140,10 +140,10 @@ Here is an example demonstrating how to use `TraceAnalyzer`.
140140
The above code demonstrates how to perform trace analysis using `libcachesim`. The workflow is as follows:
141141

142142
1. Open the trace file with `TraceReader`, specifying the trace type and any reader initialization parameters. The URI starting with `s3://`, will download a trace file from an S3 bucket.
143-
3. Configure the analysis options with `AnalysisOption` to enable or disable specific analyses (such as request rate, size, etc.).
144-
4. Optionally, set additional analysis parameters with `AnalysisParam`.
145-
5. Create a `TraceAnalyzer` object with the reader, output directory, and the chosen options and parameters.
146-
6. Run the analysis with `analyzer.run()`.
143+
2. Configure the analysis options with `AnalysisOption` to enable or disable specific analyses (such as request rate, size, etc.).
144+
3. Optionally, set additional analysis parameters with `AnalysisParam`.
145+
4. Create a `TraceAnalyzer` object with the reader, output directory, and the chosen options and parameters.
146+
5. Run the analysis with `analyzer.run()`.
147147

148148
After running, you can access the analysis results, such as summary statistics (`stat`) or detailed results (e.g., `example_analysis.size`).
149149

src/exception.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,41 @@ void register_exception(py::module& m) {
1717
static py::exception<CacheException> exc_cache(m, "CacheException");
1818
static py::exception<ReaderException> exc_reader(m, "ReaderException");
1919

20+
// Single exception translator with catch blocks ordered from most-specific to least-specific
2021
py::register_exception_translator([](std::exception_ptr p) {
2122
try {
2223
if (p) std::rethrow_exception(p);
2324
} catch (const CacheException& e) {
25+
// Custom exception: CacheException
2426
py::set_error(exc_cache, e.what());
2527
} catch (const ReaderException& e) {
28+
// Custom exception: ReaderException
2629
py::set_error(exc_reader, e.what());
27-
}
28-
});
29-
30-
py::register_exception_translator([](std::exception_ptr p) {
31-
try {
32-
if (p) std::rethrow_exception(p);
3330
} catch (const std::bad_alloc& e) {
31+
// Memory allocation error
3432
PyErr_SetString(PyExc_MemoryError, e.what());
3533
} catch (const std::invalid_argument& e) {
34+
// Invalid argument error
3635
PyErr_SetString(PyExc_ValueError, e.what());
3736
} catch (const std::out_of_range& e) {
37+
// Out of range error
3838
PyErr_SetString(PyExc_IndexError, e.what());
3939
} catch (const std::domain_error& e) {
40+
// Domain error
4041
PyErr_SetString(PyExc_ValueError,
4142
("Domain error: " + std::string(e.what())).c_str());
4243
} catch (const std::overflow_error& e) {
44+
// Overflow error
4345
PyErr_SetString(PyExc_OverflowError, e.what());
4446
} catch (const std::range_error& e) {
47+
// Range error
4548
PyErr_SetString(PyExc_ValueError,
4649
("Range error: " + std::string(e.what())).c_str());
4750
} catch (const std::runtime_error& e) {
51+
// Generic runtime error
4852
PyErr_SetString(PyExc_RuntimeError, e.what());
4953
} catch (const std::exception& e) {
54+
// Catch-all for any other std::exception
5055
PyErr_SetString(PyExc_RuntimeError,
5156
("C++ exception: " + std::string(e.what())).c_str());
5257
}

0 commit comments

Comments
 (0)