Skip to content

Commit

Permalink
fixes Profiler dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 21, 2024
1 parent 7c79634 commit 0df25ff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions lodstorage/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Created on 2022-11-18
@author: wf
"""
import time


class Profiler:
"""
simple profiler
"""

def __init__(self, msg, profile=True, with_start: bool = True):
"""
construct me with the given msg and profile active flag
Args:
msg(str): the message to show if profiling is active
profile(bool): True if messages should be shown
"""
self.msg = msg
self.profile = profile
if with_start:
self.start()

def start(self):
"""
start profiling
"""
self.starttime = time.time()
if self.profile:
print(f"Starting {self.msg} ...")

def time(self, extraMsg=""):
"""
time the action and print if profile is active
"""
elapsed = time.time() - self.starttime
if self.profile:
print(f"{self.msg}{extraMsg} took {elapsed:5.1f} s")
return elapsed
2 changes: 1 addition & 1 deletion lodstorage/sql_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from typing import Any, Dict, List, Type

from ngwidgets.profiler import Profiler
from lodstorage.profiler import Profiler
from sqlmodel import Session, create_engine, select

from lodstorage.query import QueryManager
Expand Down

0 comments on commit 0df25ff

Please sign in to comment.