Skip to content

Commit 9a9aad3

Browse files
committed
Add some logging to track time taken for each step
1 parent d8f8197 commit 9a9aad3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

stac_search/agents/items_search.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from dataclasses import dataclass
66
from pprint import pformat
7+
import time
78
from typing import List, Dict, Any, Union
89

910
import requests
@@ -279,10 +280,16 @@ class ItemSearchResult:
279280

280281

281282
async def item_search(ctx: Context) -> ItemSearchResult:
283+
start_time = time.time()
282284
# formulate the query to be used for the search
283285
results = await search_items_agent.run(
284286
f"Find items for the query: {ctx.query}", deps=ctx
285287
)
288+
query_formulation_time = time.time()
289+
logger.info(
290+
f"Query formulation time: {query_formulation_time - start_time} seconds"
291+
)
292+
286293
catalog_url_to_use = ctx.catalog_url or STAC_CATALOG_URL
287294

288295
# determine the collections to search
@@ -327,6 +334,10 @@ async def item_search(ctx: Context) -> ItemSearchResult:
327334
}
328335

329336
logger.info(f"Searching with params: {params}")
337+
params_formulation_time = time.time()
338+
logger.info(
339+
f"Params formulation time: {params_formulation_time - query_formulation_time} seconds"
340+
)
330341

331342
polygon = get_polygon_from_geodini(results.data.location)
332343
if polygon:
@@ -337,14 +348,28 @@ async def item_search(ctx: Context) -> ItemSearchResult:
337348
return ItemSearchResult(
338349
items=None, search_params=params, aoi=None, explanation=explanation
339350
)
351+
geocoding_time = time.time()
352+
logger.info(
353+
f"Geocoding time: {geocoding_time - params_formulation_time} seconds"
354+
)
340355

341356
if ctx.return_search_params_only:
342357
logger.info("Returning STAC query parameters only")
358+
total_time = time.time() - start_time
359+
logger.info(
360+
f"Total time: {total_time} seconds"
361+
)
343362
return ItemSearchResult(
344363
search_params=params, aoi=polygon, explanation=explanation
345364
)
346365

347366
items = list(client.search(**params).items_as_dicts())
367+
search_time = time.time()
368+
logger.info(
369+
f"Search time: {search_time - geocoding_time} seconds"
370+
)
371+
total_time = time.time() - start_time
372+
logger.info(f"Total time: {total_time} seconds")
348373
return ItemSearchResult(
349374
items=items, aoi=polygon, explanation=explanation, search_params=params
350375
)

0 commit comments

Comments
 (0)