asaptools.timekeeper module¶
A module containing the TimeKeeper class.
This module contains is a simple class to act as a time keeper for internal performance monitoring (namely, timing given processes).
Copyright 2020 University Corporation for Atmospheric Research
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
class
asaptools.timekeeper.TimeKeeper(time=<built-in function time>)[source]¶ Bases:
objectClass to keep timing recordings, start/stop/reset timers.
-
_time¶ The method to use for getting the time (e.g., time.time)
-
_start_times¶ A dictionary of start times for each named timer
- Type
dict
-
_accumulated_times¶ A dictionary of the total accumulated times for each named timer
- Type
dict
-
_added_order¶ A list containing the name of each timer, in the order it was added to the TimeKeeper
- Type
list
-
get_all_times()[source]¶ Returns the dictionary of accumulated times on the local processor.
- Returns
The dictionary of accumulated times
- Return type
dict
-
get_names()[source]¶ Method to return the clock names in the order in which they were added.
- Returns
The list of timer names in the order they were added
- Return type
list
-
get_time(name)[source]¶ Returns the accumulated time of the given timer.
If the given timer name has never been created, it is created and the accumulated time is set to zero before returning.
- Parameters
name – The name or ID of the timer to stop
- Returns
- The accumulated time of the named timer (or 0.0 if the
named timer has never been created before).
- Return type
float
-
reset(name)[source]¶ Method to reset a timer associated with a given name.
If the name has never been used before, the timer is created and the accumulated time is set to 0. If the timer has been used before, the accumulated time is set to 0.
- Parameters
name – The name or ID of the timer to reset
-
start(name)[source]¶ Method to start a timer associated with a given name.
If the name has never been used before, the timer is created and the accumulated time is set to 0.
- Parameters
name – The name or ID of the timer to start
-
stop(name)[source]¶ Stop the timing and add the accumulated time to the timer.
Method to stop a timer associated with a given name, and adds the accumulated time to the timer when stopped. If the given timer name has never been used before (either by calling reset() or start()), the timer is created and the accumulated time is set to 0.
- Parameters
name – The name or ID of the timer to stop
-