Belle II Software development
PyProfilingModule Class Reference
Inheritance diagram for PyProfilingModule:
WrapperModule

Public Member Functions

 __init__ (self, module, output_file_name=None)
 
 initialize (self)
 
 event (self)
 
 terminate (self)
 
 wrapper_name (self)
 
 param (self)
 
 available_params (self)
 
 compose_wrapped_module_name (self, module)
 
 get_name (self)
 
 beginRun (self)
 
 endRun (self)
 

Public Attributes

str output_file_name = self.default_output_file_name
 The output file name the results will be written into.
 
 profiler = cProfile.Profile()
 The used profiler instance.
 
 module = module
 The wrapped module.
 

Static Public Attributes

str default_output_file_name = "profile.txt"
 The default name for output if none is given.
 

Detailed Description

Wrapper module that evaluates the computational performance of python modules.

Uses cProfile.

Attributes:
  module (basf2.Module): The wrapped module that should be profiled.
    Should be a module written in Python, since the profile interacts
    with the interpreter for the measurements, but cannot look into c++ implementations.

  output_file_name (str, optional): Path to the file where the profiling information
    shall be stored. Defaults to profile.txt.

  profiler (cProfile.Profile): Profiler instance to manage and extract the profiling statistics.

Definition at line 111 of file metamodules.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
module,
output_file_name = None )
Create a new PyProfilingModule wrapped around the given module
   which outputs its results to the output_file_name of given (if not, to profile.txt).

Definition at line 131 of file metamodules.py.

131 def __init__(self, module, output_file_name=None):
132 """Create a new PyProfilingModule wrapped around the given module
133 which outputs its results to the output_file_name of given (if not, to profile.txt)."""
134 super().__init__(module)
135
136
137 self.output_file_name = self.default_output_file_name
138
139 if output_file_name is not None:
140 self.output_file_name = output_file_name
141

Member Function Documentation

◆ available_params()

available_params ( self)
inherited
Forwards the available parameters

Definition at line 78 of file metamodules.py.

78 def available_params(self):
79 """Forwards the available parameters"""
80 return self.module.available_params
81

◆ beginRun()

beginRun ( self)
inherited
Begin run method of the module

Definition at line 94 of file metamodules.py.

94 def beginRun(self):
95 """Begin run method of the module"""
96 self.module.beginRun()
97

◆ compose_wrapped_module_name()

compose_wrapped_module_name ( self,
module )
inherited
Compose a name that indicates the wrapped module.

Definition at line 82 of file metamodules.py.

82 def compose_wrapped_module_name(self, module):
83 """Compose a name that indicates the wrapped module."""
84 return f"{self.wrapper_name}({module.name()})"
85

◆ endRun()

endRun ( self)
inherited
End run method of the module

Definition at line 102 of file metamodules.py.

102 def endRun(self):
103 """End run method of the module"""
104 self.module.endRun()
105

◆ event()

event ( self)
Event method of the module

Reimplemented from WrapperModule.

Definition at line 148 of file metamodules.py.

148 def event(self):
149 """Event method of the module"""
150 profiler = self.profiler
151 profiler.enable()
152 super().event()
153 profiler.disable()
154

◆ get_name()

get_name ( self)
inherited
Forwards the name().

Definition at line 86 of file metamodules.py.

86 def get_name(self):
87 """Forwards the name()."""
88 return self.name()
89

◆ initialize()

initialize ( self)
Initialize method of the module

Reimplemented from WrapperModule.

Definition at line 142 of file metamodules.py.

142 def initialize(self):
143 """Initialize method of the module"""
144
145 self.profiler = cProfile.Profile()
146 super().initialize()
147

◆ param()

param ( self)
inherited
Forwards the parameters

Definition at line 73 of file metamodules.py.

73 def param(self):
74 """Forwards the parameters"""
75 return self.module.param
76

◆ terminate()

terminate ( self)
Terminate method of the module

Reimplemented from WrapperModule.

Definition at line 155 of file metamodules.py.

155 def terminate(self):
156 """Terminate method of the module"""
157 super().terminate()
158 sortby = 'cumulative'
159 with open(self.output_file_name, 'w') as profile_output_file:
160 profile_stats = pstats.Stats(self.profiler, stream=profile_output_file)
161 profile_stats.sort_stats(sortby)
162 profile_stats.print_stats()
163
164

◆ wrapper_name()

wrapper_name ( self)
inherited
Name of the wrapper class.

Definition at line 68 of file metamodules.py.

68 def wrapper_name(self):
69 """Name of the wrapper class."""
70 return self.__class__.__name__
71

Member Data Documentation

◆ default_output_file_name

str default_output_file_name = "profile.txt"
static

The default name for output if none is given.

Definition at line 129 of file metamodules.py.

◆ module

module = module
inherited

The wrapped module.

Definition at line 53 of file metamodules.py.

◆ output_file_name

output_file_name = self.default_output_file_name

The output file name the results will be written into.

Definition at line 137 of file metamodules.py.

◆ profiler

profiler = cProfile.Profile()

The used profiler instance.

Definition at line 145 of file metamodules.py.


The documentation for this class was generated from the following file: