Esempio n. 1
0
    def __init__(self, description):
        from pyLibrary.queries.windows import Stats

        if ON and not hasattr(self, "description"):
            self.description = description
            self.samples = []
            self.stats = Stats()()
            profiles[description] = self
Esempio n. 2
0
    def __init__(self, description):
        from pyLibrary.queries.windows import Stats

        if ON and not hasattr(self, "description"):
            self.description = description
            self.samples = []
            self.stats = Stats()()
            profiles[description] = self
Esempio n. 3
0
class Profiler(object):
    """
    VERY SIMPLE PROFILER FOR USE IN with STATEMENTS
    PRIMARILY TO BE USED IN PyPy, WHERE cProfile IMPACTS
    OPTIMIZED RUN TIME TOO MUCH
    """

    def __new__(cls, *args):
        if ON:
            output = profiles.get(args[0])
            if output:
                return output
        output = object.__new__(cls, *args)
        return output

    def __init__(self, description):
        from pyLibrary.queries.windows import Stats

        if ON and not hasattr(self, "description"):
            self.description = description
            self.samples = []
            self.stats = Stats()()
            profiles[description] = self

    def __enter__(self):
        if ON:
            self.start = clock()
        return self

    def __exit__(self, type, value, traceback):
        if ON:
            self.end = clock()
            duration = self.end - self.start

            from pyLibrary.queries.windows import Stats

            self.stats.add(duration)
            if self.samples is not None:
                self.samples.append(duration)
                if len(self.samples) > 100:
                    self.samples = None
Esempio n. 4
0
class Profiler(object):
    """
    VERY SIMPLE PROFILER FOR USE IN with STATEMENTS
    PRIMARILY TO BE USED IN PyPy, WHERE cProfile IMPACTS
    OPTIMIZED RUN TIME TOO MUCH
    """
    def __new__(cls, *args):
        if ON:
            output = profiles.get(args[0])
            if output:
                return output
        output = object.__new__(cls, *args)
        return output

    def __init__(self, description):
        from pyLibrary.queries.windows import Stats

        if ON and not hasattr(self, "description"):
            self.description = description
            self.samples = []
            self.stats = Stats()()
            profiles[description] = self

    def __enter__(self):
        if ON:
            self.start = clock()
        return self

    def __exit__(self, type, value, traceback):
        if ON:
            self.end = clock()
            duration = self.end - self.start

            from pyLibrary.queries.windows import Stats

            self.stats.add(duration)
            if self.samples is not None:
                self.samples.append(duration)
                if len(self.samples) > 100:
                    self.samples = None