From 32dd0f543aeb484f93b070f5d7938a46a4cefa96 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 24 Jan 2022 17:58:35 -0800 Subject: [PATCH] Log the time it takes to save the game. --- game/persistency.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/game/persistency.py b/game/persistency.py index 4520b021..9b982407 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -1,12 +1,13 @@ from __future__ import annotations import logging -import os import pickle import shutil from pathlib import Path from typing import Optional, TYPE_CHECKING +from game.profiling import logged_duration + if TYPE_CHECKING: from game import Game @@ -54,14 +55,15 @@ def load_game(path: str) -> Optional[Game]: def save_game(game: Game) -> bool: - try: - with open(_temporary_save_file(), "wb") as f: - pickle.dump(game, f) - shutil.copy(_temporary_save_file(), game.savepath) - return True - except Exception: - logging.exception("Could not save game") - return False + with logged_duration("Saving game"): + try: + with open(_temporary_save_file(), "wb") as f: + pickle.dump(game, f) + shutil.copy(_temporary_save_file(), game.savepath) + return True + except Exception: + logging.exception("Could not save game") + return False def autosave(game: Game) -> bool: