Example #1
0
    def get(self, filter={}):
        _yappi._pause()
        self.clear()
        try:
            _yappi.enum_func_stats(self._enumerator, filter)

            # convert the children info from tuple to YChildFuncStat
            for stat in self:

                _childs = YChildFuncStats()
                for child_tpl in stat.children:
                    rstat = self[child_tpl[0]]

                    # sometimes even the profile results does not contain the result because of filtering
                    # or timing(call_leave called but call_enter is not), with this we ensure that the children
                    # index always point to a valid stat.
                    if rstat is None:
                        continue

                    tavg = rstat.ttot / rstat.ncall
                    cfstat = YChildFuncStat(child_tpl + (
                        tavg,
                        rstat.builtin,
                        rstat.full_name,
                        rstat.module,
                        rstat.lineno,
                        rstat.name,
                    ))
                    _childs.append(cfstat)
                stat.children = _childs
            result = super(YFuncStats, self).get()
        finally:
            _yappi._resume()
        return result
Example #2
0
def get_func_stats(tag=None, ctx_id=None, filter=None, filter_callback=None):
    """
    Gets the function profiler results with given filters and returns an iterable.

    filter: is here mainly for backward compat. we will not document it anymore.
    tag, ctx_id: select given tag and ctx_id related stats in C side.
    filter_callback: we could do it like: get_func_stats().filter(). The problem
    with this approach is YFuncStats has an internal list which complicates:
        - delete() operation because list deletions are O(n)
        - sort() and pop() operations currently work on sorted list and they hold the
          list as sorted.
    To preserve above behaviour and have a delete() method, we can use an OrderedDict()
    maybe, but simply that is not worth the effort for an extra filter() call. Maybe
    in the future.
    """
    if not filter:
        filter = {}

    if tag:
        filter['tag'] = tag
    if ctx_id:
        filter['ctx_id'] = ctx_id

    # multiple invocation pause/resume is allowed. This is needed because
    # not only get() is executed here.
    _yappi._pause()
    try:
        stats = YFuncStats().get(filter=filter,
                                 filter_callback=filter_callback)
    finally:
        _yappi._resume()
    return stats
Example #3
0
File: yappi.py Project: nirs/yappi
    def get(self):
        _yappi._pause()
        self.clear()
        try:
            _yappi.enum_func_stats(self._enumerator)

            # convert the children info from tuple to YChildFuncStat
            for stat in self:
                _childs = YChildFuncStats()
                for child_tpl in stat.children:
                    rstat = self[child_tpl[0]]

                    # sometimes even the profile results does not contain the result because of filtering
                    # or timing(call_leave called but call_enter is not), with this we ensure that the children
                    # index always point to a valid stat.
                    if rstat is None:
                        continue

                    tavg = rstat.ttot / rstat.ncall
                    cfstat = YChildFuncStat(child_tpl+(tavg, rstat.builtin, rstat.full_name, rstat.module,
                        rstat.lineno, rstat.name,))
                    _childs.append(cfstat)
                stat.children = _childs
            result = super(YFuncStats, self).get()
        finally:
            _yappi._resume()
        return result
Example #4
0
 def get(self):
     _yappi._pause()
     self.clear()
     try:
         _yappi.enum_thread_stats(self._enumerator)
         result = super(YThreadStats, self).get()
     finally:
         _yappi._resume()
     return result
Example #5
0
def clear_stats():
    """
    Clears all of the profile results.
    """
    _yappi._pause()
    try:
        _yappi.clear_stats()
    finally:
        _yappi._resume()
Example #6
0
File: yappi.py Project: nirs/yappi
def clear_stats():
    """
    Clears all of the profile results.
    """
    _yappi._pause()
    try:
        _yappi.clear_stats()
    finally:
        _yappi._resume()
Example #7
0
File: yappi.py Project: nirs/yappi
 def get(self):
     _yappi._pause()
     self.clear()
     try:
         _yappi.enum_thread_stats(self._enumerator)
         result = super(YThreadStats, self).get()
     finally:
         _yappi._resume()
     return result
Example #8
0
def get_thread_stats():
    """
    Gets the thread profiler results with given filters and returns an iterable.
    """
    _yappi._pause()
    try:
        stats = YThreadStats().get()
    finally:
        _yappi._resume()
    return stats
Example #9
0
File: yappi.py Project: nirs/yappi
def get_thread_stats():
    """
    Gets the thread profiler results with given filters and returns an iterable.
    """
    _yappi._pause()
    try:
        stats = YThreadStats().get()
    finally:
        _yappi._resume()
    return stats
Example #10
0
File: yappi.py Project: nirs/yappi
def get_func_stats():
    """
    Gets the function profiler results with given filters and returns an iterable.
    """
    # multiple invocation pause/resume is allowed. This is needed because
    # not only get() is executed here.
    _yappi._pause()
    try:
        stats = YFuncStats().get()
    finally:
        _yappi._resume()
    return stats
Example #11
0
def get_func_stats(filter=None):
    """
    Gets the function profiler results with given filters and returns an iterable.
    """
    # multiple invocation pause/resume is allowed. This is needed because
    # not only get() is executed here.
    _yappi._pause()
    try:
        stats = YFuncStats().get(filter=filter)
    finally:
        _yappi._resume()
    return stats
Example #12
0
    def get(self):

        backend = _yappi.get_context_backend()
        if self._BACKEND != backend:
            raise YappiError(
                "Cannot retrieve stats for '%s' when backend is set as '%s'" %
                (self._BACKEND.lower(), backend.lower()))

        _yappi._pause()
        self.clear()
        try:
            _yappi.enum_context_stats(self._enumerator)
            result = super(_YContextStats, self).get()
        finally:
            _yappi._resume()
        return result
Example #13
0
def get_func_stats(filter={}):
    """
    Gets the function profiler results with given filters and returns an iterable.
    """
    _VALID_FILTER_KEYS = set(["tag", "name", "module", "ctx_id"])
    if len(filter):
        for filter_key in filter:
            if filter_key not in _VALID_FILTER_KEYS:
                warnings.warn('Invalid filter key.(%s)' % (filter_key))

    # multiple invocation pause/resume is allowed. This is needed because
    # not only get() is executed here.
    _yappi._pause()
    try:
        stats = YFuncStats().get(filter=filter)
    finally:
        _yappi._resume()
    return stats