gemseo.core.execution_statistics module#
Execution statistics.
- class ExecutionStatistics(name)[source]#
Bases:
Serializable
Record execution statistics of objects.
This should be applied to objects such as
BaseMonitoredProcess
, hereafter referred to as the _measured object_.A measured object often has an execution method whose number of calls is counted and time measured. Some have also a linearization method whose number of calls is counted too.
The recording of the statistics can be disabled all at once by setting
is_enabled
toFalse
. By default, it is set toTrue
. When enabled, the recording of time stamps can be enabled by settingis_time_stamps_enabled
toTrue
. By default, it is set toFalse
. These switches are global and shall be modified from the class.If any of those switches are disabled, the recordings, if any, are not removed.
The helper method
record()
is a context manager that should be used to record statistics.The results of the recordings can be accessed with
n_calls
,n_calls_linearize
,duration
,time_stamps
. The time stamps should be processed withcreate_gantt_chart()
.The recorded statistics are not restored after pickling.
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
name (str) -- The name of the measured object.
- record(linearize=False)[source]#
Record execution statistics while executing code in a context manager.
- Parameters:
linearize (bool) --
Whether measuring execution for linearization.
By default it is set to False.
- Return type:
Generator[Any, Any, Any]
- property duration: float | None#
The cumulated execution duration.
This is property is multiprocessing safe.
- Raises:
RuntimeError -- If the statistics are disabled.
- property n_calls: int | None#
The number of executions.
This property is multiprocessing safe.
- Raises:
RuntimeError -- If the statistics are disabled.
- property n_calls_linearize: int | None#
The number of linearizations.
This property is multiprocessing safe.
- Raises:
RuntimeError -- If the statistics are disabled.
- time_stamps: ClassVar[DictProxy[str, ListProxy[tuple[float, float, bool]]] | None] = None#
The mapping from the measured object names to their execution time stamps.
It is
None
when time stamps recording is disabled.The structure is
{ "measure object name": [ (start time, end time, whether it is for linearization), ... ], "other measure object name": [ ... ], }