Skip to content

Commit 01a9c9b

Browse files
committed
Added memory-cpu monitoring.
1 parent bdaec56 commit 01a9c9b

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

functions-python/pmtiles_builder/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ google-cloud-storage
2424
# Configuration
2525
python-dotenv==1.0.0
2626
tippecanoe
27+
psutil
2728

functions-python/pmtiles_builder/src/gtfs_stops_to_geojson.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections import defaultdict
55

66
from csv_cache import CsvCache, ROUTES_FILE, TRIPS_FILE, STOP_TIMES_FILE, STOPS_FILE
7+
from shared.helpers.runtime_metrics import track_metrics
78

89
logger = logging.getLogger(__name__)
910

@@ -41,6 +42,7 @@ def build_stop_to_routes(stop_times_data, trips_data):
4142
return stop_to_routes
4243

4344

45+
@track_metrics(metrics=("time", "memory", "cpu"))
4446
def convert_stops_to_geojson(csv_cache: CsvCache, output_file):
4547
"""Converts GTFS stops data to a GeoJSON file."""
4648
routes_map = create_routes_map(csv_cache.get_file(ROUTES_FILE))

functions-python/pmtiles_builder/src/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
AGENCY_FILE,
3636
SHAPES_FILE,
3737
)
38-
from shared.helpers.logger import get_logger
38+
from shared.helpers.runtime_metrics import track_metrics
39+
from shared.helpers.logger import get_logger, init_logger
3940
from gtfs_stops_to_geojson import convert_stops_to_geojson
4041

4142
import flask
4243
import functions_framework
4344

45+
init_logger()
46+
4447

4548
@functions_framework.http
4649
def build_pmtiles_handler(request: flask.Request) -> dict:
@@ -305,6 +308,7 @@ def _upload_files_to_gcs(self, file_to_upload):
305308
except Exception as e:
306309
raise Exception(f"Failed to upload files to GCS: {e}") from e
307310

311+
@track_metrics(metrics=("time", "memory", "cpu"))
308312
def _create_shapes_index(self) -> dict:
309313
"""
310314
Create an index for shapes.txt file to quickly access shape points by shape_id.
@@ -370,6 +374,7 @@ def _get_shape_points(self, shape_id, index):
370374
except Exception as e:
371375
raise Exception(f"Failed to get shape points for {shape_id}: {e}") from e
372376

377+
@track_metrics(metrics=("time", "memory", "cpu"))
373378
def _create_routes_geojson(self):
374379
try:
375380
agencies = self._load_agencies()
@@ -454,6 +459,7 @@ def _create_routes_geojson(self):
454459
except Exception as e:
455460
raise Exception(f"Failed to create routes GeoJSON: {e}") from e
456461

462+
@track_metrics(metrics=("time", "memory", "cpu"))
457463
def _run_tippecanoe(self, input_file, output_file):
458464
self.logger.info("Running tippecanoe for input file %s", input_file)
459465
try:
@@ -479,6 +485,7 @@ def _run_tippecanoe(self, input_file, output_file):
479485
f"Failed to run tippecanoe for output file {output_file}: {e}"
480486
) from e
481487

488+
@track_metrics(metrics=("time", "memory", "cpu"))
482489
def _create_routes_json(self):
483490
self.logger.info("Creating routes json...")
484491
try:

0 commit comments

Comments
 (0)