Skip to content

Commit

Permalink
Add objectgraph logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 21, 2024
1 parent bab6939 commit cd7e14c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tilecloud_chain/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Generate the tiles, generate the queue, ..."""

import gc
import logging
import os
import random
Expand All @@ -13,6 +14,7 @@
from typing import IO, cast

import boto3
import objgraph
import prometheus_client
import tilecloud.filter.error
from tilecloud import Tile, TileCoord, TileStore
Expand Down Expand Up @@ -44,6 +46,20 @@
_LOGGER = logging.getLogger(__name__)


def _objgraph(tile: Tile) -> Tile:
"""Log the objgraph."""
[gc.collect(generation) for generation in range(3)]
values = [
f"{name}: {number} {diff}"
for name, number, diff in objgraph.growth(
limit=int(os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_LIMIT", "10"))
)
]
if values:
_LOGGER.debug("Objgraph growth in queue:\n%s", "\n".join(values))
return tile


class LogTilesContext:
"""Logging tile context."""

Expand Down Expand Up @@ -111,6 +127,9 @@ def gene(self, layer_name: str | None = None) -> None:
if self._options.role != "slave" or self._options.tiles:
self._generate_queue(layer_name)

if os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_GENE", "0").lower() in ("1", "true", "on"):
self._gene.imap(_objgraph)

self.generate_consume()
self.generate_resume(layer_name)

Expand Down
17 changes: 17 additions & 0 deletions tilecloud_chain/store/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import gc
import io
import logging
import multiprocessing
Expand All @@ -38,6 +39,7 @@
from datetime import datetime, timedelta
from typing import Any, cast

import objgraph
import sqlalchemy
import sqlalchemy.sql.functions
from prometheus_client import Counter, Gauge, Summary
Expand Down Expand Up @@ -525,6 +527,21 @@ def list(self) -> Iterator[Tile]:
continue
job_id = self.jobs.pop(config_filename)
try:
if os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_POSTGRESQL", "0").lower() in (
"1",
"true",
"on",
):
[gc.collect(generation) for generation in range(3)]
values = [
f"{name}: {number} {diff}"
for name, number, diff in objgraph.growth(
limit=int(os.environ.get("TILECLOUD_CHAIN_OBJGRAPH_LIMIT", "10"))
)
]
if values:
_LOGGER.debug("Objgraph growth in postgresql:\n%s", "\n".join(values))

with self.SessionMaker() as session:
sqlalchemy_tile = (
session.query(Queue)
Expand Down

0 comments on commit cd7e14c

Please sign in to comment.