Skip to content

Commit 931fabe

Browse files
committed
new log parsing logic
1 parent c689310 commit 931fabe

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.16.0 (2025-04-30)
2+
3+
* new Range request parsing logic to make sure it works with S3 and HTTPS files
4+
15
## 0.15.0 (2025-02-27)
26

37
* add support for `VSIFile` backend (https://github.com/developmentseed/tilebench/pull/27)

tests/test_tilebench.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Test profiler with S3 and HTTPS files."""
2+
3+
import pytest
4+
from rio_tiler.io import Reader
5+
6+
from tilebench import profile as profiler
7+
8+
9+
@pytest.mark.parametrize(
10+
"src_path,head,get",
11+
[
12+
(
13+
"s3://sentinel-cogs/sentinel-s2-l2a-cogs/15/T/VK/2023/10/S2B_15TVK_20231008_0_L2A/TCI.tif",
14+
0,
15+
3,
16+
),
17+
(
18+
"https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/15/T/VK/2023/10/S2B_15TVK_20231008_0_L2A/TCI.tif",
19+
1,
20+
3,
21+
),
22+
],
23+
)
24+
def test_profiler(src_path, head, get):
25+
"""Test profiler."""
26+
config = {
27+
"AWS_DEFAULT_REGION": "us-west-2",
28+
"GDAL_DISABLE_READDIR_ON_OPEN": "EMPTY_DIR",
29+
}
30+
31+
@profiler(
32+
quiet=True,
33+
add_to_return=True,
34+
config=config,
35+
)
36+
def _read_tile(src_path: str, x: int, y: int, z: int, tilesize: int = 256):
37+
with Reader(src_path) as cog:
38+
return cog.tile(x, y, z, tilesize=tilesize)
39+
40+
(_, _), stats = _read_tile(src_path, 121, 185, 9)
41+
assert stats["HEAD"]["count"] == head
42+
assert stats["GET"]["count"] == get
43+
assert stats["GET"]["bytes"] == 386677

tilebench/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ def parse_rasterio_io_logs(logs: List[str]) -> Dict[str, Any]:
3030
# GET
3131
all_get_requests = len([line for line in logs if "CURL_INFO_HEADER_OUT: GET" in line])
3232

33-
get_requests = [line for line in logs if ": Downloading" in line]
33+
get_requests = [
34+
line for line in logs if "CURL_INFO_HEADER_IN: Content-Range: bytes" in line
35+
]
3436
get_values = [
35-
list(map(int, get.split(" Downloading ")[1].split(" ")[0].split("-")))
37+
list(
38+
map(
39+
int,
40+
get.split("CURL_INFO_HEADER_IN: Content-Range: bytes ")[1]
41+
.split("/")[0]
42+
.split("-"),
43+
)
44+
)
3645
for get in get_requests
3746
]
3847
get_values_str = [f"{start}-{end}" for (start, end) in get_values]

0 commit comments

Comments
 (0)