Exemple #1
0

#
#   AUTO-TUPLE
#
@timemory.util.auto_tuple(get_timemory_config(), key="")
def bar():
    """
    Demonstrate decorator and context-manager with auto_tuple
    Run fibonacci calculation and then sleep for 2 seconds within context-manager
    """
    print("fibonacci({}) = {}".format(nfib, fibonacci(nfib)))
    with timemory.util.auto_tuple(get_timemory_config(), key="[sleep]"):
        time.sleep(2)


#
#   EXECUTE
#
if __name__ == "__main__":

    # do some work
    foo()
    bar()

    # get the dictionary
    data = timemory.get()
    # print the dictionary
    print("TIMEMORY_DATA:\n{}".format(
        json.dumps(data, indent=4, sort_keys=True)))
Exemple #2
0
    def from_timemory(input=None, select=None):
        """Read in timemory data.

        Links:
            https://github.com/NERSC/timemory
            https://timemory.readthedocs.io

        Arguments:
            input (str or file-stream or dict or None):
                Valid argument types are:

                1. Filename for a timemory JSON tree file
                2. Open file stream to one of these files
                3. Dictionary from timemory JSON tree

                    Currently, timemory supports two JSON layouts: flat and tree.
                The former is a 1D-array representation of the hierarchy which
                represents the hierarchy via indentation schemes in the labels
                and is not compatible with hatchet. The latter is a hierarchical
                representation of the data and is the required JSON layout when
                using hatchet. Timemory JSON tree files typically have the
                extension ".tree.json".

                If input is None, this assumes that timemory has been
                recording data within the application that is using hatchet.
                In this situation, this method will attempt to import the
                data directly from timemory.
                    At the time of this writing, the direct data import will:

                1. Stop any currently collecting components
                2. Aggregate child thread data of the calling thread
                3. Clear all data on the child threads
                4. Aggregate the data from any MPI and/or UPC++ ranks.

                Thus, if MPI or UPC++ is used, every rank must call this routine.
                The zeroth rank will have the aggregation and all the other non-zero
                ranks will only have the rank-specific data.
                    Whether or not the per-thread and per-rank data itself is
                combined is controlled by the `collapse_threads` and `collapse_processes`
                attributes in the `timemory.settings` submodule.
                    In the C++ API, it is possible for only #1 to be applied and data
                can be obtained for an individual thread and/or rank without aggregation.
                This is not currently available to Python, however, it can be made
                available upon request via a GitHub Issue.

            select (list of str):
                A list of strings which match the component enumeration names
        """
        from .readers.timemory_reader import TimemoryReader

        if input is not None:
            try:
                return TimemoryReader(input, select).read()
            except IOError:
                pass
        else:
            try:
                import timemory

                TimemoryReader(timemory.get(hierarchy=True), select).read()
            except ImportError:
                print(
                    "Error! timemory could not be imported. Provide filename, file stream, or dict."
                )
                raise
Exemple #3
0
 def get_results(report=False):
     # Get the results as dictionary
     data = timemory.get()
     if report is True:
         print("\n{}".format(json.dumps(data, indent=4, sort_keys=True)))
     return data