Standardized logging code to all global var; writers now accessible from all files (#62)

* added skeleton for terminal logger

* done skeleton terminal writer logic... todo: actual calls to the write classes

* moved lambda to top function

* added logic to support timing

* prettier printing

* prettier printing

* lint

* separated out timing and other stats variables. printing in dict format

* keeping logging history and wiping rest

* updated logic to calculate total times instead of average times

* made stats tracker configurable

* moved stats tracker and profiler to own class file; implemented basic functionality for profiler

* lint removing duplicate function

* update readme; moved around config variables

* profiler prints on sig kill

* merge

* standardized all logging to global variables
This commit is contained in:
evonneng authored and GitHub committed 2022-05-06 21:55:33 -07:00
1 parent 5cb00c286d
commit a498a6cc64
9 files changed
+322 -67

No files matched your search

+21 -6
View File
@@ -4,13 +4,14 @@ Profiler base class and functionality
import logging
import sys
import time
from typing import Callable
from typing import Callable, Dict
from omegaconf import DictConfig
from mattport.utils import comms
from mattport.utils.decorators import check_main_thread, check_profiler_enabled, decorate_all
PROFILER = None
PROFILER = []
def time_function(func: Callable) -> Callable:
@@ -25,20 +26,34 @@ def time_function(func: Callable) -> Callable:
for attr in func.__qualname__.split(".")[:-1]:
class_str += f"{vals[attr].__qualname__}_"
class_str += func.__name__
PROFILER.update_time(class_str, start, time.time())
PROFILER[0].update_time(class_str, start, time.time())
return ret
return wrapper
def flush_profiler(config: Dict):
"""Method that checks if profiler is enabled before flushing
Args:
config (Dict): config check
"""
if config.enable_profiler and PROFILER:
PROFILER[0].print_profile()
def setup_profiler(config: DictConfig):
"""Initialization of profilers"""
if comms.is_main_process():
PROFILER.append(Profiler(config))
@decorate_all([check_profiler_enabled, check_main_thread])
class Profiler:
"""Profiler class"""
def __init__(self, config: DictConfig, is_main_thread: bool):
def __init__(self, config: DictConfig):
self.config = config
if self.config.logging.enable_profiler:
self.is_main_thread = is_main_thread
self.profiler_dict = {}
def update_time(self, func_name: str, start_time: float, end_time: float):