File: line_profiler_utils.py

package info (click to toggle)
python-line-profiler 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 776 kB
  • sloc: python: 3,097; sh: 810; ansic: 65; makefile: 15
file content (25 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import inspect


def add_imported_function_or_module(self, item):
    """Method to add an object to LineProfiler to be profiled.

    This method is used to extend an instance of LineProfiler so it can identify
    whether an object is function/method, class or module and handle it's
    profiling accordingly.

    Args:
        item (Callable | Type | ModuleType):
            object to be profiled.
    """
    if inspect.isfunction(item):
        self.add_function(item)
    elif inspect.isclass(item):
        for k, v in item.__dict__.items():
            if inspect.isfunction(v):
                self.add_function(v)
    elif inspect.ismodule(item):
        self.add_module(item)
    else:
        return
    self.enable_by_count()