Пример #1
0
    def test_no_timeline(self):
        """no_timeline"""
        old_data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]
        os.environ["TIMEMORY_TIMELINE_PROFILE"] = "OFF"
        tim.settings.parse()

        n = 5
        with marker(
                components=["wall_clock", "current_peak_rss"],
                key=self.shortDescription(),
        ):
            for i in range(n):
                with marker(
                        components=["wall_clock", "current_peak_rss"],
                        key=self.shortDescription(),
                ):
                    fibonacci(n)

        # counts must be == 1
        data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]

        maxcnt = 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] >= 1)
                maxcnt = max(k["stats"]["count"], maxcnt)
        self.assertTrue(maxcnt > 1)
Пример #2
0
def timemory_json_data():

    import numpy as np
    import timemory
    from timemory.bundle import marker
    from timemory.trace import Config as TracerConfig
    from timemory.profiler import Config as ProfilerConfig
    from timemory_func import prof_func, trace_func, components

    # disable automatic output during finalization
    timemory.settings.auto_output = False

    # enable flat collection because of the coverage exe
    timemory.settings.flat_profile = True

    with marker(components, key="main"):
        nx = 10
        ny = 10
        tol = 5.0e-2
        profl_arr = np.random.rand(nx, ny)
        trace_arr = np.zeros([nx, ny], dtype=np.float)
        trace_arr[:, :] = profl_arr[:, :]

        # restrict the scope of the profiler
        ProfilerConfig.only_filenames = ["timemory_func.py", "_methods.py"]
        ProfilerConfig.include_line = False
        prof_func(profl_arr, tol)

        # restrict the scope of the tracer
        TracerConfig.only_filenames = ["timemory_func.py"]
        trace_func(trace_arr, tol)

    return timemory.get(hierarchy=True)
Пример #3
0
def fib(n, instr):
    if instr == True:
        with marker(components=["wall_clock"], key="fib"):
            return n if n < 2 else (fib(n - 1, True) + fib(n - 2, False))

    else:
        return n if n < 2 else (fibonacci(n - 1) + fibonacci(n - 2))
Пример #4
0
def fibonacci(n, with_arg=True):
    with marker(
        ["wall_clock", "peak_rss", "current_peak_rss"],
            "fib({})".format(n) if with_arg else "",
            mode="full" if not with_arg else "defer",
    ):
        return (n if n < 2 else
                (fibonacci(n - 1, with_arg) + fibonacci(n - 2, with_arg)))
Пример #5
0
 def _run(name):
     with auto_tuple(get_config(["wall_clock"]), key="auto_tuple_serial"):
         n = 8 * settings.throttle_count
         for i in range(n):
             with marker(components=("wall_clock"), key=self.shortDescription()):
                 pass
     self.assertFalse(tim.trace.is_throttled("thread"))
     self.assertFalse(tim.trace.is_throttled(
         self.shortDescription()))
Пример #6
0
def fibonacci(n, with_arg=True):
    mode = "full" if not with_arg else "defer"
    with marker(
        ["wall_clock", "peak_rss", "current_peak_rss"],
            "fib({})".format(n) if with_arg else "",
            mode=mode,
    ):
        arr = np.ones([100, 100], dtype=float)  # noqa: F841
        return (n if n < 2 else
                (fibonacci(n - 1, with_arg) + fibonacci(n - 2, with_arg)))
Пример #7
0
    def test_flat(self):
        """flat
        """
        n = 25
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        self.assertEqual(data[-1]["depth"], 0)
Пример #8
0
    def test_no_flat(self):
        """not_flat"""
        n = 10
        tim.settings.flat_profile = False
        with marker(components=["wall_clock", "cpu_clock"],
                    key=self.shortDescription()):
            fib(n, True)

        print("{}\n".format(
            json.dumps(tim.get()["timemory"]["wall_clock"], indent=4)))
        # inspect data
        data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]
        self.assertEqual(data[-1]["depth"], n)
Пример #9
0
    def test_no_flat(self):
        """not_flat
        """
        os.environ["TIMEMORY_FLAT_PROFILE"] = "OFF"
        tim.settings.parse()
        n = 25
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        self.assertEqual(data[-1]["depth"], n)
Пример #10
0
    def test_timeline(self):
        """timeline"""
        old_data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]

        n = 20
        with marker(
                components=["wall_clock", "current_peak_rss"],
                key=self.shortDescription(),
        ):
            for i in range(n):
                with marker(
                        components=["wall_clock", "current_peak_rss"],
                        key=self.shortDescription(),
                ):
                    fibonacci(n)

        # inspect data
        data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]

        # counts must be == 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] == 1)
Пример #11
0
    def setUpClass(self):
        # set up environment variables
        os.environ["TIMEMORY_TIMELINE_PROFILE"] = "ON"
        tim.settings.verbose = 1
        tim.settings.debug = False
        tim.settings.json_output = True
        tim.settings.mpi_thread = False
        tim.settings.dart_output = True
        tim.settings.dart_count = 1
        tim.settings.banner = False

        tim.settings.parse()

        # put one empty marker
        with marker(components=["wall_clock"], key=''):
            pass
Пример #12
0
    def test_flat(self):
        """flat"""
        n = 10
        with marker(components=["wall_clock", "cpu_clock"],
                    key=self.shortDescription()):
            with profile(
                    components=["wall_clock", "cpu_clock"],
                    flat=True,
                    timeline=False,
            ):
                fibonacci(n)

        print("{}\n".format(
            json.dumps(tim.get()["timemory"]["wall_clock"], indent=4)))
        # inspect data
        data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]
        self.assertEqual(data[-1]["depth"], 0)
Пример #13
0
    def setUpClass(self):
        # set up environment variables
        os.environ["TIMEMORY_TIMELINE_PROFILE"] = "ON"
        tim.settings.verbose = 1
        tim.settings.debug = False
        tim.settings.json_output = True
        tim.settings.mpi_thread = False
        tim.settings.dart_output = True
        tim.settings.dart_count = 1
        tim.settings.banner = False
        tim.settings.timing_units = "usec"
        tim.settings.memory_units = "byte"

        tim.settings.parse()

        # put one empty marker
        with marker(components=["wall_clock", "current_peak_rss"],
                    key="dummy"):
            pass
Пример #14
0
    def test_timeline(self):
        """timeline
        """
        n = 5

        old_data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]

        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        #print("\n{}".format(json.dumps(data, indent=4, sort_keys=True)))

        # counts must be == 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] == 1)
Пример #15
0
    def test_no_timeline(self):
        """no_timeline
        """
        old_data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        os.environ["TIMEMORY_TIMELINE_PROFILE"] = "OFF"

        tim.settings.parse()
        n = 5
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # counts must be == 1
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        #print("\n{}".format(json.dumps(data, indent=4, sort_keys=True)))
        maxcnt = 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] >= 1)
                maxcnt = max(k["stats"]["count"], maxcnt)
        self.assertTrue(maxcnt > 1)
Пример #16
0
def run(n):
    ''' Decorator and context manager for high-level custom collection(s)'''
    fib(n)
    with marker(simple_set + extended_set, key="auto_tuple_ctx_manager"):
        fib(n)