Ejemplo n.º 1
0
 def clear(self):
     if DEBUG and self.hit + self.miss > 100:
         Log.note(
             "Hit Rate: {{rate|round(places=2)|percent}} (hits={{hits}},"
             " misses={{misses}})",
             rate=self.hit / (self.hit + self.miss),
             hits=self.hit,
             misses=self.miss,
         )
     self.hit = 0
     self.miss = 0
     self.cache.clear()
Ejemplo n.º 2
0
# encoding: utf-8

from mo_parsing.utils import Log
from mo_parsing.cache import packrat_cache
from mo_parsing.core import ParserElement
from mo_parsing.exceptions import ParseException

try:
    from jx_python import jx
    from mo_files import File
    from mo_future import text, process_time
    from mo_times import Date
    from pyLibrary import convert
except Exception as casue:
    Log.note("please pip install jx-python and pyLibrary")


class Profiler(object):
    def __init__(self, file):
        """
        USE with Profiler("myfile.tab"): TO ENABLE PER-PARSER PROFILING
        :param file:
        """
        self.file = File(file).set_extension("tab")
        self.previous_parse = None

    def __enter__(self):
        timing.clear()
        self.previous_parse = ParserElement._parse
        ParserElement._parse = _profile_parse