コード例 #1
0
ファイル: run_info_data.py プロジェクト: wholtz/BASTet
 def wrapper(*args, **kwargs):
     # Pre-execute recording
     self.clear()  # Clear all runtime information data and profilers
     self.record_preexecute(
     )  # Record system provenance and pre-execution data
     start_time = time.time()  # Start the execution timer
     # Execute the function
     if not self.get_profile_memory():
         result = func(
             *args,
             **kwargs)  # Execute the function without memory profiling
     else:
         self.__memory_profiler = memory_profiler.LineProfiler()
         result = self.__memory_profiler(func)(
             *args,
             **kwargs)  # Execute the function with memory profiling
     # Post-execute recording
     execution_time = time.time(
     ) - start_time  # Compute the execution time
     self.record_postexecute(
         execution_time=execution_time)  # Record post-execution data
     self.clean_up()  # Clean up empty data
     if self.gather_data:
         self.gather()  # Gather the data from all MPI ranks
     # Return the result
     return result
コード例 #2
0
ファイル: profiling.py プロジェクト: mdeegen/paderbox
 def profiled_func(*args, **kwargs):
     profiler = memory_profiler.LineProfiler()
     try:
         profiler.add_function(func_or_list)
         profiler.enable_by_count()
         return func_or_list(*args, **kwargs)
     finally:
         memory_profiler.show_results(profiler)
コード例 #3
0
ファイル: debug_util.py プロジェクト: rrickk12/cellstar
 def wrapper(*args, **kwargs):
     if PROFILE_MEMORY:
         prof = memory_profiler.LineProfiler()
         val = prof(func)(*args, **kwargs)
         memory_profiler.show_results(prof)
     else:
         val = func(*args, **kwargs)
     return val
コード例 #4
0
ファイル: profiling.py プロジェクト: mdeegen/paderbox
            def profiled_func(*args, **kwargs):
                profiler = memory_profiler.LineProfiler()
                try:
                    if not func_or_list:
                        func_or_list.append(func)

                    for module in func_or_list:
                        if isfunction(module):
                            profiler.add_function(module)
                        elif isclass(module):
                            for k, v in module.__dict__.items():
                                if isfunction(v):
                                    profiler.add_function(v)

                    profiler.enable_by_count()
                    return func(*args, **kwargs)
                finally:
                    memory_profiler.show_results(profiler)
コード例 #5
0
    def function_action_execute(self, target, source, env):

        task_metrics = {
            'outputs': [str(t) for t in target],
            'inputs': [str(s) for s in source],
            'action': fullname(self.original_func),
            'builder': target[0].get_builder().get_name(target[0].get_env()),
        }
        profile = memory_profiler.LineProfiler(include_children=False)

        task_metrics['start_time'] = time.time_ns()
        thread_start_time = time.thread_time_ns()
        return_value = profile(self.original_func)(target=target,
                                                   source=source,
                                                   env=env)
        task_metrics['cpu_time'] = time.thread_time_ns() - thread_start_time
        task_metrics['end_time'] = time.time_ns()

        memory_increases_per_line = []
        for (file_where_code_is, lines_of_code) in profile.code_map.items():

            # skip the first item in the list because this is just the initial
            # memory state, and we are interested just in the increases
            for (line_number, memory_usage) in list(lines_of_code)[1:]:
                if memory_usage:
                    memory_increase = memory_usage[0]
                    memory_increases_per_line.append(memory_increase)

        task_metrics['mem_usage'] = int(
            sum(memory_increases_per_line) * 1024 * 1024)

        self.per_action_instance.build_tasks_metrics.append(task_metrics)
        task_metrics[
            'array_index'] = self.per_action_instance.build_tasks_metrics.index(
                task_metrics)

        return return_value
コード例 #6
0
ファイル: decorators.py プロジェクト: marthaboyer/beast
 def __call__(self, *args):
     self.m = memory_profiler.LineProfiler()
     self.c = self.m(self.f)
     return self.c(*args)
コード例 #7
0
def _mem_profile(fn):
    prof = mp.LineProfiler(backend="psutil")
    prof(fn)()
    mp.show_results(prof)
コード例 #8
0
 def wrapper(*args, **kwargs):
     prof = memory_profiler.LineProfiler(backend=backend)
     prof(func)(*args, **kwargs)
     return prof
コード例 #9
0
 def wrapper(*args, **kwargs):
     prof = memory_profiler.LineProfiler()
     val = prof(f)(*args, **kwargs)
     memory_profiler.show_results(prof, stream=sys.stdout)
     return val
コード例 #10
0
"""
Line-by-line profiling of RAM use of Python scripts in
:mod:`mandelbrot.implementations` using :mod:`memory_profiler`.
"""
import memory_profiler

import mandelbrot

if __name__ == "__main__":
    args = mandelbrot.parsed_mandelbrot_args()

    for impl in mandelbrot.all_implementations():
        print(f"About to profile {impl.id_}")

        profile = memory_profiler.LineProfiler()
        profile.add_function(impl.callable)
        cmd = (
            f"{impl.fully_qualified_name}(grid_side_size={args.grid_side_size}, "
            f"max_iter={args.max_iter})")
        global_ns = globals()
        local_ns = locals()
        profile.runctx(cmd, global_ns, local_ns)
        memory_profiler.show_results(profile)